From: jabarros Date: Fri, 10 Oct 2014 13:10:39 +0000 (+0200) Subject: Fixed. When removing a file inside a folder and then upload another, thumbnails are... X-Git-Tag: oc-android-1.7.0_signed~15^2~21 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/8f1045de2bacb871b9b96ddfac3d6d6957aa519e?ds=inline;hp=--cc Fixed. When removing a file inside a folder and then upload another, thumbnails are not shown correctly --- 8f1045de2bacb871b9b96ddfac3d6d6957aa519e diff --git a/src/com/owncloud/android/providers/FileContentProvider.java b/src/com/owncloud/android/providers/FileContentProvider.java index 9792f3e9..36bade52 100644 --- a/src/com/owncloud/android/providers/FileContentProvider.java +++ b/src/com/owncloud/android/providers/FileContentProvider.java @@ -26,6 +26,7 @@ import com.owncloud.android.db.ProviderMeta; import com.owncloud.android.db.ProviderMeta.ProviderTableMeta; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.shares.ShareType; +import com.owncloud.android.ui.adapter.DiskLruImageCache; @@ -42,6 +43,7 @@ import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteQueryBuilder; +import android.graphics.Bitmap.CompressFormat; import android.net.Uri; import android.text.TextUtils; @@ -55,6 +57,12 @@ import android.text.TextUtils; public class FileContentProvider extends ContentProvider { private DataBaseHelper mDbHelper; + private static final int DISK_CACHE_SIZE = 1024 * 1024 * 10; // 10MB + private static final CompressFormat mCompressFormat = CompressFormat.JPEG; + private static final int mCompressQuality = 70; + + private final Object thumbnailDiskCacheLock = new Object(); + private DiskLruImageCache mThumbnailCache; // Projection for filelist table private static HashMap mFileProjectionMap; @@ -165,13 +173,14 @@ public class FileContentProvider extends ContentProvider { int count = 0; switch (mUriMatcher.match(uri)) { case SINGLE_FILE: - /*Cursor c = query(db, uri, null, where, whereArgs, null); - String remotePath = "(unexisting)"; + Cursor c = query(db, uri, null, where, whereArgs, null); + String remoteId = ""; if (c != null && c.moveToFirst()) { - remotePath = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PATH)); + remoteId = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID)); + removeFileFromCache(remoteId); } - Log_OC.d(TAG, "Removing FILE " + remotePath); - */ + Log_OC.d(TAG, "Removing FILE " + remoteId); + count = db.delete(ProviderTableMeta.FILE_TABLE_NAME, ProviderTableMeta._ID + "=" @@ -197,7 +206,7 @@ public class FileContentProvider extends ContentProvider { Cursor children = query(uri, null, null, null, null); if (children != null && children.moveToFirst()) { long childId; - boolean isDir; + boolean isDir; //String remotePath; while (!children.isAfterLast()) { childId = children.getLong(children.getColumnIndex(ProviderTableMeta._ID)); @@ -240,7 +249,29 @@ public class FileContentProvider extends ContentProvider { } return count; } - + + /** + * Remove from cache the remoteId passed + * @param fileRemoteId: remote id of file passed + */ + private void removeFileFromCache(String fileRemoteId){ + Context context = getContext(); + if (context != null) { + synchronized (thumbnailDiskCacheLock) { + try { + mThumbnailCache = new DiskLruImageCache(context, "thumbnailCache", + DISK_CACHE_SIZE, mCompressFormat, mCompressQuality); + + mThumbnailCache.removeKey(fileRemoteId); + + } catch (Exception e) { + Log_OC.d(TAG, "Thumbnail cache could not be opened ", e); + mThumbnailCache = null; + } + thumbnailDiskCacheLock.notifyAll(); // Wake any waiting threads + } + } + } @Override public String getType(Uri uri) { diff --git a/src/com/owncloud/android/ui/adapter/DiskLruImageCache.java b/src/com/owncloud/android/ui/adapter/DiskLruImageCache.java index d22dc971..01fe5ebd 100644 --- a/src/com/owncloud/android/ui/adapter/DiskLruImageCache.java +++ b/src/com/owncloud/android/ui/adapter/DiskLruImageCache.java @@ -33,7 +33,7 @@ public class DiskLruImageCache { private StringBuffer mValidKeyBuffer = new StringBuffer(64); private StringBuffer mConversionBuffer = new StringBuffer(2).append('_'); - private static final String TAG = "DiskLruImageCache"; + private static final String TAG = DiskLruImageCache.class.getSimpleName(); public DiskLruImageCache( Context context,String uniqueName, int diskCacheSize, CompressFormat compressFormat, int quality ) throws IOException { @@ -186,4 +186,17 @@ public class DiskLruImageCache { return mValidKeyBuffer.toString(); } + /** + * Remove passed key from cache + * @param key + */ + public void removeKey( String key ) { + String validKey = convertToValidKey(key); + try { + mDiskCache.remove(validKey); + Log.d(TAG, "removeKey from cache: " + validKey); + } catch (IOException e) { + e.printStackTrace(); + } + } } \ No newline at end of file