X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/1c83e751156e4986a2ddd06cf0a93893e9e36e71..40b5fb815613c4cf9023c9c9ad93cda0d2521f86:/src/com/owncloud/android/datamodel/FileDataStorageManager.java diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index d1e26034..39b1959c 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -27,13 +27,12 @@ import java.util.Vector; import com.owncloud.android.MainApp; import com.owncloud.android.db.ProviderMeta.ProviderTableMeta; -import com.owncloud.android.lib.operations.common.OCShare; -import com.owncloud.android.lib.operations.common.ShareType; -import com.owncloud.android.lib.utils.FileUtils; +import com.owncloud.android.lib.resources.shares.OCShare; +import com.owncloud.android.lib.resources.shares.ShareType; +import com.owncloud.android.lib.resources.files.FileUtils; import com.owncloud.android.utils.FileStorageUtils; import com.owncloud.android.utils.Log_OC; - import android.accounts.Account; import android.content.ContentProviderClient; import android.content.ContentProviderOperation; @@ -237,11 +236,11 @@ public class FileDataStorageManager { } } - if (file.isFolder()) { - updateFolderSize(file.getFileId()); - } else { - updateFolderSize(file.getParentId()); - } +// if (file.isFolder()) { +// updateFolderSize(file.getFileId()); +// } else { +// updateFolderSize(file.getParentId()); +// } return overriden; } @@ -388,38 +387,38 @@ public class FileDataStorageManager { } } - updateFolderSize(folder.getFileId()); + //updateFolderSize(folder.getFileId()); } - /** - * - * @param id - */ - private void updateFolderSize(long id) { - if (id > FileDataStorageManager.ROOT_PARENT_ID) { - Log_OC.d(TAG, "Updating size of " + id); - if (getContentResolver() != null) { - getContentResolver().update(ProviderTableMeta.CONTENT_URI_DIR, - new ContentValues(), // won't be used, but cannot be null; crashes in KLP - ProviderTableMeta._ID + "=?", - new String[] { String.valueOf(id) }); - } else { - try { - getContentProviderClient().update(ProviderTableMeta.CONTENT_URI_DIR, - new ContentValues(), // won't be used, but cannot be null; crashes in KLP - ProviderTableMeta._ID + "=?", - new String[] { String.valueOf(id) }); - - } catch (RemoteException e) { - Log_OC.e(TAG, "Exception in update of folder size through compatibility patch " + e.getMessage()); - } - } - } else { - Log_OC.e(TAG, "not updating size for folder " + id); - } - } +// /** +// * +// * @param id +// */ +// private void updateFolderSize(long id) { +// if (id > FileDataStorageManager.ROOT_PARENT_ID) { +// Log_OC.d(TAG, "Updating size of " + id); +// if (getContentResolver() != null) { +// getContentResolver().update(ProviderTableMeta.CONTENT_URI_DIR, +// new ContentValues(), // won't be used, but cannot be null; crashes in KLP +// ProviderTableMeta._ID + "=?", +// new String[] { String.valueOf(id) }); +// } else { +// try { +// getContentProviderClient().update(ProviderTableMeta.CONTENT_URI_DIR, +// new ContentValues(), // won't be used, but cannot be null; crashes in KLP +// ProviderTableMeta._ID + "=?", +// new String[] { String.valueOf(id) }); +// +// } catch (RemoteException e) { +// Log_OC.e(TAG, "Exception in update of folder size through compatibility patch " + e.getMessage()); +// } +// } +// } else { +// Log_OC.e(TAG, "not updating size for folder " + id); +// } +// } public void removeFile(OCFile file, boolean removeDBData, boolean removeLocalCopy) { @@ -442,7 +441,7 @@ public class FileDataStorageManager { } else { getContentResolver().delete(file_uri, where, whereArgs); } - updateFolderSize(file.getParentId()); + //updateFolderSize(file.getParentId()); } if (removeLocalCopy && file.isDown() && file.getStoragePath() != null) { boolean success = new File(file.getStoragePath()).delete(); @@ -482,7 +481,7 @@ public class FileDataStorageManager { } else { getContentResolver().delete(folder_uri, where, whereArgs); } - updateFolderSize(folder.getParentId()); + //updateFolderSize(folder.getParentId()); } private void removeLocalFolder(File folder) { @@ -610,6 +609,35 @@ public class FileDataStorageManager { } + public Cursor getContent(long parentId) { + Log_OC.d(TAG, "getContent start"); + Uri req_uri = Uri.withAppendedPath( + ProviderTableMeta.CONTENT_URI_DIR, + String.valueOf(parentId)); + Cursor c = null; + + if (getContentProviderClient() != null) { + try { + c = getContentProviderClient().query(req_uri, null, + ProviderTableMeta.FILE_PARENT + "=?" , + new String[] { String.valueOf(parentId)}, null); + } catch (RemoteException e) { + Log_OC.e(TAG, e.getMessage()); + return c; + } + } else { + c = getContentResolver().query(req_uri, null, + ProviderTableMeta.FILE_PARENT + "=?" , + new String[] { String.valueOf(parentId)}, null); + + //Log_OC.d(TAG, "getContent Uri " + req_uri); + //c.setNotificationUri(getContentResolver(), req_uri); + } + + Log_OC.d(TAG, "getContent end"); + return c; + } + private OCFile createRootDir() { OCFile file = new OCFile(OCFile.ROOT_PATH); file.setMimetype("DIR"); @@ -674,33 +702,33 @@ public class FileDataStorageManager { return c; } - private Cursor getShareCursorForValue(String key, String value) { - Cursor c = null; - if (getContentResolver() != null) { - c = getContentResolver() - .query(ProviderTableMeta.CONTENT_URI_SHARE, - null, - key + "=? AND " - + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER - + "=?", - new String[] { value, mAccount.name }, null); - } else { - try { - c = getContentProviderClient().query( - ProviderTableMeta.CONTENT_URI_SHARE, - null, - key + "=? AND " + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER - + "=?", new String[] { value, mAccount.name }, - null); - } catch (RemoteException e) { - Log_OC.e(TAG, "Could not get file details: " + e.getMessage()); - c = null; - } - } - return c; - } - - private OCFile createFileInstance(Cursor c) { +// private Cursor getShareCursorForValue(String key, String value) { +// Cursor c = null; +// if (getContentResolver() != null) { +// c = getContentResolver() +// .query(ProviderTableMeta.CONTENT_URI_SHARE, +// null, +// key + "=? AND " +// + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER +// + "=?", +// new String[] { value, mAccount.name }, null); +// } else { +// try { +// c = getContentProviderClient().query( +// ProviderTableMeta.CONTENT_URI_SHARE, +// null, +// key + "=? AND " + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER +// + "=?", new String[] { value, mAccount.name }, +// null); +// } catch (RemoteException e) { +// Log_OC.e(TAG, "Could not get file details: " + e.getMessage()); +// c = null; +// } +// } +// return c; +// } + + public OCFile createFileInstance(Cursor c) { OCFile file = null; if (c != null) { file = new OCFile(c.getString(c @@ -838,28 +866,53 @@ public class FileDataStorageManager { return overriden; } - private OCShare getShareById(long id) { - Cursor c = getShareCursorForValue(ProviderTableMeta._ID, String.valueOf(id)); - OCShare share = null; - if (c.moveToFirst()) { - share = createShareInstance(c); - } - c.close(); - return share; - } +// private OCShare getShareById(long id) { +// Cursor c = getShareCursorForValue(ProviderTableMeta._ID, String.valueOf(id)); +// OCShare share = null; +// if (c.moveToFirst()) { +// share = createShareInstance(c); +// } +// c.close(); +// return share; +// } +// +// private OCShare getShareByRemoteId(long remoteId) { +// Cursor c = getShareCursorForValue(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, String.valueOf(remoteId)); +// OCShare share = null; +// if (c.moveToFirst()) { +// share = createShareInstance(c); +// } +// c.close(); +// return share; +// } + + public OCShare getFirstShareByPathAndType(String path, ShareType type) { + Cursor c = null; + if (getContentResolver() != null) { + c = getContentResolver().query( + ProviderTableMeta.CONTENT_URI_SHARE, + null, + ProviderTableMeta.OCSHARES_PATH + "=? AND " + + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? AND " + + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?", + new String[] { path, Integer.toString(type.getValue()), mAccount.name }, + null); + } else { + try { + c = getContentProviderClient().query( + ProviderTableMeta.CONTENT_URI_SHARE, + null, + ProviderTableMeta.OCSHARES_PATH + "=? AND " + + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? AND " + + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?", + new String[] { path, Integer.toString(type.getValue()), mAccount.name }, + null); - private OCShare getShareByRemoteId(long remoteId) { - Cursor c = getShareCursorForValue(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, String.valueOf(remoteId)); - OCShare share = null; - if (c.moveToFirst()) { - share = createShareInstance(c); + } catch (RemoteException e) { + Log_OC.e(TAG, "Could not get file details: " + e.getMessage()); + c = null; + } } - c.close(); - return share; - } - - public OCShare getShareByPath(String path) { - Cursor c = getShareCursorForValue(ProviderTableMeta.OCSHARES_PATH, path); OCShare share = null; if (c.moveToFirst()) { share = createShareInstance(c); @@ -1115,8 +1168,22 @@ public class FileDataStorageManager { } } - - + + public void removeShare(OCShare share){ + Uri share_uri = ProviderTableMeta.CONTENT_URI_SHARE; + String where = ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?" + " AND " + ProviderTableMeta.FILE_PATH + "=?"; + String [] whereArgs = new String[]{mAccount.name, share.getPath()}; + if (getContentProviderClient() != null) { + try { + getContentProviderClient().delete(share_uri, where, whereArgs); + } catch (RemoteException e) { + e.printStackTrace(); + } + } else { + getContentResolver().delete(share_uri, where, whereArgs); + } + } + public void saveSharesDB(ArrayList shares) { saveShares(shares); @@ -1262,4 +1329,5 @@ public class FileDataStorageManager { */ //} } + }