From: jabarros Date: Mon, 29 Sep 2014 11:55:28 +0000 (+0200) Subject: Add column 'update_thumbnail' to the local files db for controlling the update of... X-Git-Tag: oc-android-1.7.0_signed~163^2~1 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/97d611aec320cf7d833ead40c7846466316f9b68?ds=inline;hp=--cc Add column 'update_thumbnail' to the local files db for controlling the update of the thumbnails when images are updated on the server --- 97d611aec320cf7d833ead40c7846466316f9b68 diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index aaafb3a0..a65eef8d 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -188,6 +188,7 @@ public class FileDataStorageManager { cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink()); cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions()); cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId()); + cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail()); boolean sameRemotePath = fileExists(file.getRemotePath()); if (sameRemotePath || @@ -878,6 +879,8 @@ public class FileDataStorageManager { file.setPublicLink(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PUBLIC_LINK))); file.setPermissions(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PERMISSIONS))); file.setRemoteId(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID))); + file.setNeedsUpdateThumbnail(c.getInt( + c.getColumnIndex(ProviderTableMeta.FILE_UPDATE_THUMBNAIL)) == 1 ? true : false); } return file; @@ -1222,6 +1225,7 @@ public class FileDataStorageManager { cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink()); cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions()); cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId()); + cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail() ? 1 : 0); boolean existsByPath = fileExists(file.getRemotePath()); if (existsByPath || fileExists(file.getFileId())) { diff --git a/src/com/owncloud/android/datamodel/OCFile.java b/src/com/owncloud/android/datamodel/OCFile.java index 92168ff5..5f45cc42 100644 --- a/src/com/owncloud/android/datamodel/OCFile.java +++ b/src/com/owncloud/android/datamodel/OCFile.java @@ -68,6 +68,8 @@ public class OCFile implements Parcelable, Comparable { private String mPermissions; private String mRemoteId; + private boolean mNeedsUpdateThumbnail; + /** * Create new {@link OCFile} with given path. @@ -109,6 +111,8 @@ public class OCFile implements Parcelable, Comparable { mPublicLink = source.readString(); mPermissions = source.readString(); mRemoteId = source.readString(); + mNeedsUpdateThumbnail = source.readInt() == 0; + } @Override @@ -131,6 +135,7 @@ public class OCFile implements Parcelable, Comparable { dest.writeString(mPublicLink); dest.writeString(mPermissions); dest.writeString(mRemoteId); + dest.writeInt(mNeedsUpdateThumbnail ? 1 : 0); } /** @@ -343,6 +348,7 @@ public class OCFile implements Parcelable, Comparable { mPublicLink = null; mPermissions = null; mRemoteId = null; + mNeedsUpdateThumbnail = false; } /** @@ -408,6 +414,14 @@ public class OCFile implements Parcelable, Comparable { return mNeedsUpdating; } + public boolean needsUpdateThumbnail() { + return mNeedsUpdateThumbnail; + } + + public void setNeedsUpdateThumbnail(boolean needsUpdateThumbnail) { + this.mNeedsUpdateThumbnail = needsUpdateThumbnail; + } + public long getLastSyncDateForProperties() { return mLastSyncDateForProperties; } diff --git a/src/com/owncloud/android/db/ProviderMeta.java b/src/com/owncloud/android/db/ProviderMeta.java index 1adf6971..bc59869a 100644 --- a/src/com/owncloud/android/db/ProviderMeta.java +++ b/src/com/owncloud/android/db/ProviderMeta.java @@ -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 = 7; + public static final int DB_VERSION = 8; private ProviderMeta() { } @@ -70,6 +70,7 @@ public class ProviderMeta { 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"; diff --git a/src/com/owncloud/android/files/services/FileDownloader.java b/src/com/owncloud/android/files/services/FileDownloader.java index 2e34a8b6..7799ca1f 100644 --- a/src/com/owncloud/android/files/services/FileDownloader.java +++ b/src/com/owncloud/android/files/services/FileDownloader.java @@ -391,6 +391,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis long syncDate = System.currentTimeMillis(); file.setLastSyncDateForProperties(syncDate); file.setLastSyncDateForData(syncDate); + file.setNeedsUpdateThumbnail(true); file.setModificationTimestamp(mCurrentDownload.getModificationTimestamp()); file.setModificationTimestampAtLastSyncForData(mCurrentDownload.getModificationTimestamp()); // file.setEtag(mCurrentDownload.getEtag()); // TODO Etag, where available diff --git a/src/com/owncloud/android/providers/FileContentProvider.java b/src/com/owncloud/android/providers/FileContentProvider.java index 1dd452a6..3a93c167 100644 --- a/src/com/owncloud/android/providers/FileContentProvider.java +++ b/src/com/owncloud/android/providers/FileContentProvider.java @@ -97,6 +97,8 @@ public class FileContentProvider extends ContentProvider { ProviderTableMeta.FILE_PERMISSIONS); mFileProjectionMap.put(ProviderTableMeta.FILE_REMOTE_ID, ProviderTableMeta.FILE_REMOTE_ID); + mFileProjectionMap.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, + ProviderTableMeta.FILE_UPDATE_THUMBNAIL); } private static final int SINGLE_FILE = 1; @@ -559,7 +561,8 @@ public class FileContentProvider extends ContentProvider { + ProviderTableMeta.FILE_SHARE_BY_LINK + " INTEGER, " + ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT, " + ProviderTableMeta.FILE_PERMISSIONS + " TEXT null," - + ProviderTableMeta.FILE_REMOTE_ID + " TEXT null);" + + ProviderTableMeta.FILE_REMOTE_ID + " TEXT null," + + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + " INTEGER);" //boolean ); // Create table ocshares @@ -708,6 +711,23 @@ public class FileContentProvider extends ContentProvider { } if (!upgraded) Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion); + + if (oldVersion < 8 && newVersion >= 8) { + Log_OC.i("SQL", "Entering in the #8 ADD in onUpgrade"); + db.beginTransaction(); + try { + db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME + + " ADD COLUMN " + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + " 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); } } diff --git a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java index ef95a8a2..56b51319 100644 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -156,7 +156,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { thumbnail = getBitmapFromDiskCache(imageKey); // Not found in disk cache - if (thumbnail == null) { + if (thumbnail == null || file.needsUpdateThumbnail()) { // Converts dp to pixel Resources r = mContext.getResources(); int px = (int) Math.round(TypedValue.applyDimension( @@ -172,6 +172,9 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { // Add thumbnail to cache addBitmapToCache(imageKey, thumbnail); + + file.setNeedsUpdateThumbnail(false); + mStorageManager.saveFile(file); } } else { @@ -235,7 +238,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { public void addBitmapToCache(String key, Bitmap bitmap) { synchronized (thumbnailDiskCacheLock) { - if (mThumbnailCache != null && mThumbnailCache.getBitmap(key) == null) { + if (mThumbnailCache != null) { mThumbnailCache.put(key, bitmap); } } @@ -363,7 +366,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { if (file.isImage()){ // Thumbnail in Cache? Bitmap thumbnail = getBitmapFromDiskCache(String.valueOf(file.getRemoteId())); - if (thumbnail != null){ + if (thumbnail != null && !file.needsUpdateThumbnail()){ fileIcon.setImageBitmap(thumbnail); } else { // generate new Thumbnail