Add "open as" to profiles (#2340)
* Extract "open as" utilities to BaseActivity * Add "open as" to profiles. Fixes #2329 * Rename STATUS_URL intent extra key * Add nullability notations for new java code * Pacify ktlint
This commit is contained in:
parent
fcc9265703
commit
f822234995
6 changed files with 69 additions and 58 deletions
|
|
@ -197,6 +197,33 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
|
|||
.show();
|
||||
}
|
||||
|
||||
public @Nullable String getOpenAsText() {
|
||||
List<AccountEntity> accounts = accountManager.getAllAccountsOrderedByActive();
|
||||
switch (accounts.size()) {
|
||||
case 0:
|
||||
case 1:
|
||||
return null;
|
||||
case 2:
|
||||
for (AccountEntity account : accounts) {
|
||||
if (account != accountManager.getActiveAccount()) {
|
||||
return String.format(getString(R.string.action_open_as), account.getFullName());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
default:
|
||||
return String.format(getString(R.string.action_open_as), "…");
|
||||
}
|
||||
}
|
||||
|
||||
public void openAsAccount(@NonNull String url, @NonNull AccountEntity account) {
|
||||
accountManager.setActiveAccount(account);
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
intent.putExtra(MainActivity.REDIRECT_URL, url);
|
||||
startActivity(intent);
|
||||
finishWithoutSlideOutAnimation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue