Search in sources :

Example 21 with AccountEntity

use of com.keylesspalace.tusky.db.AccountEntity in project Tusky by Vavassor.

the class BaseActivity method redirectIfNotLoggedIn.

protected void redirectIfNotLoggedIn() {
    AccountEntity account = accountManager.getActiveAccount();
    if (account == null) {
        Intent intent = new Intent(this, LoginActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivityWithSlideInAnimation(intent);
        finish();
    }
}
Also used : Intent(android.content.Intent) AccountEntity(com.keylesspalace.tusky.db.AccountEntity)

Example 22 with AccountEntity

use of com.keylesspalace.tusky.db.AccountEntity 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)

Example 23 with AccountEntity

use of com.keylesspalace.tusky.db.AccountEntity in project Tusky by Vavassor.

the class NotificationHelper method deleteLegacyNotificationChannels.

public static void deleteLegacyNotificationChannels(@NonNull Context context, @NonNull AccountManager accountManager) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        // used until Tusky 1.4
        // noinspection ConstantConditions
        notificationManager.deleteNotificationChannel(CHANNEL_MENTION);
        notificationManager.deleteNotificationChannel(CHANNEL_FAVOURITE);
        notificationManager.deleteNotificationChannel(CHANNEL_BOOST);
        notificationManager.deleteNotificationChannel(CHANNEL_FOLLOW);
        // used until Tusky 1.7
        for (AccountEntity account : accountManager.getAllAccountsOrderedByActive()) {
            notificationManager.deleteNotificationChannel(CHANNEL_FAVOURITE + " " + account.getIdentifier());
        }
    }
}
Also used : NotificationManager(android.app.NotificationManager) AccountEntity(com.keylesspalace.tusky.db.AccountEntity)

Aggregations

AccountEntity (com.keylesspalace.tusky.db.AccountEntity)23 Intent (android.content.Intent)12 AccountManager (com.keylesspalace.tusky.db.AccountManager)9 ArrayList (java.util.ArrayList)4 NotificationManager (android.app.NotificationManager)3 Drawable (android.graphics.drawable.Drawable)3 MenuItem (android.view.MenuItem)3 Status (com.keylesspalace.tusky.entity.Status)3 Context (android.content.Context)2 SharedPreferences (android.content.SharedPreferences)2 Bitmap (android.graphics.Bitmap)2 Bundle (android.os.Bundle)2 FloatingActionButton (android.support.design.widget.FloatingActionButton)2 TabLayout (android.support.design.widget.TabLayout)2 ActionBar (android.support.v7.app.ActionBar)2 Toolbar (android.support.v7.widget.Toolbar)2 Log (android.util.Log)2 Menu (android.view.Menu)2 View (android.view.View)2 ImageView (android.widget.ImageView)2