UploadController: add javadoc

This commit is contained in:
Xiang Fan 2017-12-30 19:32:46 +08:00 committed by Nicolas Raoul
parent 24679f7322
commit ba96a97785

View file

@ -36,6 +36,9 @@ public class UploadController {
void onUploadStarted(Contribution contribution);
}
/**
* Constructs a new UploadController.
*/
public UploadController(SessionManager sessionManager, Context context, SharedPreferences sharedPreferences) {
this.sessionManager = sessionManager;
this.context = context;
@ -57,6 +60,9 @@ public class UploadController {
}
};
/**
* Prepares the upload service.
*/
public void prepareService() {
Intent uploadServiceIntent = new Intent(context, UploadService.class);
uploadServiceIntent.setAction(UploadService.ACTION_START_SERVICE);
@ -64,12 +70,25 @@ public class UploadController {
context.bindService(uploadServiceIntent, uploadServiceConnection, Context.BIND_AUTO_CREATE);
}
/**
* Disconnects the upload service.
*/
public void cleanup() {
if (isUploadServiceConnected) {
context.unbindService(uploadServiceConnection);
}
}
/**
* Starts a new upload task.
* @param title the title of the contribution
* @param mediaUri the media URI of the contribution
* @param description the description of the contribution
* @param mimeType the MIME type of the contribution
* @param source the source of the contribution
* @param decimalCoords the coordinates in decimal. (e.g. "37.51136|-77.602615")
* @param onComplete the progress tracker
*/
public void startUpload(String title, Uri mediaUri, String description, String mimeType, String source, String decimalCoords, ContributionUploadProgress onComplete) {
Contribution contribution;
@ -85,6 +104,11 @@ public class UploadController {
startUpload(contribution, onComplete);
}
/**
* Starts a new upload task.
* @param contribution the contribution object
* @param onComplete the progress tracker
*/
public void startUpload(final Contribution contribution, final ContributionUploadProgress onComplete) {
//Set creator, desc, and license
if (TextUtils.isEmpty(contribution.getCreator())) {
@ -173,6 +197,12 @@ public class UploadController {
}
/**
* Counts the number of bytes in {@code stream}.
* @param stream the stream
* @return the number of bytes in {@code stream}
* @throws IOException if an I/O error occurs
*/
private long countBytes(InputStream stream) throws IOException {
long count = 0;
BufferedInputStream bis = new BufferedInputStream(stream);