mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 21:55:48 +03:00
Merge pull request #851 from owncloud/download_folder_update_database
Download folder update database
This commit is contained in:
commit
e2a7138e0e
5 changed files with 64 additions and 9 deletions
|
@ -193,6 +193,7 @@ public class FileDataStorageManager {
|
|||
cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
|
||||
cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
|
||||
cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail());
|
||||
cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading());
|
||||
|
||||
boolean sameRemotePath = fileExists(file.getRemotePath());
|
||||
if (sameRemotePath ||
|
||||
|
@ -302,6 +303,7 @@ public class FileDataStorageManager {
|
|||
cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
|
||||
cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
|
||||
cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail());
|
||||
cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading());
|
||||
|
||||
boolean existsByPath = fileExists(file.getRemotePath());
|
||||
if (existsByPath || fileExists(file.getFileId())) {
|
||||
|
@ -877,6 +879,8 @@ public class FileDataStorageManager {
|
|||
file.setRemoteId(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID)));
|
||||
file.setNeedsUpdateThumbnail(c.getInt(
|
||||
c.getColumnIndex(ProviderTableMeta.FILE_UPDATE_THUMBNAIL)) == 1 ? true : false);
|
||||
file.setDownloading(c.getInt(
|
||||
c.getColumnIndex(ProviderTableMeta.FILE_IS_DOWNLOADING)) == 1 ? true : false);
|
||||
|
||||
}
|
||||
return file;
|
||||
|
@ -1259,6 +1263,10 @@ public class FileDataStorageManager {
|
|||
ProviderTableMeta.FILE_UPDATE_THUMBNAIL,
|
||||
file.needsUpdateThumbnail() ? 1 : 0
|
||||
);
|
||||
cv.put(
|
||||
ProviderTableMeta.FILE_IS_DOWNLOADING,
|
||||
file.isDownloading() ? 1 : 0
|
||||
);
|
||||
|
||||
boolean existsByPath = fileExists(file.getRemotePath());
|
||||
if (existsByPath || fileExists(file.getFileId())) {
|
||||
|
|
|
@ -70,6 +70,8 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
|
|||
|
||||
private boolean mNeedsUpdateThumbnail;
|
||||
|
||||
private boolean mIsDownloading;
|
||||
|
||||
|
||||
/**
|
||||
* Create new {@link OCFile} with given path.
|
||||
|
@ -112,6 +114,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
|
|||
mPermissions = source.readString();
|
||||
mRemoteId = source.readString();
|
||||
mNeedsUpdateThumbnail = source.readInt() == 0;
|
||||
mIsDownloading = source.readInt() == 0;
|
||||
|
||||
}
|
||||
|
||||
|
@ -136,6 +139,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
|
|||
dest.writeString(mPermissions);
|
||||
dest.writeString(mRemoteId);
|
||||
dest.writeInt(mNeedsUpdateThumbnail ? 1 : 0);
|
||||
dest.writeInt(mIsDownloading ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -348,6 +352,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
|
|||
mPermissions = null;
|
||||
mRemoteId = null;
|
||||
mNeedsUpdateThumbnail = false;
|
||||
mIsDownloading = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -562,14 +567,16 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
|
|||
this.mRemoteId = remoteId;
|
||||
}
|
||||
|
||||
public boolean isDownloading() {
|
||||
return mIsDownloading;
|
||||
}
|
||||
|
||||
public void setDownloading(boolean isDownloading) {
|
||||
this.mIsDownloading = isDownloading;
|
||||
}
|
||||
|
||||
public boolean isSynchronizing() {
|
||||
// TODO real implementation
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isDownloading() {
|
||||
// TODO real implementation
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ import com.owncloud.android.MainApp;
|
|||
public class ProviderMeta {
|
||||
|
||||
public static final String DB_NAME = "filelist";
|
||||
public static final int DB_VERSION = 8;
|
||||
public static final int DB_VERSION = 9;
|
||||
|
||||
private ProviderMeta() {
|
||||
}
|
||||
|
@ -71,6 +71,7 @@ public class ProviderMeta {
|
|||
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_IS_DOWNLOADING= "is_downloading";
|
||||
|
||||
public static final String FILE_DEFAULT_SORT_ORDER = FILE_NAME
|
||||
+ " collate nocase asc";
|
||||
|
|
|
@ -169,6 +169,12 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
|
|||
newDownload.addDatatransferProgressListener(this);
|
||||
newDownload.addDatatransferProgressListener((FileDownloaderBinder) mBinder);
|
||||
requestedDownloads.add(downloadKey);
|
||||
|
||||
// Store file on db with state 'downloading'
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(account, getContentResolver());
|
||||
file.setDownloading(true);
|
||||
storageManager.saveFile(file);
|
||||
|
||||
sendBroadcastNewDownload(newDownload);
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
@ -377,6 +383,8 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
|
|||
downloadResult = mCurrentDownload.execute(mDownloadClient);
|
||||
if (downloadResult.isSuccess()) {
|
||||
saveDownloadedFile();
|
||||
} else {
|
||||
updateUnsuccessfulDownloadedFile();
|
||||
}
|
||||
|
||||
} catch (AccountsException e) {
|
||||
|
@ -417,10 +425,20 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
|
|||
file.setStoragePath(mCurrentDownload.getSavePath());
|
||||
file.setFileLength((new File(mCurrentDownload.getSavePath()).length()));
|
||||
file.setRemoteId(mCurrentDownload.getFile().getRemoteId());
|
||||
file.setDownloading(false);
|
||||
mStorageManager.saveFile(file);
|
||||
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
|
||||
|
|
|
@ -97,6 +97,8 @@ public class FileContentProvider extends ContentProvider {
|
|||
ProviderTableMeta.FILE_REMOTE_ID);
|
||||
mFileProjectionMap.put(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;
|
||||
|
@ -624,7 +626,8 @@ public class FileContentProvider extends ContentProvider {
|
|||
+ ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT, "
|
||||
+ ProviderTableMeta.FILE_PERMISSIONS + " 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
|
||||
|
@ -795,7 +798,25 @@ public class FileContentProvider extends ContentProvider {
|
|||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue