From 28c7e7469792e1e3468e1ea01d6c65dd91919368 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Thu, 16 May 2019 11:34:13 +0200 Subject: [PATCH] use account.hashCode instead of name as account switching value Signed-off-by: tobiasKaminsky --- .drone.yml | 24 +++---- .../android/authentication/AccountUtils.java | 17 ++++- .../android/ui/activity/DrawerActivity.java | 69 ++++++++++--------- .../owncloud/android/utils/DisplayUtils.java | 2 +- 4 files changed, 67 insertions(+), 45 deletions(-) diff --git a/.drone.yml b/.drone.yml index 8273551e52..8236b30795 100644 --- a/.drone.yml +++ b/.drone.yml @@ -138,21 +138,21 @@ steps: recipients_only: true recipients: [ $EMAIL_RECIPIENTS ] environment: - EMAIL_USERNAME: + EMAIL_USERNAME: from_secret: EMAIL_USERNAME - EMAIL_PASSWORD: + EMAIL_PASSWORD: from_secret: EMAIL_PASSWORD - EMAIL_RECIPIENTS: - from_secret: EMAIL_RECIPIENTS - EMAIL_HOST: - from_secret: EMAIL_HOST + EMAIL_RECIPIENTS: + from_secret: EMAIL_RECIPIENTS + EMAIL_HOST: + from_secret: EMAIL_HOST when: - event: - - push - status: - - failure - branch: - - master + event: + - push + status: + - failure + branch: + - master trigger: branch: diff --git a/src/main/java/com/owncloud/android/authentication/AccountUtils.java b/src/main/java/com/owncloud/android/authentication/AccountUtils.java index d01a81595b..12e93abe18 100644 --- a/src/main/java/com/owncloud/android/authentication/AccountUtils.java +++ b/src/main/java/com/owncloud/android/authentication/AccountUtils.java @@ -138,7 +138,6 @@ public final class AccountUtils { return null; } - public static boolean setCurrentOwnCloudAccount(final Context context, String accountName) { boolean result = false; if (accountName != null) { @@ -155,6 +154,22 @@ public final class AccountUtils { return result; } + public static boolean setCurrentOwnCloudAccount(final Context context, int hashCode) { + boolean result = false; + if (hashCode != 0) { + for (final Account account : getAccounts(context)) { + if (hashCode == account.hashCode()) { + SharedPreferences.Editor appPrefs = PreferenceManager.getDefaultSharedPreferences(context).edit(); + appPrefs.putString(PREF_SELECT_OC_ACCOUNT, account.name); + appPrefs.apply(); + result = true; + break; + } + } + } + return result; + } + public static void resetOwnCloudAccount(Context context) { SharedPreferences.Editor appPrefs = PreferenceManager.getDefaultSharedPreferences(context).edit(); appPrefs.putString(PREF_SELECT_OC_ACCOUNT, null); diff --git a/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index a81bdb1ef7..70e8c61768 100644 --- a/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -41,7 +41,6 @@ import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.text.Html; -import android.text.TextUtils; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -412,6 +411,34 @@ public abstract class DrawerActivity extends ToolbarActivity setDrawerMenuItemChecked(menuItem.getItemId()); + if (menuItem.getGroupId() == R.id.drawer_menu_accounts) { + switch (menuItem.getItemId()) { + case R.id.drawer_menu_account_add: + boolean isProviderOrOwnInstallationVisible = getResources() + .getBoolean(R.bool.show_provider_or_own_installation); + + if (isProviderOrOwnInstallationVisible) { + Intent firstRunIntent = new Intent(getApplicationContext(), FirstRunActivity.class); + firstRunIntent.putExtra(FirstRunActivity.EXTRA_ALLOW_CLOSE, true); + startActivity(firstRunIntent); + } else { + createAccount(false); + } + break; + + case R.id.drawer_menu_account_manage: + Intent manageAccountsIntent = new Intent(getApplicationContext(), ManageAccountsActivity.class); + startActivityForResult(manageAccountsIntent, ACTION_MANAGE_ACCOUNTS); + break; + + default: + accountClicked(menuItem.getItemId()); + break; + } + + return; + } + switch (menuItem.getItemId()) { case R.id.nav_all_files: showFiles(false); @@ -469,22 +496,6 @@ public abstract class DrawerActivity extends ToolbarActivity menuItem.setChecked(false); UserInfoActivity.openAccountRemovalConfirmationDialog(getAccount(), getSupportFragmentManager(), true); break; - case R.id.drawer_menu_account_add: - boolean isProviderOrOwnInstallationVisible = getResources() - .getBoolean(R.bool.show_provider_or_own_installation); - - if (isProviderOrOwnInstallationVisible) { - Intent firstRunIntent = new Intent(getApplicationContext(), FirstRunActivity.class); - firstRunIntent.putExtra(FirstRunActivity.EXTRA_ALLOW_CLOSE, true); - startActivity(firstRunIntent); - } else { - createAccount(false); - } - break; - case R.id.drawer_menu_account_manage: - Intent manageAccountsIntent = new Intent(getApplicationContext(), ManageAccountsActivity.class); - startActivityForResult(manageAccountsIntent, ACTION_MANAGE_ACCOUNTS); - break; case R.id.nav_recently_added: handleSearchEvents(new SearchEvent("%", SearchRemoteOperation.SearchType.CONTENT_TYPE_SEARCH, SearchEvent.UnsetType.UNSET_BOTTOM_NAV_BAR), menuItem.getItemId()); @@ -501,10 +512,6 @@ public abstract class DrawerActivity extends ToolbarActivity handleSearchEvents(new SearchEvent("video/%", SearchRemoteOperation.SearchType.CONTENT_TYPE_SEARCH, SearchEvent.UnsetType.UNSET_BOTTOM_NAV_BAR), menuItem.getItemId()); break; - case Menu.NONE: - // account clicked - accountClicked(menuItem.getTitle().toString()); - break; default: if (menuItem.getItemId() >= MENU_ITEM_EXTERNAL_LINK && menuItem.getItemId() <= MENU_ITEM_EXTERNAL_LINK + 100) { @@ -542,12 +549,12 @@ public abstract class DrawerActivity extends ToolbarActivity * sets the new/current account and restarts. In case the given account equals the actual/current account the * call will be ignored. * - * @param accountName The account name to be set + * @param hashCode HashCode of account to be set */ - private void accountClicked(String accountName) { + private void accountClicked(int hashCode) { final Account currentAccount = accountManager.getCurrentAccount(); - if (currentAccount != null && !TextUtils.equals(currentAccount.name, accountName)) { - AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), accountName); + if (currentAccount != null && currentAccount.hashCode() != hashCode && + AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), hashCode)) { fetchExternalLinks(true); restart(); } @@ -577,7 +584,7 @@ public abstract class DrawerActivity extends ToolbarActivity * @param view the clicked ImageView */ public void onAccountDrawerClick(View view) { - accountClicked(view.getContentDescription().toString()); + accountClicked(Integer.parseInt(view.getContentDescription().toString())); } /** @@ -703,7 +710,7 @@ public abstract class DrawerActivity extends ToolbarActivity if (!getAccount().name.equals(account.name)) { MenuItem accountMenuItem = mNavigationView.getMenu().add( R.id.drawer_menu_accounts, - Menu.NONE, + account.hashCode(), MENU_ORDER_ACCOUNT, DisplayUtils.getAccountNameDisplayText(this, account, account.name, account.name)) .setIcon(TextDrawable.createAvatar(account, mMenuAccountAvatarRadiusDimension)); @@ -713,10 +720,10 @@ public abstract class DrawerActivity extends ToolbarActivity } catch (Exception e) { Log_OC.e(TAG, "Error calculating RGB value for account menu item.", e); mNavigationView.getMenu().add( - R.id.drawer_menu_accounts, - Menu.NONE, - MENU_ORDER_ACCOUNT, - DisplayUtils.getAccountNameDisplayText(this, account, account.name, account.name)) + R.id.drawer_menu_accounts, + account.hashCode(), + MENU_ORDER_ACCOUNT, + DisplayUtils.getAccountNameDisplayText(this, account, account.name, account.name)) .setIcon(R.drawable.ic_user); } } diff --git a/src/main/java/com/owncloud/android/utils/DisplayUtils.java b/src/main/java/com/owncloud/android/utils/DisplayUtils.java index eb77714a45..88d87a0d9c 100644 --- a/src/main/java/com/owncloud/android/utils/DisplayUtils.java +++ b/src/main/java/com/owncloud/android/utils/DisplayUtils.java @@ -463,7 +463,7 @@ public final class DisplayUtils { public static void setAvatar(@NonNull Account account, @NonNull String userId, AvatarGenerationListener listener, float avatarRadius, Resources resources, Object callContext, Context context) { if (callContext instanceof View) { - ((View) callContext).setContentDescription(account.name); + ((View) callContext).setContentDescription(String.valueOf(account.hashCode())); } ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context.getContentResolver());