cleanup uploader. add comments. uncomment unused functions. rename.

This commit is contained in:
Luke Owncloud 2014-10-31 13:32:25 +01:00
parent 068b826b32
commit 5af3c6d389
5 changed files with 136 additions and 136 deletions

View file

@ -71,6 +71,7 @@ NOTE: Even though API level is set to 19, APK also runs on older devices because
NOTE: You must sign the [Contributor Agreement][1] before your changes can be accepted!
* Commit your changes locally: "git commit -a"
* If substantial changes were done to the official repository while you were working, merge those changes: "git merge upstream/develop"
* Push your changes to your Github repo: "git push"
* Browse to https://github.com/YOURGITHUBNAME/android/pulls and issue pull request
* Click "Edit" and set "base:develop"

View file

@ -40,9 +40,8 @@ public class DbHandler {
private final String TABLE_INSTANT_UPLOAD = "instant_upload";
public static final int UPLOAD_STATUS_UPLOAD_LATER = 0;
public static final int UPLOAD_STATUS_UPLOAD_FAILED = 1;
public enum UploadStatus {UPLOAD_STATUS_UPLOAD_LATER, UPLOAD_STATUS_UPLOAD_FAILED};
public DbHandler(Context context) {
mDatabaseName = MainApp.getDBName();
mHelper = new OpenerHelper(context);
@ -53,20 +52,35 @@ public class DbHandler {
mDB.close();
}
/**
* Store a file persistantly for upload.
* @param filepath
* @param account
* @param message
* @return
*/
public boolean putFileForLater(String filepath, String account, String message) {
ContentValues cv = new ContentValues();
cv.put("path", filepath);
cv.put("account", account);
cv.put("attempt", UPLOAD_STATUS_UPLOAD_LATER);
cv.put("attempt", String.valueOf(UploadStatus.UPLOAD_STATUS_UPLOAD_LATER));
cv.put("message", message);
long result = mDB.insert(TABLE_INSTANT_UPLOAD, null, cv);
Log_OC.d(TABLE_INSTANT_UPLOAD, "putFileForLater returns with: " + result + " for file: " + filepath);
return result != -1;
}
public int updateFileState(String filepath, Integer status, String message) {
/**
* Update upload status of file.
*
* @param filepath
* @param status
* @param message
* @return
*/
public int updateFileState(String filepath, UploadStatus status, String message) {
ContentValues cv = new ContentValues();
cv.put("attempt", status);
cv.put("attempt", String.valueOf(status));
cv.put("message", message);
int result = mDB.update(TABLE_INSTANT_UPLOAD, cv, "path=?", new String[] { filepath });
Log_OC.d(TABLE_INSTANT_UPLOAD, "updateFileState returns with: " + result + " for file: " + filepath);
@ -74,23 +88,25 @@ public class DbHandler {
}
public Cursor getAwaitingFiles() {
return mDB.query(TABLE_INSTANT_UPLOAD, null, "attempt=" + UPLOAD_STATUS_UPLOAD_LATER, null, null, null, null);
return mDB.query(TABLE_INSTANT_UPLOAD, null, "attempt=" + UploadStatus.UPLOAD_STATUS_UPLOAD_LATER, null, null, null, null);
}
public Cursor getFailedFiles() {
return mDB.query(TABLE_INSTANT_UPLOAD, null, "attempt>" + UPLOAD_STATUS_UPLOAD_LATER, null, null, null, null);
}
//ununsed until now. uncomment if needed.
// public Cursor getFailedFiles() {
// return mDB.query(TABLE_INSTANT_UPLOAD, null, "attempt>" + UploadStatus.UPLOAD_STATUS_UPLOAD_LATER, null, null, null, null);
// }
public void clearFiles() {
mDB.delete(TABLE_INSTANT_UPLOAD, null, null);
}
//ununsed until now. uncomment if needed.
// public void clearFiles() {
// mDB.delete(TABLE_INSTANT_UPLOAD, null, null);
// }
/**
*
* Remove file from upload list. Should be called when upload succeed or failed and should not be retried.
* @param localPath
* @return true when one or more pending files was removed
*/
public boolean removeIUPendingFile(String localPath) {
public boolean removePendingFile(String localPath) {
long result = mDB.delete(TABLE_INSTANT_UPLOAD, "path = ?", new String[] { localPath });
Log_OC.d(TABLE_INSTANT_UPLOAD, "delete returns with: " + result + " for file: " + localPath);
return result != 0;

View file

@ -1,99 +1,99 @@
/* ownCloud Android client application
* Copyright (C) 2011 Bartek Przybylski
* Copyright (C) 2012-2013 ownCloud Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.owncloud.android.db;
import android.net.Uri;
import android.provider.BaseColumns;
import com.owncloud.android.MainApp;
/**
* Meta-Class that holds various static field information
*
* @author Bartek Przybylski
*
*/
public class ProviderMeta {
public static final String DB_NAME = "filelist";
public static final int DB_VERSION = 8;
private ProviderMeta() {
}
static public class ProviderTableMeta implements BaseColumns {
public static final String FILE_TABLE_NAME = "filelist";
public static final String OCSHARES_TABLE_NAME = "ocshares";
public static final Uri CONTENT_URI = Uri.parse("content://"
+ MainApp.getAuthority() + "/");
public static final Uri CONTENT_URI_FILE = Uri.parse("content://"
+ MainApp.getAuthority() + "/file");
public static final Uri CONTENT_URI_DIR = Uri.parse("content://"
+ MainApp.getAuthority() + "/dir");
public static final Uri CONTENT_URI_SHARE = Uri.parse("content://"
+ MainApp.getAuthority() + "/shares");
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.owncloud.file";
public static final String CONTENT_TYPE_ITEM = "vnd.android.cursor.item/vnd.owncloud.file";
// Columns of filelist table
public static final String FILE_PARENT = "parent";
public static final String FILE_NAME = "filename";
public static final String FILE_CREATION = "created";
public static final String FILE_MODIFIED = "modified";
public static final String FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA = "modified_at_last_sync_for_data";
public static final String FILE_CONTENT_LENGTH = "content_length";
public static final String FILE_CONTENT_TYPE = "content_type";
public static final String FILE_STORAGE_PATH = "media_path";
public static final String FILE_PATH = "path";
public static final String FILE_ACCOUNT_OWNER = "file_owner";
public static final String FILE_LAST_SYNC_DATE = "last_sync_date"; // _for_properties, but let's keep it as it is
public static final String FILE_LAST_SYNC_DATE_FOR_DATA = "last_sync_date_for_data";
public static final String FILE_KEEP_IN_SYNC = "keep_in_sync";
public static final String FILE_ETAG = "etag";
public static final String FILE_SHARE_BY_LINK = "share_by_link";
public static final String FILE_PUBLIC_LINK = "public_link";
public static final String FILE_PERMISSIONS = "permissions";
public static final String FILE_REMOTE_ID = "remote_id";
public static final String FILE_UPDATE_THUMBNAIL = "update_thumbnail";
public static final String FILE_DEFAULT_SORT_ORDER = FILE_NAME
+ " collate nocase asc";
// Columns of ocshares table
public static final String OCSHARES_FILE_SOURCE = "file_source";
public static final String OCSHARES_ITEM_SOURCE = "item_source";
public static final String OCSHARES_SHARE_TYPE = "share_type";
public static final String OCSHARES_SHARE_WITH = "shate_with";
public static final String OCSHARES_PATH = "path";
public static final String OCSHARES_PERMISSIONS = "permissions";
public static final String OCSHARES_SHARED_DATE = "shared_date";
public static final String OCSHARES_EXPIRATION_DATE = "expiration_date";
public static final String OCSHARES_TOKEN = "token";
public static final String OCSHARES_SHARE_WITH_DISPLAY_NAME = "shared_with_display_name";
public static final String OCSHARES_IS_DIRECTORY = "is_directory";
public static final String OCSHARES_USER_ID = "user_id";
public static final String OCSHARES_ID_REMOTE_SHARED = "id_remote_shared";
public static final String OCSHARES_ACCOUNT_OWNER = "owner_share";
public static final String OCSHARES_DEFAULT_SORT_ORDER = OCSHARES_FILE_SOURCE
+ " collate nocase asc";
}
}
/* ownCloud Android client application
* Copyright (C) 2011 Bartek Przybylski
* Copyright (C) 2012-2013 ownCloud Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.owncloud.android.db;
import android.net.Uri;
import android.provider.BaseColumns;
import com.owncloud.android.MainApp;
/**
* Meta-Class that holds various static field information
*
* @author Bartek Przybylski
*
*/
public class ProviderMeta {
public static final String DB_NAME = "filelist";
public static final int DB_VERSION = 8;
private ProviderMeta() {
}
static public class ProviderTableMeta implements BaseColumns {
public static final String FILE_TABLE_NAME = "filelist";
public static final String OCSHARES_TABLE_NAME = "ocshares";
public static final Uri CONTENT_URI = Uri.parse("content://"
+ MainApp.getAuthority() + "/");
public static final Uri CONTENT_URI_FILE = Uri.parse("content://"
+ MainApp.getAuthority() + "/file");
public static final Uri CONTENT_URI_DIR = Uri.parse("content://"
+ MainApp.getAuthority() + "/dir");
public static final Uri CONTENT_URI_SHARE = Uri.parse("content://"
+ MainApp.getAuthority() + "/shares");
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.owncloud.file";
public static final String CONTENT_TYPE_ITEM = "vnd.android.cursor.item/vnd.owncloud.file";
// Columns of filelist table
public static final String FILE_PARENT = "parent";
public static final String FILE_NAME = "filename";
public static final String FILE_CREATION = "created";
public static final String FILE_MODIFIED = "modified";
public static final String FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA = "modified_at_last_sync_for_data";
public static final String FILE_CONTENT_LENGTH = "content_length";
public static final String FILE_CONTENT_TYPE = "content_type";
public static final String FILE_STORAGE_PATH = "media_path";
public static final String FILE_PATH = "path";
public static final String FILE_ACCOUNT_OWNER = "file_owner";
public static final String FILE_LAST_SYNC_DATE = "last_sync_date"; // _for_properties, but let's keep it as it is
public static final String FILE_LAST_SYNC_DATE_FOR_DATA = "last_sync_date_for_data";
public static final String FILE_KEEP_IN_SYNC = "keep_in_sync";
public static final String FILE_ETAG = "etag";
public static final String FILE_SHARE_BY_LINK = "share_by_link";
public static final String FILE_PUBLIC_LINK = "public_link";
public static final String FILE_PERMISSIONS = "permissions";
public static final String FILE_REMOTE_ID = "remote_id";
public static final String FILE_UPDATE_THUMBNAIL = "update_thumbnail";
public static final String FILE_DEFAULT_SORT_ORDER = FILE_NAME
+ " collate nocase asc";
// Columns of ocshares table
public static final String OCSHARES_FILE_SOURCE = "file_source";
public static final String OCSHARES_ITEM_SOURCE = "item_source";
public static final String OCSHARES_SHARE_TYPE = "share_type";
public static final String OCSHARES_SHARE_WITH = "shate_with";
public static final String OCSHARES_PATH = "path";
public static final String OCSHARES_PERMISSIONS = "permissions";
public static final String OCSHARES_SHARED_DATE = "shared_date";
public static final String OCSHARES_EXPIRATION_DATE = "expiration_date";
public static final String OCSHARES_TOKEN = "token";
public static final String OCSHARES_SHARE_WITH_DISPLAY_NAME = "shared_with_display_name";
public static final String OCSHARES_IS_DIRECTORY = "is_directory";
public static final String OCSHARES_USER_ID = "user_id";
public static final String OCSHARES_ID_REMOTE_SHARED = "id_remote_shared";
public static final String OCSHARES_ACCOUNT_OWNER = "owner_share";
public static final String OCSHARES_DEFAULT_SORT_ORDER = OCSHARES_FILE_SOURCE
+ " collate nocase asc";
}
}

View file

@ -301,7 +301,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
/**
* Download worker. Performs the pending downloads in the order they were requested.
*
* Created with the Looper of a new thread, started in {@link FileUploader#onCreate()}.
* Created with the Looper of a new thread, started in {@link FileDownloader#onCreate()}.
*/
private static class ServiceHandler extends Handler {
// don't make it a final class, and don't remove the static ; lint will warn about a possible memory leak

View file

@ -76,7 +76,7 @@ import com.owncloud.android.utils.ErrorMessageAdapter;
public class FileUploader extends Service implements OnDatatransferProgressListener {
public class FileUploader extends Service {
private static final String UPLOAD_FINISH_MESSAGE = "UPLOAD_FINISH";
public static final String EXTRA_UPLOAD_RESULT = "RESULT";
@ -273,7 +273,6 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
}
mPendingUploads.putIfAbsent(uploadKey, newUpload); // Grants that the file only upload once time
newUpload.addDatatransferProgressListener(this);
newUpload.addDatatransferProgressListener((FileUploaderBinder)mBinder);
requestedUploads.add(uploadKey);
}
@ -473,7 +472,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
* @param uploadKey Key to access the upload to perform, contained in
* mPendingUploads
*/
public void uploadFile(String uploadKey) {
private void uploadFile(String uploadKey) {
synchronized (mPendingUploads) {
mCurrentUpload = mPendingUploads.get(uploadKey);
@ -707,22 +706,6 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
mNotificationManager.notify(R.string.uploader_upload_in_progress_ticker, mNotificationBuilder.build());
}
/**
* Callback method to update the progress bar in the status notification
*/
@Override
public void onTransferProgress(long progressRate, long totalTransferredSoFar, long totalToTransfer, String filePath) {
int percent = (int) (100.0 * ((double) totalTransferredSoFar) / ((double) totalToTransfer));
if (percent != mLastPercent) {
mNotificationBuilder.setProgress(100, percent, false);
String fileName = filePath.substring(filePath.lastIndexOf(FileUtils.PATH_SEPARATOR) + 1);
String text = String.format(getString(R.string.uploader_upload_in_progress_content), percent, fileName);
mNotificationBuilder.setContentText(text);
mNotificationManager.notify(R.string.uploader_upload_in_progress_ticker, mNotificationBuilder.build());
}
mLastPercent = percent;
}
/**
* Updates the status notification with the result of an upload operation.
*
@ -797,7 +780,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
//message = getString(R.string.failed_upload_quota_exceeded_text);
if (db.updateFileState(
upload.getOriginalStoragePath(),
DbHandler.UPLOAD_STATUS_UPLOAD_FAILED,
DbHandler.UploadStatus.UPLOAD_STATUS_UPLOAD_FAILED,
message) == 0) {
db.putFileForLater(
upload.getOriginalStoragePath(),
@ -820,7 +803,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
if (uploadResult.isSuccess()) {
DbHandler db = new DbHandler(this.getBaseContext());
db.removeIUPendingFile(mCurrentUpload.getOriginalStoragePath());
db.removePendingFile(mCurrentUpload.getOriginalStoragePath());
db.close();
// remove success notification, with a delay of 2 seconds