Search in sources :

Example 1 with AccountSelectionListener

use of com.keylesspalace.tusky.interfaces.AccountSelectionListener in project Tusky by Vavassor.

the class BaseActivity method showAccountChooserDialog.

public void showAccountChooserDialog(CharSequence dialogTitle, boolean showActiveAccount, AccountSelectionListener listener) {
    List<AccountEntity> accounts = accountManager.getAllAccountsOrderedByActive();
    AccountEntity activeAccount = accountManager.getActiveAccount();
    switch(accounts.size()) {
        case 1:
            listener.onAccountSelected(activeAccount);
            return;
        case 2:
            if (!showActiveAccount) {
                for (AccountEntity account : accounts) {
                    if (activeAccount != account) {
                        listener.onAccountSelected(account);
                        return;
                    }
                }
            }
            break;
    }
    if (!showActiveAccount && activeAccount != null) {
        accounts.remove(activeAccount);
    }
    AccountSelectionAdapter adapter = new AccountSelectionAdapter(this);
    adapter.addAll(accounts);
    new AlertDialog.Builder(this).setTitle(dialogTitle).setAdapter(adapter, (dialogInterface, index) -> listener.onAccountSelected(accounts.get(index))).show();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) ActivityManager(android.app.ActivityManager) Context(android.content.Context) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) PackageManager(android.content.pm.PackageManager) NonNull(androidx.annotation.NonNull) Intent(android.content.Intent) BitmapFactory(android.graphics.BitmapFactory) HashMap(java.util.HashMap) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) AccountSelectionAdapter(com.keylesspalace.tusky.adapter.AccountSelectionAdapter) View(android.view.View) ContextCompat(androidx.core.content.ContextCompat) Log(android.util.Log) ThemeUtils(com.keylesspalace.tusky.util.ThemeUtils) AccountSelectionListener(com.keylesspalace.tusky.interfaces.AccountSelectionListener) ActivityCompat(androidx.core.app.ActivityCompat) PermissionRequester(com.keylesspalace.tusky.interfaces.PermissionRequester) StringRes(androidx.annotation.StringRes) List(java.util.List) Nullable(androidx.annotation.Nullable) SharedPreferences(android.content.SharedPreferences) Bitmap(android.graphics.Bitmap) PreferenceManager(androidx.preference.PreferenceManager) AccountManager(com.keylesspalace.tusky.db.AccountManager) Injectable(com.keylesspalace.tusky.di.Injectable) Snackbar(com.google.android.material.snackbar.Snackbar) AccountEntity(com.keylesspalace.tusky.db.AccountEntity) AccountSelectionAdapter(com.keylesspalace.tusky.adapter.AccountSelectionAdapter) AccountEntity(com.keylesspalace.tusky.db.AccountEntity)

Aggregations

ActivityManager (android.app.ActivityManager)1 Context (android.content.Context)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 PackageManager (android.content.pm.PackageManager)1 Bitmap (android.graphics.Bitmap)1 BitmapFactory (android.graphics.BitmapFactory)1 Bundle (android.os.Bundle)1 Log (android.util.Log)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 StringRes (androidx.annotation.StringRes)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)1 ActivityCompat (androidx.core.app.ActivityCompat)1 ContextCompat (androidx.core.content.ContextCompat)1 PreferenceManager (androidx.preference.PreferenceManager)1 Snackbar (com.google.android.material.snackbar.Snackbar)1