Merge pull request #851 from owncloud/download_folder_update_database

Download folder update database
This commit is contained in:
David A. Velasco 2015-01-20 13:07:50 +01:00
commit e2a7138e0e
5 changed files with 64 additions and 9 deletions

View file

@ -193,6 +193,7 @@ public class FileDataStorageManager {
cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions()); cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId()); cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail()); cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail());
cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading());
boolean sameRemotePath = fileExists(file.getRemotePath()); boolean sameRemotePath = fileExists(file.getRemotePath());
if (sameRemotePath || if (sameRemotePath ||
@ -302,6 +303,7 @@ public class FileDataStorageManager {
cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions()); cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId()); cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail()); cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail());
cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading());
boolean existsByPath = fileExists(file.getRemotePath()); boolean existsByPath = fileExists(file.getRemotePath());
if (existsByPath || fileExists(file.getFileId())) { if (existsByPath || fileExists(file.getFileId())) {
@ -877,6 +879,8 @@ public class FileDataStorageManager {
file.setRemoteId(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID))); file.setRemoteId(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID)));
file.setNeedsUpdateThumbnail(c.getInt( file.setNeedsUpdateThumbnail(c.getInt(
c.getColumnIndex(ProviderTableMeta.FILE_UPDATE_THUMBNAIL)) == 1 ? true : false); c.getColumnIndex(ProviderTableMeta.FILE_UPDATE_THUMBNAIL)) == 1 ? true : false);
file.setDownloading(c.getInt(
c.getColumnIndex(ProviderTableMeta.FILE_IS_DOWNLOADING)) == 1 ? true : false);
} }
return file; return file;
@ -1259,6 +1263,10 @@ public class FileDataStorageManager {
ProviderTableMeta.FILE_UPDATE_THUMBNAIL, ProviderTableMeta.FILE_UPDATE_THUMBNAIL,
file.needsUpdateThumbnail() ? 1 : 0 file.needsUpdateThumbnail() ? 1 : 0
); );
cv.put(
ProviderTableMeta.FILE_IS_DOWNLOADING,
file.isDownloading() ? 1 : 0
);
boolean existsByPath = fileExists(file.getRemotePath()); boolean existsByPath = fileExists(file.getRemotePath());
if (existsByPath || fileExists(file.getFileId())) { if (existsByPath || fileExists(file.getFileId())) {

View file

@ -70,6 +70,8 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
private boolean mNeedsUpdateThumbnail; private boolean mNeedsUpdateThumbnail;
private boolean mIsDownloading;
/** /**
* Create new {@link OCFile} with given path. * Create new {@link OCFile} with given path.
@ -112,6 +114,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
mPermissions = source.readString(); mPermissions = source.readString();
mRemoteId = source.readString(); mRemoteId = source.readString();
mNeedsUpdateThumbnail = source.readInt() == 0; mNeedsUpdateThumbnail = source.readInt() == 0;
mIsDownloading = source.readInt() == 0;
} }
@ -136,6 +139,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
dest.writeString(mPermissions); dest.writeString(mPermissions);
dest.writeString(mRemoteId); dest.writeString(mRemoteId);
dest.writeInt(mNeedsUpdateThumbnail ? 1 : 0); dest.writeInt(mNeedsUpdateThumbnail ? 1 : 0);
dest.writeInt(mIsDownloading ? 1 : 0);
} }
/** /**
@ -348,6 +352,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
mPermissions = null; mPermissions = null;
mRemoteId = null; mRemoteId = null;
mNeedsUpdateThumbnail = false; mNeedsUpdateThumbnail = false;
mIsDownloading = false;
} }
/** /**
@ -562,14 +567,16 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
this.mRemoteId = remoteId; this.mRemoteId = remoteId;
} }
public boolean isDownloading() {
return mIsDownloading;
}
public void setDownloading(boolean isDownloading) {
this.mIsDownloading = isDownloading;
}
public boolean isSynchronizing() { public boolean isSynchronizing() {
// TODO real implementation // TODO real implementation
return false; return false;
} }
public boolean isDownloading() {
// TODO real implementation
return false;
}
} }

View file

@ -31,7 +31,7 @@ import com.owncloud.android.MainApp;
public class ProviderMeta { public class ProviderMeta {
public static final String DB_NAME = "filelist"; public static final String DB_NAME = "filelist";
public static final int DB_VERSION = 8; public static final int DB_VERSION = 9;
private ProviderMeta() { private ProviderMeta() {
} }
@ -71,6 +71,7 @@ public class ProviderMeta {
public static final String FILE_PERMISSIONS = "permissions"; public static final String FILE_PERMISSIONS = "permissions";
public static final String FILE_REMOTE_ID = "remote_id"; public static final String FILE_REMOTE_ID = "remote_id";
public static final String FILE_UPDATE_THUMBNAIL = "update_thumbnail"; public static final String FILE_UPDATE_THUMBNAIL = "update_thumbnail";
public static final String FILE_IS_DOWNLOADING= "is_downloading";
public static final String FILE_DEFAULT_SORT_ORDER = FILE_NAME public static final String FILE_DEFAULT_SORT_ORDER = FILE_NAME
+ " collate nocase asc"; + " collate nocase asc";

View file

@ -169,6 +169,12 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
newDownload.addDatatransferProgressListener(this); newDownload.addDatatransferProgressListener(this);
newDownload.addDatatransferProgressListener((FileDownloaderBinder) mBinder); newDownload.addDatatransferProgressListener((FileDownloaderBinder) mBinder);
requestedDownloads.add(downloadKey); requestedDownloads.add(downloadKey);
// Store file on db with state 'downloading'
FileDataStorageManager storageManager = new FileDataStorageManager(account, getContentResolver());
file.setDownloading(true);
storageManager.saveFile(file);
sendBroadcastNewDownload(newDownload); sendBroadcastNewDownload(newDownload);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
@ -377,6 +383,8 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
downloadResult = mCurrentDownload.execute(mDownloadClient); downloadResult = mCurrentDownload.execute(mDownloadClient);
if (downloadResult.isSuccess()) { if (downloadResult.isSuccess()) {
saveDownloadedFile(); saveDownloadedFile();
} else {
updateUnsuccessfulDownloadedFile();
} }
} catch (AccountsException e) { } catch (AccountsException e) {
@ -417,10 +425,20 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
file.setStoragePath(mCurrentDownload.getSavePath()); file.setStoragePath(mCurrentDownload.getSavePath());
file.setFileLength((new File(mCurrentDownload.getSavePath()).length())); file.setFileLength((new File(mCurrentDownload.getSavePath()).length()));
file.setRemoteId(mCurrentDownload.getFile().getRemoteId()); file.setRemoteId(mCurrentDownload.getFile().getRemoteId());
file.setDownloading(false);
mStorageManager.saveFile(file); mStorageManager.saveFile(file);
mStorageManager.triggerMediaScan(file.getStoragePath()); mStorageManager.triggerMediaScan(file.getStoragePath());
} }
/**
* Update the OC File after a unsuccessful download
*/
private void updateUnsuccessfulDownloadedFile() {
OCFile file = mStorageManager.getFileById(mCurrentDownload.getFile().getFileId());
file.setDownloading(false);
mStorageManager.saveFile(file);
}
/** /**
* Creates a status notification to show the download progress * Creates a status notification to show the download progress

View file

@ -97,6 +97,8 @@ public class FileContentProvider extends ContentProvider {
ProviderTableMeta.FILE_REMOTE_ID); ProviderTableMeta.FILE_REMOTE_ID);
mFileProjectionMap.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, mFileProjectionMap.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL,
ProviderTableMeta.FILE_UPDATE_THUMBNAIL); ProviderTableMeta.FILE_UPDATE_THUMBNAIL);
mFileProjectionMap.put(ProviderTableMeta.FILE_IS_DOWNLOADING,
ProviderTableMeta.FILE_IS_DOWNLOADING);
} }
private static final int SINGLE_FILE = 1; private static final int SINGLE_FILE = 1;
@ -624,7 +626,8 @@ public class FileContentProvider extends ContentProvider {
+ ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT, " + ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT, "
+ ProviderTableMeta.FILE_PERMISSIONS + " TEXT null," + ProviderTableMeta.FILE_PERMISSIONS + " TEXT null,"
+ ProviderTableMeta.FILE_REMOTE_ID + " TEXT null," + ProviderTableMeta.FILE_REMOTE_ID + " TEXT null,"
+ ProviderTableMeta.FILE_UPDATE_THUMBNAIL + " INTEGER);" //boolean + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + " INTEGER," //boolean
+ ProviderTableMeta.FILE_IS_DOWNLOADING + " INTEGER);" //boolean
); );
// Create table ocshares // Create table ocshares
@ -795,7 +798,25 @@ public class FileContentProvider extends ContentProvider {
} }
} }
if (!upgraded) if (!upgraded)
Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
", newVersion == " + newVersion);
if (oldVersion < 9 && newVersion >= 9) {
Log_OC.i("SQL", "Entering in the #9 ADD in onUpgrade");
db.beginTransaction();
try {
db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
" ADD COLUMN " + ProviderTableMeta.FILE_IS_DOWNLOADING + " INTEGER " +
" DEFAULT 0");
upgraded = true;
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
if (!upgraded)
Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
", newVersion == " + newVersion); ", newVersion == " + newVersion);
} }
} }