X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/ec19a11a385ff21d3e85a94e618d48d8be9ef20d..4457dbd3177fb6084f801187c35e09008bcd3b50:/src/com/owncloud/android/providers/FileContentProvider.java?ds=inline diff --git a/src/com/owncloud/android/providers/FileContentProvider.java b/src/com/owncloud/android/providers/FileContentProvider.java index a94454ce..b50609a5 100644 --- a/src/com/owncloud/android/providers/FileContentProvider.java +++ b/src/com/owncloud/android/providers/FileContentProvider.java @@ -1,6 +1,10 @@ -/* ownCloud Android client application +/** + * ownCloud Android client application + * + * @author Bartek Przybylski + * @author David A. Velasco * Copyright (C) 2011 Bartek Przybylski - * Copyright (C) 2012-2013 ownCloud Inc. + * Copyright (C) 2015 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -21,13 +25,16 @@ package com.owncloud.android.providers; import java.util.ArrayList; import java.util.HashMap; +import com.owncloud.android.MainApp; import com.owncloud.android.R; -import com.owncloud.android.datamodel.ThumbnailsCacheManager; import com.owncloud.android.db.ProviderMeta; import com.owncloud.android.db.ProviderMeta.ProviderTableMeta; +import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.shares.ShareType; +import android.accounts.Account; +import android.accounts.AccountManager; import android.content.ContentProvider; import android.content.ContentProviderOperation; import android.content.ContentProviderResult; @@ -46,10 +53,6 @@ import android.text.TextUtils; /** * The ContentProvider for the ownCloud App. - * - * @author Bartek Przybylski - * @author David A. Velasco - * */ public class FileContentProvider extends ContentProvider { @@ -98,6 +101,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; @@ -625,7 +630,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 @@ -682,9 +688,9 @@ public class FileContentProvider extends ContentProvider { Log_OC.i("SQL", "Entering in the #3 ADD in onUpgrade"); db.beginTransaction(); try { - db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME + - " ADD COLUMN " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + - " INTEGER " + " DEFAULT 0"); + db.execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME + + " ADD COLUMN " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + + " INTEGER " + " DEFAULT 0"); db.execSQL("UPDATE " + ProviderTableMeta.FILE_TABLE_NAME + " SET " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " = " + @@ -705,7 +711,7 @@ public class FileContentProvider extends ContentProvider { Log_OC.i("SQL", "Entering in the #4 ADD in onUpgrade"); db.beginTransaction(); try { - db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME + + db.execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME + " ADD COLUMN " + ProviderTableMeta.FILE_ETAG + " TEXT " + " DEFAULT NULL"); @@ -763,11 +769,11 @@ public class FileContentProvider extends ContentProvider { Log_OC.i("SQL", "Entering in the #7 ADD in onUpgrade"); db.beginTransaction(); try { - db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME + + db.execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME + " ADD COLUMN " + ProviderTableMeta.FILE_PERMISSIONS + " TEXT " + " DEFAULT NULL"); - db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME + + db.execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME + " ADD COLUMN " + ProviderTableMeta.FILE_REMOTE_ID + " TEXT " + " DEFAULT NULL"); @@ -785,7 +791,7 @@ public class FileContentProvider extends ContentProvider { Log_OC.i("SQL", "Entering in the #8 ADD in onUpgrade"); db.beginTransaction(); try { - db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME + + db.execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME + " ADD COLUMN " + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + " INTEGER " + " DEFAULT 0"); @@ -796,9 +802,77 @@ 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); + + if (oldVersion < 10 && newVersion >= 10) { + Log_OC.i("SQL", "Entering in the #10 ADD in onUpgrade"); + upgraded = updateAccountName(db); + } + if (!upgraded) + Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion); } } + + private boolean updateAccountName(SQLiteDatabase db){ + AccountManager ama = AccountManager.get(getContext()); + boolean upgradedResult = true; + boolean upgraded = false; + try { + // get accounts ALREADY UPDATED from AccountManager + Account[] accounts = AccountManager.get(getContext()).getAccountsByType(MainApp.getAccountType()); + String serverUrl, username, oldAccountName; + for (Account account : accounts) { + // build new account name + serverUrl = ama.getUserData(account, AccountUtils.Constants.KEY_OC_BASE_URL); + username = account.name.substring(0, account.name.lastIndexOf('@')); + oldAccountName = AccountUtils.buildAccountNameOld(Uri.parse(serverUrl), username); + + // update values in database + db.beginTransaction(); + try{ + db.execSQL("UPDATE " + ProviderTableMeta.FILE_TABLE_NAME + + " SET " + ProviderTableMeta.FILE_ACCOUNT_OWNER + " ='" + + account.name + "' " + + " WHERE " + ProviderTableMeta.FILE_ACCOUNT_OWNER + " ='" + + oldAccountName + "' " ); + upgraded = true; + db.setTransactionSuccessful(); + + Log_OC.i("SQL", "Updated account in database: old name == " + oldAccountName + + ", new name == " + account.name); + + } catch (SQLException e){ + upgraded = false; + } finally { + db.endTransaction(); + } + upgradedResult = upgraded && upgradedResult; + } + } catch (Exception e) { + Log_OC.i("Exception", "Exception:" + e); + } + + return upgradedResult; + } }