X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/9804b40839678e01ff664ccf99322ba0b882588f..06758342319b8cc7d0e8b239780bb2881d4519e9:/src/com/owncloud/android/providers/FileContentProvider.java diff --git a/src/com/owncloud/android/providers/FileContentProvider.java b/src/com/owncloud/android/providers/FileContentProvider.java index 1a5810bd..36bade52 100644 --- a/src/com/owncloud/android/providers/FileContentProvider.java +++ b/src/com/owncloud/android/providers/FileContentProvider.java @@ -24,9 +24,9 @@ import java.util.HashMap; import com.owncloud.android.R; import com.owncloud.android.db.ProviderMeta; import com.owncloud.android.db.ProviderMeta.ProviderTableMeta; -import com.owncloud.android.lib.resources.files.FileUtils; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.shares.ShareType; -import com.owncloud.android.utils.Log_OC; +import com.owncloud.android.ui.adapter.DiskLruImageCache; @@ -43,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; @@ -56,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; @@ -94,6 +101,12 @@ public class FileContentProvider extends ContentProvider { ProviderTableMeta.FILE_SHARE_BY_LINK); mFileProjectionMap.put(ProviderTableMeta.FILE_PUBLIC_LINK, ProviderTableMeta.FILE_PUBLIC_LINK); + mFileProjectionMap.put(ProviderTableMeta.FILE_PERMISSIONS, + 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; @@ -142,68 +155,32 @@ public class FileContentProvider extends ContentProvider { @Override public int delete(Uri uri, String where, String[] whereArgs) { - Log_OC.d(TAG, "Deleting " + uri + " at provider " + this); + //Log_OC.d(TAG, "Deleting " + uri + " at provider " + this); int count = 0; SQLiteDatabase db = mDbHelper.getWritableDatabase(); db.beginTransaction(); - - // Get parentId to notify the change - long parentId = getParentId(uri); - - // Delete action try { count = delete(db, uri, where, whereArgs); db.setTransactionSuccessful(); } finally { db.endTransaction(); } - Log_OC.d(TAG, "Uri " + uri); getContext().getContentResolver().notifyChange(uri, null); - - // Notify the change to the parent folder - notifyChangeToParentUri(parentId); return count; } - private long getParentId(Uri uri) { - long parentId = -1; - - if (mUriMatcher.match(uri) == SINGLE_FILE || mUriMatcher.match(uri) == DIRECTORY) { - String fileId = uri.toString().substring(uri.toString().lastIndexOf(FileUtils.PATH_SEPARATOR) + 1); - Uri selectFileUri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, fileId); - String[] fileProjection = new String[] { ProviderTableMeta.FILE_PARENT}; - Cursor fileCursor = query(selectFileUri, fileProjection, null, null, null); - - if (fileCursor != null && fileCursor.moveToFirst()) { - parentId = fileCursor.getLong(fileCursor.getColumnIndex(ProviderTableMeta.FILE_PARENT)); - } - fileCursor.close(); - } - Log_OC.d(TAG, "getParentId = " + parentId); - return parentId; - } - - private void notifyChangeToParentUri(long parentId) { - if (parentId != -1) { - Uri parentUri = Uri.withAppendedPath( - ProviderTableMeta.CONTENT_URI_DIR, - String.valueOf(parentId)); - Log_OC.d(TAG, "ParentUri " + parentUri); - getContext().getContentResolver().notifyChange(parentUri, null); - } - } - private int delete(SQLiteDatabase db, Uri uri, String where, String[] whereArgs) { 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 + "=" @@ -229,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)); @@ -272,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) { @@ -290,7 +289,6 @@ public class FileContentProvider extends ContentProvider { @Override public Uri insert(Uri uri, ContentValues values) { //Log_OC.d(TAG, "Inserting " + values.getAsString(ProviderTableMeta.FILE_PATH) + " at provider " + this); - Log_OC.d(TAG, "Uri " + uri); Uri newUri = null; SQLiteDatabase db = mDbHelper.getWritableDatabase(); db.beginTransaction(); @@ -455,7 +453,6 @@ public class FileContentProvider extends ContentProvider { // DB case_sensitive db.execSQL("PRAGMA case_sensitive_like = true"); Cursor c = sqlQuery.query(db, projection, selection, selectionArgs, null, null, order); - Log_OC.d(TAG, "setting notification URI: " + uri); c.setNotificationUri(getContext().getContentResolver(), uri); return c; } @@ -463,8 +460,7 @@ public class FileContentProvider extends ContentProvider { @Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { - Log_OC.d(TAG, "Updating " + values.getAsString(ProviderTableMeta.FILE_PATH) + " at provider " + this); - Log_OC.d(TAG, "Uri " + uri); + //Log_OC.d(TAG, "Updating " + values.getAsString(ProviderTableMeta.FILE_PATH) + " at provider " + this); int count = 0; SQLiteDatabase db = mDbHelper.getWritableDatabase(); db.beginTransaction(); @@ -594,7 +590,10 @@ public class FileContentProvider extends ContentProvider { + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " INTEGER, " + ProviderTableMeta.FILE_ETAG + " TEXT, " + ProviderTableMeta.FILE_SHARE_BY_LINK + " INTEGER, " - + ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT );" + + ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT, " + + ProviderTableMeta.FILE_PERMISSIONS + " TEXT null," + + ProviderTableMeta.FILE_REMOTE_ID + " TEXT null," + + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + " INTEGER);" //boolean ); // Create table ocshares @@ -683,7 +682,7 @@ public class FileContentProvider extends ContentProvider { } if (!upgraded) Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion); - + if (oldVersion < 6 && newVersion >= 6) { Log_OC.i("SQL", "Entering in the #5 ADD in onUpgrade"); db.beginTransaction(); @@ -695,7 +694,7 @@ public class FileContentProvider extends ContentProvider { db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME + " ADD COLUMN " + ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT " + " DEFAULT NULL"); - + // Create table ocshares db.execSQL("CREATE TABLE " + ProviderTableMeta.OCSHARES_TABLE_NAME + "(" + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " @@ -713,6 +712,27 @@ public class FileContentProvider extends ContentProvider { + ProviderTableMeta.OCSHARES_USER_ID + " INTEGER, " + ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + " INTEGER," + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + " TEXT );" ); + + upgraded = true; + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + } + if (!upgraded) + Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion); + + if (oldVersion < 7 && newVersion >= 7) { + Log_OC.i("SQL", "Entering in the #7 ADD in onUpgrade"); + db.beginTransaction(); + try { + db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME + + " ADD COLUMN " + ProviderTableMeta.FILE_PERMISSIONS + " TEXT " + + " DEFAULT NULL"); + + db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME + + " ADD COLUMN " + ProviderTableMeta.FILE_REMOTE_ID + " TEXT " + + " DEFAULT NULL"); upgraded = true; db.setTransactionSuccessful(); @@ -722,6 +742,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); } }