From 7b57950abfed721ce1e4d4529d7ed080bc11dd44 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Wed, 14 Oct 2020 08:44:15 +0200 Subject: [PATCH] switch to users Signed-off-by: tobiasKaminsky --- .../client/jobs/AccountRemovalWork.kt | 2 +- .../client/jobs/ContactsBackupWork.kt | 2 +- .../client/jobs/MediaFoldersDetectionWork.kt | 7 ++-- .../java/com/owncloud/android/MainApp.java | 17 ++++---- .../datamodel/ArbitraryDataProvider.java | 40 +++++++++++++------ .../android/files/FileMenuFilter.java | 3 +- .../ui/activity/ManageAccountsActivity.java | 5 +-- .../android/ui/activity/SettingsActivity.java | 4 +- .../fragment/OCFileListBottomSheetDialog.java | 2 +- .../ui/fragment/OCFileListFragment.java | 12 ++---- .../ContactsBackupFragment.java | 6 +-- 11 files changed, 54 insertions(+), 46 deletions(-) diff --git a/src/main/java/com/nextcloud/client/jobs/AccountRemovalWork.kt b/src/main/java/com/nextcloud/client/jobs/AccountRemovalWork.kt index 6b9d2c4fd6..4acc435a54 100644 --- a/src/main/java/com/nextcloud/client/jobs/AccountRemovalWork.kt +++ b/src/main/java/com/nextcloud/client/jobs/AccountRemovalWork.kt @@ -135,7 +135,7 @@ class AccountRemovalWork( user: User, arbitraryDataProvider: ArbitraryDataProvider ) { - val arbitraryDataPushString = arbitraryDataProvider.getValue(user.toPlatformAccount(), PushUtils.KEY_PUSH) + val arbitraryDataPushString = arbitraryDataProvider.getValue(user, PushUtils.KEY_PUSH) val pushServerUrl = context.resources.getString(R.string.push_server_url) if (!TextUtils.isEmpty(arbitraryDataPushString) && !TextUtils.isEmpty(pushServerUrl)) { val gson = Gson() diff --git a/src/main/java/com/nextcloud/client/jobs/ContactsBackupWork.kt b/src/main/java/com/nextcloud/client/jobs/ContactsBackupWork.kt index fc61b3223d..3d3ca43167 100644 --- a/src/main/java/com/nextcloud/client/jobs/ContactsBackupWork.kt +++ b/src/main/java/com/nextcloud/client/jobs/ContactsBackupWork.kt @@ -88,7 +88,7 @@ class ContactsBackupWork( } val user = optionalUser.get() val lastExecution = arbitraryDataProvider.getLongValue( - user.toPlatformAccount(), + user, ContactsPreferenceActivity.PREFERENCE_CONTACTS_LAST_BACKUP ) val force = inputData.getBoolean(FORCE, false) diff --git a/src/main/java/com/nextcloud/client/jobs/MediaFoldersDetectionWork.kt b/src/main/java/com/nextcloud/client/jobs/MediaFoldersDetectionWork.kt index 4b07fecf1c..8577ac3e14 100644 --- a/src/main/java/com/nextcloud/client/jobs/MediaFoldersDetectionWork.kt +++ b/src/main/java/com/nextcloud/client/jobs/MediaFoldersDetectionWork.kt @@ -122,10 +122,9 @@ class MediaFoldersDetectionWork constructor( if (!imageMediaFolderPaths.isEmpty() || !videoMediaFolderPaths.isEmpty()) { val allUsers = userAccountManager.allUsers val activeUsers: MutableList = ArrayList() - for (account in allUsers) { - if (!arbitraryDataProvider.getBooleanValue(account.toPlatformAccount(), PENDING_FOR_REMOVAL) - ) { - activeUsers.add(account) + for (user in allUsers) { + if (!arbitraryDataProvider.getBooleanValue(user, PENDING_FOR_REMOVAL)) { + activeUsers.add(user) } } for (user in activeUsers) { diff --git a/src/main/java/com/owncloud/android/MainApp.java b/src/main/java/com/owncloud/android/MainApp.java index 250d497204..b0f93d6824 100644 --- a/src/main/java/com/owncloud/android/MainApp.java +++ b/src/main/java/com/owncloud/android/MainApp.java @@ -96,6 +96,7 @@ import javax.inject.Inject; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLEngine; +import androidx.annotation.NonNull; import androidx.annotation.RequiresApi; import androidx.annotation.StringRes; import androidx.appcompat.app.AlertDialog; @@ -303,40 +304,40 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector { registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() { @Override - public void onActivityCreated(Activity activity, Bundle savedInstanceState) { + public void onActivityCreated(@NonNull Activity activity, Bundle savedInstanceState) { Log_OC.d(activity.getClass().getSimpleName(), "onCreate(Bundle) starting"); onboarding.launchActivityIfNeeded(activity); } @Override - public void onActivityStarted(Activity activity) { + public void onActivityStarted(@NonNull Activity activity) { Log_OC.d(activity.getClass().getSimpleName(), "onStart() starting"); } @Override - public void onActivityResumed(Activity activity) { + public void onActivityResumed(@NonNull Activity activity) { Log_OC.d(activity.getClass().getSimpleName(), "onResume() starting"); passCodeManager.onActivityStarted(activity); } @Override - public void onActivityPaused(Activity activity) { + public void onActivityPaused(@NonNull Activity activity) { Log_OC.d(activity.getClass().getSimpleName(), "onPause() ending"); } @Override - public void onActivityStopped(Activity activity) { + public void onActivityStopped(@NonNull Activity activity) { Log_OC.d(activity.getClass().getSimpleName(), "onStop() ending"); passCodeManager.onActivityStopped(activity); } @Override - public void onActivitySaveInstanceState(Activity activity, Bundle outState) { + public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) { Log_OC.d(activity.getClass().getSimpleName(), "onSaveInstanceState(Bundle) starting"); } @Override - public void onActivityDestroyed(Activity activity) { + public void onActivityDestroyed(@NonNull Activity activity) { Log_OC.d(activity.getClass().getSimpleName(), "onDestroy() ending"); } }); @@ -354,7 +355,7 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector { ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(mContext.getContentResolver()); List users = accountManager.getAllUsers(); for (User user : users) { - if (arbitraryDataProvider.getBooleanValue(user.toPlatformAccount(), PREFERENCE_CONTACTS_AUTOMATIC_BACKUP)) { + if (arbitraryDataProvider.getBooleanValue(user, PREFERENCE_CONTACTS_AUTOMATIC_BACKUP)) { backgroundJobManager.schedulePeriodicContactsBackup(user); } diff --git a/src/main/java/com/owncloud/android/datamodel/ArbitraryDataProvider.java b/src/main/java/com/owncloud/android/datamodel/ArbitraryDataProvider.java index d02d18b772..f49acd78a7 100644 --- a/src/main/java/com/owncloud/android/datamodel/ArbitraryDataProvider.java +++ b/src/main/java/com/owncloud/android/datamodel/ArbitraryDataProvider.java @@ -26,6 +26,7 @@ import android.content.ContentValues; import android.database.Cursor; import android.net.Uri; +import com.nextcloud.client.account.User; import com.owncloud.android.db.ProviderMeta; import com.owncloud.android.lib.common.utils.Log_OC; @@ -124,14 +125,19 @@ public class ArbitraryDataProvider { } - public Long getLongValue(Account account, String key) { - return getLongValue(account.name, key); + public Long getLongValue(User user, String key) { + return getLongValue(user.getAccountName(), key); } public boolean getBooleanValue(String accountName, String key) { return TRUE.equalsIgnoreCase(getValue(accountName, key)); } + public boolean getBooleanValue(User user, String key) { + return getBooleanValue(user.getAccountName(), key); + } + + @Deprecated public boolean getBooleanValue(Account account, String key) { return getBooleanValue(account.name, key); } @@ -155,22 +161,34 @@ public class ArbitraryDataProvider { /** * Returns stored value as string or empty string + * * @return string if value found or empty string */ @NonNull + @Deprecated public String getValue(Account account, String key) { return account != null ? getValue(account.name, key) : ""; } + /** + * Returns stored value as string or empty string + * + * @return string if value found or empty string + */ + @NonNull + public String getValue(@Nullable User user, String key) { + return user != null ? getValue(user.getAccountName(), key) : ""; + } + public String getValue(String accountName, String key) { Cursor cursor = contentResolver.query( - ProviderMeta.ProviderTableMeta.CONTENT_URI_ARBITRARY_DATA, - null, - ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID + " = ? and " + - ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_KEY + " = ?", - new String[]{accountName, key}, - null - ); + ProviderMeta.ProviderTableMeta.CONTENT_URI_ARBITRARY_DATA, + null, + ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID + " = ? and " + + ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_KEY + " = ?", + new String[]{accountName, key}, + null + ); if (cursor != null) { if (cursor.moveToFirst()) { @@ -229,8 +247,4 @@ public class ArbitraryDataProvider { return dataSet; } - - - - } diff --git a/src/main/java/com/owncloud/android/files/FileMenuFilter.java b/src/main/java/com/owncloud/android/files/FileMenuFilter.java index 576c4996a6..2b1e6a3c2c 100644 --- a/src/main/java/com/owncloud/android/files/FileMenuFilter.java +++ b/src/main/java/com/owncloud/android/files/FileMenuFilter.java @@ -309,8 +309,7 @@ public class FileMenuFilter { @Nullable public static Editor getEditor(ContentResolver contentResolver, User user, String mimeType) { - String json = new ArbitraryDataProvider(contentResolver).getValue(user.toPlatformAccount(), - ArbitraryDataProvider.DIRECT_EDITING); + String json = new ArbitraryDataProvider(contentResolver).getValue(user, ArbitraryDataProvider.DIRECT_EDITING); if (json.isEmpty()) { return null; diff --git a/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java b/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java index d92194ee0c..aad2b87f00 100644 --- a/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java @@ -194,7 +194,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap List users = accountManager.getAllUsers(); List newList = new ArrayList<>(); for (User user : users) { - boolean pendingForRemoval = arbitraryDataProvider.getBooleanValue(user.toPlatformAccount(), PENDING_FOR_REMOVAL); + boolean pendingForRemoval = arbitraryDataProvider.getBooleanValue(user, PENDING_FOR_REMOVAL); if (!pendingForRemoval) { newList.add(user); @@ -246,8 +246,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap List users = accountManager.getAllUsers(); List userListItems = new ArrayList<>(users.size()); for (User user : users) { - boolean pendingForRemoval = arbitraryDataProvider.getBooleanValue(user.toPlatformAccount(), - PENDING_FOR_REMOVAL); + boolean pendingForRemoval = arbitraryDataProvider.getBooleanValue(user, PENDING_FOR_REMOVAL); userListItems.add(new UserListItem(user, !pendingForRemoval)); } diff --git a/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java b/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java index 8f43e24fee..c52986453e 100644 --- a/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java @@ -604,7 +604,7 @@ public class SettingsActivity extends ThemedPreferenceActivity final SwitchPreference pUploadOnWifiCheckbox = (SwitchPreference) findPreference("synced_folder_on_wifi"); pUploadOnWifiCheckbox.setChecked( - arbitraryDataProvider.getBooleanValue(user.toPlatformAccount(), SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI)); + arbitraryDataProvider.getBooleanValue(user, SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI)); pUploadOnWifiCheckbox.setOnPreferenceClickListener(preference -> { arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI, @@ -920,7 +920,7 @@ public class SettingsActivity extends ThemedPreferenceActivity } @Override - public void onConfigurationChanged(Configuration newConfig) { + public void onConfigurationChanged(@NonNull Configuration newConfig) { super.onConfigurationChanged(newConfig); getDelegate().onConfigurationChanged(newConfig); } diff --git a/src/main/java/com/owncloud/android/ui/fragment/OCFileListBottomSheetDialog.java b/src/main/java/com/owncloud/android/ui/fragment/OCFileListBottomSheetDialog.java index f29612b4d3..f5157748da 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/OCFileListBottomSheetDialog.java +++ b/src/main/java/com/owncloud/android/ui/fragment/OCFileListBottomSheetDialog.java @@ -134,7 +134,7 @@ public class OCFileListBottomSheetDialog extends BottomSheetDialog { } String json = new ArbitraryDataProvider(getContext().getContentResolver()) - .getValue(user.toPlatformAccount(), ArbitraryDataProvider.DIRECT_EDITING); + .getValue(user, ArbitraryDataProvider.DIRECT_EDITING); if (!json.isEmpty() && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && diff --git a/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java index 99a04fbd48..771f3be516 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -935,10 +935,8 @@ public class OCFileListFragment extends ExtendedListFragment implements getContext().getContentResolver()); - String publicKey = arbitraryDataProvider.getValue(user.toPlatformAccount(), - EncryptionUtils.PUBLIC_KEY); - String privateKey = arbitraryDataProvider.getValue(user.toPlatformAccount(), - EncryptionUtils.PRIVATE_KEY); + String publicKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PUBLIC_KEY); + String privateKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PRIVATE_KEY); if (publicKey.isEmpty() || privateKey.isEmpty()) { Log_OC.d(TAG, "no public key for " + user.getAccountName()); @@ -1639,10 +1637,8 @@ public class OCFileListFragment extends ExtendedListFragment implements new ArbitraryDataProvider(requireContext().getContentResolver()); - String publicKey = arbitraryDataProvider.getValue(user.toPlatformAccount(), - EncryptionUtils.PUBLIC_KEY); - String privateKey = arbitraryDataProvider.getValue(user.toPlatformAccount(), - EncryptionUtils.PRIVATE_KEY); + String publicKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PUBLIC_KEY); + String privateKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PRIVATE_KEY); if (publicKey.isEmpty() || privateKey.isEmpty()) { Log_OC.d(TAG, "no public key for " + user.getAccountName()); diff --git a/src/main/java/com/owncloud/android/ui/fragment/contactsbackup/ContactsBackupFragment.java b/src/main/java/com/owncloud/android/ui/fragment/contactsbackup/ContactsBackupFragment.java index 59fadbd0c7..6565db71a4 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/contactsbackup/ContactsBackupFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/contactsbackup/ContactsBackupFragment.java @@ -25,7 +25,6 @@ import android.accounts.Account; import android.app.DatePickerDialog; import android.content.DialogInterface; import android.content.Intent; -import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.os.Bundle; import android.view.LayoutInflater; @@ -135,6 +134,7 @@ public class ContactsBackupFragment extends FileFragment implements DatePickerDi final ContactsPreferenceActivity contactsPreferenceActivity = (ContactsPreferenceActivity) getActivity(); account = contactsPreferenceActivity.getAccount(); + User user = contactsPreferenceActivity.getUser().orElseThrow(RuntimeException::new); ActionBar actionBar = contactsPreferenceActivity != null ? contactsPreferenceActivity.getSupportActionBar() : null; @@ -148,7 +148,7 @@ public class ContactsBackupFragment extends FileFragment implements DatePickerDi arbitraryDataProvider = new ArbitraryDataProvider(getContext().getContentResolver()); ThemeUtils.tintSwitch(backupSwitch, ThemeUtils.primaryAccentColor(getContext())); - backupSwitch.setChecked(arbitraryDataProvider.getBooleanValue(account, PREFERENCE_CONTACTS_AUTOMATIC_BACKUP)); + backupSwitch.setChecked(arbitraryDataProvider.getBooleanValue(user, PREFERENCE_CONTACTS_AUTOMATIC_BACKUP)); onCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() { @Override @@ -166,7 +166,7 @@ public class ContactsBackupFragment extends FileFragment implements DatePickerDi backupSwitch.setOnCheckedChangeListener(onCheckedChangeListener); // display last backup - Long lastBackupTimestamp = arbitraryDataProvider.getLongValue(account, PREFERENCE_CONTACTS_LAST_BACKUP); + Long lastBackupTimestamp = arbitraryDataProvider.getLongValue(user, PREFERENCE_CONTACTS_LAST_BACKUP); if (lastBackupTimestamp == -1) { lastBackup.setText(R.string.contacts_preference_backup_never);