switch to users

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2020-10-14 08:44:15 +02:00
parent baff5f2f64
commit 7b57950abf
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
11 changed files with 54 additions and 46 deletions

View file

@ -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()

View file

@ -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)

View file

@ -122,10 +122,9 @@ class MediaFoldersDetectionWork constructor(
if (!imageMediaFolderPaths.isEmpty() || !videoMediaFolderPaths.isEmpty()) {
val allUsers = userAccountManager.allUsers
val activeUsers: MutableList<User> = 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) {

View file

@ -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<User> 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);
}

View file

@ -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;
}
}

View file

@ -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;

View file

@ -194,7 +194,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap
List<User> users = accountManager.getAllUsers();
List<User> 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<User> users = accountManager.getAllUsers();
List<UserListItem> 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));
}

View file

@ -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);
}

View file

@ -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 &&

View file

@ -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());

View file

@ -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);