diff --git a/app/src/main/java/app/fedilab/android/activities/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/activities/BaseMainActivity.java index b11cfe91b..0601f8d14 100644 --- a/app/src/main/java/app/fedilab/android/activities/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/BaseMainActivity.java @@ -246,6 +246,9 @@ public abstract class BaseMainActivity extends BaseActivity default: mLauncher = iconLauncher.BUBBLES; } + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putString(Helper.LOGO_LAUNCHER, icon); + editor.commit(); } } } diff --git a/app/src/main/java/app/fedilab/android/activities/LoginActivity.java b/app/src/main/java/app/fedilab/android/activities/LoginActivity.java index 981dee476..35186fb63 100644 --- a/app/src/main/java/app/fedilab/android/activities/LoginActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/LoginActivity.java @@ -256,27 +256,7 @@ public class LoginActivity extends BaseActivity { connectionButton = findViewById(R.id.login_button); info_instance = findViewById(R.id.info_instance); ImageView main_logo = findViewById(R.id.main_logo); - - switch (BaseMainActivity.mLauncher){ - case BUBBLES: - main_logo.setImageResource(R.drawable.fedilab_logo_bubble); - break; - case FEDIVERSE: - main_logo.setImageResource(R.drawable.fedilab_logo_fediverse); - break; - case HERO: - main_logo.setImageResource(R.drawable.fedilab_logo_hero); - break; - case ATOM: - main_logo.setImageResource(R.drawable.fedilab_logo_atom); - break; - case BRAINCRASH: - main_logo.setImageResource(R.drawable.fedilab_logo_braincrash); - break; - default: - main_logo.setImageResource(R.drawable.fedilab_logo_bubble); - } - + main_logo.setImageResource(Helper.getMainLogo(getApplicationContext())); socialNetwork = UpdateAccountInfoAsyncTask.SOCIAL.MASTODON; //Manage instances info_instance.setOnClickListener(new View.OnClickListener() { diff --git a/app/src/main/java/app/fedilab/android/helper/Helper.java b/app/src/main/java/app/fedilab/android/helper/Helper.java index 546d8ba99..b495886bd 100644 --- a/app/src/main/java/app/fedilab/android/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/helper/Helper.java @@ -210,6 +210,7 @@ import app.fedilab.android.client.Entities.Tag; import app.fedilab.android.client.Entities.TagTimeline; import app.fedilab.android.client.Entities.Version; import app.fedilab.android.client.Tls12SocketFactory; +import app.fedilab.android.fragments.ContentSettingsFragment; import app.fedilab.android.sqlite.MainMenuDAO; import app.fedilab.android.sqlite.StatusCacheDAO; import app.fedilab.android.sqlite.TimelineCacheDAO; @@ -355,6 +356,7 @@ public class Helper { public static final String SET_DISABLE_ANIMATED_EMOJI = "set_disable_animated_emoji"; public static final String SET_CAPITALIZE = "set_capitalize"; public static final String SET_WYSIWYG = "set_wysiwyg"; + public static final String LOGO_LAUNCHER = "logo_launcher"; public static final String SET_PICTURE_COMPRESSED = "set_picture_compressed"; public static final String SET_VIDEO_COMPRESSED = "set_picture_compressed"; public static final String SET_FORWARD_TAGS_IN_REPLY = "set_forward_tags_in_reply"; @@ -1177,29 +1179,8 @@ public class Helper { channelId = "channel_boost"; channelTitle = context.getString(R.string.channel_notif_boost); } - NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, channelId); - - switch (BaseMainActivity.mLauncher){ - case BUBBLES: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_bubbles); - break; - case FEDIVERSE: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_fediverse); - break; - case HERO: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_hero); - break; - case ATOM: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_atom); - break; - case BRAINCRASH: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_crash); - break; - default: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_bubbles); - } - - notificationBuilder.setTicker(message) + NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, channelId) + .setSmallIcon(getNotificationIcon(context)).setTicker(message) .setWhen(System.currentTimeMillis()) .setAutoCancel(true); if (notifType == MENTION) { @@ -1742,11 +1723,49 @@ public class Helper { changeAccount.putExtra(INTENT_ACTION, NOTIFICATION_INTENT); activity.finish(); activity.startActivity(changeAccount); - - } + public static int getNotificationIcon(Context context){ + final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + String logo = sharedpreferences.getString(Helper.LOGO_LAUNCHER, "bubbles"); + switch (logo) { + case "bubbles": + return R.drawable.ic_plain_bubbles; + case "fediverse": + return R.drawable.ic_plain_fediverse; + case "hero": + return R.drawable.ic_plain_hero; + case "atom": + return R.drawable.ic_plain_atom; + case "braincrash": + return R.drawable.ic_plain_crash; + default: + return R.drawable.ic_plain_bubbles; + } + } + + public static int getMainLogo(Context context){ + final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + String logo = sharedpreferences.getString(Helper.LOGO_LAUNCHER, "bubbles"); + switch (logo) { + case "bubbles": + return R.drawable.fedilab_logo_bubbles; + case "fediverse": + return R.drawable.fedilab_logo_fediverse; + case "hero": + return R.drawable.fedilab_logo_hero; + case "atom": + return R.drawable.fedilab_logo_atom; + case "braincrash": + return R.drawable.fedilab_logo_crash; + default: + return R.drawable.fedilab_logo_bubbles; + } + } + + + @SuppressWarnings("SameParameterValue") private static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int roundPixelSize) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.RGB_565); diff --git a/app/src/main/java/app/fedilab/android/jobs/NotificationsSyncJob.java b/app/src/main/java/app/fedilab/android/jobs/NotificationsSyncJob.java index 3a83f3fe8..f66c3ed69 100644 --- a/app/src/main/java/app/fedilab/android/jobs/NotificationsSyncJob.java +++ b/app/src/main/java/app/fedilab/android/jobs/NotificationsSyncJob.java @@ -62,6 +62,7 @@ import static app.fedilab.android.helper.Helper.NOTIFICATION_INTENT; import static app.fedilab.android.helper.Helper.PREF_INSTANCE; import static app.fedilab.android.helper.Helper.PREF_KEY_ID; import static app.fedilab.android.helper.Helper.canNotify; +import static app.fedilab.android.helper.Helper.getMainLogo; import static app.fedilab.android.helper.Helper.notify_user; @@ -293,30 +294,8 @@ public class NotificationsSyncJob extends Job { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { - int logo_icon = R.drawable.fedilab_logo_bubble; - switch (BaseMainActivity.mLauncher){ - case BUBBLES: - logo_icon = R.drawable.fedilab_logo_bubble; - break; - case FEDIVERSE: - logo_icon = R.drawable.fedilab_logo_fediverse; - break; - case HERO: - logo_icon = R.drawable.fedilab_logo_hero; - break; - case ATOM: - logo_icon = R.drawable.fedilab_logo_atom; - break; - case BRAINCRASH: - logo_icon = R.drawable.fedilab_logo_braincrash; - break; - default: - logo_icon = R.drawable.fedilab_logo_bubble; - } - - notify_user(getContext(), account, intent, BitmapFactory.decodeResource(getContext().getResources(), - logo_icon), finalNotifType, finalTitle, message); + getMainLogo(getContext())), finalNotifType, finalTitle, message); String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null); if (lastNotif == null || notifications.get(0).getId().compareTo(lastNotif) > 0) { SharedPreferences.Editor editor = sharedpreferences.edit(); diff --git a/app/src/main/java/app/fedilab/android/services/BackupNotificationInDataBaseService.java b/app/src/main/java/app/fedilab/android/services/BackupNotificationInDataBaseService.java index 86f64b5b8..e031b856a 100644 --- a/app/src/main/java/app/fedilab/android/services/BackupNotificationInDataBaseService.java +++ b/app/src/main/java/app/fedilab/android/services/BackupNotificationInDataBaseService.java @@ -150,29 +150,9 @@ public class BackupNotificationInDataBaseService extends IntentService { mainActivity.putExtra(Helper.INTENT_ACTION, Helper.BACKUP_NOTIFICATION_INTENT); String title = getString(R.string.data_backup_toots, account.getAcct()); if (finalToastMessage) { - int logo_icon = R.drawable.fedilab_logo_bubble; - switch (BaseMainActivity.mLauncher){ - case BUBBLES: - logo_icon = R.drawable.fedilab_logo_bubble; - break; - case FEDIVERSE: - logo_icon = R.drawable.fedilab_logo_fediverse; - break; - case HERO: - logo_icon = R.drawable.fedilab_logo_hero; - break; - case ATOM: - logo_icon = R.drawable.fedilab_logo_atom; - break; - case BRAINCRASH: - logo_icon = R.drawable.fedilab_logo_braincrash; - break; - default: - logo_icon = R.drawable.fedilab_logo_bubble; - } Helper.notify_user(getApplicationContext(), account, mainActivity, BitmapFactory.decodeResource(getResources(), - logo_icon), Helper.NotifType.BACKUP, title, message); + Helper.getMainLogo(getApplicationContext())), Helper.NotifType.BACKUP, title, message); } } catch (Exception e) { e.printStackTrace(); diff --git a/app/src/main/java/app/fedilab/android/services/BackupStatusInDataBaseService.java b/app/src/main/java/app/fedilab/android/services/BackupStatusInDataBaseService.java index 829b8bc09..df49ae9b8 100644 --- a/app/src/main/java/app/fedilab/android/services/BackupStatusInDataBaseService.java +++ b/app/src/main/java/app/fedilab/android/services/BackupStatusInDataBaseService.java @@ -150,28 +150,8 @@ public class BackupStatusInDataBaseService extends IntentService { mainActivity.putExtra(Helper.INTENT_ACTION, Helper.BACKUP_INTENT); String title = getString(R.string.data_backup_toots, account.getAcct()); if (finalToastMessage) { - int logo_icon = R.drawable.fedilab_logo_bubble; - switch (BaseMainActivity.mLauncher){ - case BUBBLES: - logo_icon = R.drawable.fedilab_logo_bubble; - break; - case FEDIVERSE: - logo_icon = R.drawable.fedilab_logo_fediverse; - break; - case HERO: - logo_icon = R.drawable.fedilab_logo_hero; - break; - case ATOM: - logo_icon = R.drawable.fedilab_logo_atom; - break; - case BRAINCRASH: - logo_icon = R.drawable.fedilab_logo_braincrash; - break; - default: - logo_icon = R.drawable.fedilab_logo_bubble; - } Helper.notify_user(getApplicationContext(), account, mainActivity, BitmapFactory.decodeResource(getResources(), - logo_icon), Helper.NotifType.BACKUP, title, message); + Helper.getMainLogo(getApplicationContext())), Helper.NotifType.BACKUP, title, message); } } catch (Exception e) { e.printStackTrace(); diff --git a/app/src/main/java/app/fedilab/android/services/BackupStatusService.java b/app/src/main/java/app/fedilab/android/services/BackupStatusService.java index 8ec57f888..91908b2b1 100644 --- a/app/src/main/java/app/fedilab/android/services/BackupStatusService.java +++ b/app/src/main/java/app/fedilab/android/services/BackupStatusService.java @@ -189,28 +189,8 @@ public class BackupStatusService extends IntentService { Uri uri = Uri.parse("file://" + fullPath); intentOpen.setDataAndType(uri, "text/csv"); String title = getString(R.string.data_export_toots, account.getAcct()); - int logo_icon = R.drawable.fedilab_logo_bubble; - switch (BaseMainActivity.mLauncher){ - case BUBBLES: - logo_icon = R.drawable.fedilab_logo_bubble; - break; - case FEDIVERSE: - logo_icon = R.drawable.fedilab_logo_fediverse; - break; - case HERO: - logo_icon = R.drawable.fedilab_logo_hero; - break; - case ATOM: - logo_icon = R.drawable.fedilab_logo_atom; - break; - case BRAINCRASH: - logo_icon = R.drawable.fedilab_logo_braincrash; - break; - default: - logo_icon = R.drawable.fedilab_logo_bubble; - } Helper.notify_user(getApplicationContext(), account, intentOpen, BitmapFactory.decodeResource(getResources(), - logo_icon), Helper.NotifType.BACKUP, title, message); + Helper.getMainLogo(getApplicationContext())), Helper.NotifType.BACKUP, title, message); } catch (Exception e) { e.printStackTrace(); message = getString(R.string.data_export_error, account.getAcct()); diff --git a/app/src/main/java/app/fedilab/android/services/LiveNotificationDelayedService.java b/app/src/main/java/app/fedilab/android/services/LiveNotificationDelayedService.java index cf3674e5a..3e2426ffc 100644 --- a/app/src/main/java/app/fedilab/android/services/LiveNotificationDelayedService.java +++ b/app/src/main/java/app/fedilab/android/services/LiveNotificationDelayedService.java @@ -65,6 +65,8 @@ import app.fedilab.android.sqlite.AccountDAO; import app.fedilab.android.sqlite.Sqlite; import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY; +import static app.fedilab.android.helper.Helper.getMainLogo; +import static app.fedilab.android.helper.Helper.getNotificationIcon; /** @@ -140,28 +142,10 @@ public class LiveNotificationDelayedService extends Service { } } } - NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, CHANNEL_ID). - setContentTitle(getString(R.string.top_notification)); - switch (BaseMainActivity.mLauncher){ - case BUBBLES: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_bubbles); - break; - case FEDIVERSE: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_fediverse); - break; - case HERO: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_hero); - break; - case ATOM: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_atom); - break; - case BRAINCRASH: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_crash); - break; - default: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_bubbles); - } - android.app.Notification notification = notificationBuilder.setContentText(getString(R.string.top_notification_message, String.valueOf(totalAccount), String.valueOf(eventsCount))).build(); + android.app.Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID). + setContentTitle(getString(R.string.top_notification)) + .setSmallIcon(getNotificationIcon(getApplicationContext())) + .setContentText(getString(R.string.top_notification_message, String.valueOf(totalAccount), String.valueOf(eventsCount))).build(); startForeground(1, notification); } @@ -240,28 +224,9 @@ public class LiveNotificationDelayedService extends Service { "Live notifications", NotificationManager.IMPORTANCE_DEFAULT); ((NotificationManager) Objects.requireNonNull(getSystemService(Context.NOTIFICATION_SERVICE))).createNotificationChannel(channel); - NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, CHANNEL_ID) - .setContentTitle(getString(R.string.top_notification)); - switch (BaseMainActivity.mLauncher){ - case BUBBLES: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_bubbles); - break; - case FEDIVERSE: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_fediverse); - break; - case HERO: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_hero); - break; - case ATOM: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_atom); - break; - case BRAINCRASH: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_crash); - break; - default: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_bubbles); - } - android.app.Notification notificationChannel = notificationBuilder.setContentText(getString(R.string.top_notification_message, String.valueOf(totalAccount), String.valueOf(eventsCount))).build(); + android.app.Notification notificationChannel = new NotificationCompat.Builder(this, CHANNEL_ID) + .setContentTitle(getString(R.string.top_notification)) + .setSmallIcon(getNotificationIcon(getApplicationContext())).setContentText(getString(R.string.top_notification_message, String.valueOf(totalAccount), String.valueOf(eventsCount))).build(); startForeground(1, notificationChannel); } @@ -383,28 +348,8 @@ public class LiveNotificationDelayedService extends Service { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { - int logo_icon = R.drawable.fedilab_logo_bubble; - switch (BaseMainActivity.mLauncher){ - case BUBBLES: - logo_icon = R.drawable.fedilab_logo_bubble; - break; - case FEDIVERSE: - logo_icon = R.drawable.fedilab_logo_fediverse; - break; - case HERO: - logo_icon = R.drawable.fedilab_logo_hero; - break; - case ATOM: - logo_icon = R.drawable.fedilab_logo_atom; - break; - case BRAINCRASH: - logo_icon = R.drawable.fedilab_logo_braincrash; - break; - default: - logo_icon = R.drawable.fedilab_logo_bubble; - } Helper.notify_user(getApplicationContext(), account, intent, BitmapFactory.decodeResource(getResources(), - logo_icon), finalNotifType, "@" + notification.getAccount().getAcct(), finalMessage); + getMainLogo(getApplicationContext())), finalNotifType, "@" + notification.getAccount().getAcct(), finalMessage); return false; } }) diff --git a/app/src/main/java/app/fedilab/android/services/LiveNotificationService.java b/app/src/main/java/app/fedilab/android/services/LiveNotificationService.java index ed54d8d7e..6b2c140ee 100644 --- a/app/src/main/java/app/fedilab/android/services/LiveNotificationService.java +++ b/app/src/main/java/app/fedilab/android/services/LiveNotificationService.java @@ -82,6 +82,8 @@ import app.fedilab.android.activities.MainActivity; import me.leolin.shortcutbadger.ShortcutBadger; import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY; +import static app.fedilab.android.helper.Helper.getMainLogo; +import static app.fedilab.android.helper.Helper.getNotificationIcon; /** @@ -157,30 +159,10 @@ public class LiveNotificationService extends Service implements NetworkStateRece } } - NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, CHANNEL_ID) - .setContentTitle(getString(R.string.top_notification)); - - switch (BaseMainActivity.mLauncher){ - case BUBBLES: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_bubbles); - break; - case FEDIVERSE: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_fediverse); - break; - case HERO: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_hero); - break; - case ATOM: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_atom); - break; - case BRAINCRASH: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_crash); - break; - default: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_bubbles); - } - - android.app.Notification notification = notificationBuilder.setContentText(getString(R.string.top_notification_message, String.valueOf(totalAccount), String.valueOf(eventsCount))).build(); + android.app.Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID) + .setContentTitle(getString(R.string.top_notification)) + .setSmallIcon(getNotificationIcon(getApplicationContext())) + .setContentText(getString(R.string.top_notification_message, String.valueOf(totalAccount), String.valueOf(eventsCount))).build(); startForeground(1, notification); } @@ -320,28 +302,10 @@ public class LiveNotificationService extends Service implements NetworkStateRece "Live notifications", NotificationManager.IMPORTANCE_DEFAULT); ((NotificationManager) Objects.requireNonNull(getSystemService(Context.NOTIFICATION_SERVICE))).createNotificationChannel(channel); - NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, CHANNEL_ID) - .setContentTitle(getString(R.string.top_notification)); - switch (BaseMainActivity.mLauncher){ - case BUBBLES: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_bubbles); - break; - case FEDIVERSE: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_fediverse); - break; - case HERO: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_hero); - break; - case ATOM: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_atom); - break; - case BRAINCRASH: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_crash); - break; - default: - notificationBuilder.setSmallIcon(R.drawable.ic_plain_bubbles); - } - android.app.Notification notificationChannel = notificationBuilder.setContentText(getString(R.string.top_notification_message, String.valueOf(totalAccount), String.valueOf(eventsCount))).build(); + android.app.Notification notificationChannel = new NotificationCompat.Builder(this, CHANNEL_ID) + .setContentTitle(getString(R.string.top_notification)) + .setSmallIcon(getNotificationIcon(getApplicationContext())) + .setContentText(getString(R.string.top_notification_message, String.valueOf(totalAccount), String.valueOf(eventsCount))).build(); startForeground(1, notificationChannel); } @@ -476,28 +440,8 @@ public class LiveNotificationService extends Service implements NetworkStateRece @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { - int logo_icon = R.drawable.fedilab_logo_bubble; - switch (BaseMainActivity.mLauncher){ - case BUBBLES: - logo_icon = R.drawable.fedilab_logo_bubble; - break; - case FEDIVERSE: - logo_icon = R.drawable.fedilab_logo_fediverse; - break; - case HERO: - logo_icon = R.drawable.fedilab_logo_hero; - break; - case ATOM: - logo_icon = R.drawable.fedilab_logo_atom; - break; - case BRAINCRASH: - logo_icon = R.drawable.fedilab_logo_braincrash; - break; - default: - logo_icon = R.drawable.fedilab_logo_bubble; - } Helper.notify_user(getApplicationContext(), account, intent, BitmapFactory.decodeResource(getResources(), - logo_icon), finalNotifType, "@" + notification.getAccount().getAcct(), finalMessage); + getMainLogo(getApplicationContext())), finalNotifType, "@" + notification.getAccount().getAcct(), finalMessage); return false; } })