use account.hashCode instead of name as account switching value

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2019-05-16 11:34:13 +02:00
parent 16f7b4e17c
commit 28c7e74697
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
4 changed files with 67 additions and 45 deletions

View file

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

View file

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

View file

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

View file

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