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 e684f43ff..066b245bc 100644 --- a/app/src/main/java/app/fedilab/android/activities/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/BaseMainActivity.java @@ -2513,23 +2513,37 @@ public abstract class BaseMainActivity extends BaseActivity public void startSreaming() { - SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); - boolean liveNotifications = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, true); - if (liveNotifications) { - ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); - assert manager != null; - for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { - if (LiveNotificationDelayedService.class.getName().equals(service.service.getClassName())) { - return; + int liveNotifications = Helper.liveNotifType(getApplicationContext()); + switch (liveNotifications){ + case Helper.NOTIF_LIVE: + ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); + assert manager != null; + for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { + if (LiveNotificationDelayedService.class.getName().equals(service.service.getClassName())) { + return; + } } - } - try { - Intent streamingIntent = new Intent(this, LiveNotificationDelayedService.class); - startService(streamingIntent); - } catch (Exception ignored) { - } + try { + Intent streamingIntent = new Intent(this, LiveNotificationService.class); + startService(streamingIntent); + } catch (Exception ignored) { + } + break; + case Helper.NOTIF_DELAYED: + manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); + assert manager != null; + for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { + if (LiveNotificationDelayedService.class.getName().equals(service.service.getClassName())) { + return; + } + } + try { + Intent streamingIntent = new Intent(this, LiveNotificationDelayedService.class); + startService(streamingIntent); + } catch (Exception ignored) { + } + break; } - } public void manageFloatingButton(boolean display) { diff --git a/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java b/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java index 97124b108..059c8376d 100644 --- a/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java +++ b/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java @@ -88,6 +88,7 @@ import app.fedilab.android.filelister.FileListerDialog; import app.fedilab.android.filelister.OnFileSelectedListener; import app.fedilab.android.helper.Helper; import app.fedilab.android.services.LiveNotificationDelayedService; +import app.fedilab.android.services.LiveNotificationService; import app.fedilab.android.services.StopLiveNotificationReceiver; import app.fedilab.android.sqlite.AccountDAO; import app.fedilab.android.sqlite.Sqlite; @@ -1133,11 +1134,17 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable if (isChecked) { notification_settings.setVisibility(View.VISIBLE); try { - Intent streamingIntent = new Intent(context, LiveNotificationDelayedService.class); - context.startService(streamingIntent); - } catch (Exception ignored) { - ignored.printStackTrace(); - } + switch (Helper.liveNotifType(context)) { + case Helper.NOTIF_LIVE: + Intent streamingIntent = new Intent(context, LiveNotificationService.class); + context.startService(streamingIntent); + break; + case Helper.NOTIF_DELAYED: + streamingIntent = new Intent(context, LiveNotificationDelayedService.class); + context.startService(streamingIntent); + break; + } + } catch (Exception ignored) {} }else { notification_settings.setVisibility(View.GONE); context.sendBroadcast(new Intent(context, StopLiveNotificationReceiver.class)); @@ -1182,6 +1189,7 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { if (count2 > 0) { + context.sendBroadcast(new Intent(context, StopLiveNotificationReceiver.class)); SharedPreferences.Editor editor = sharedpreferences.edit(); switch (position) { case Helper.NOTIF_LIVE: @@ -1189,11 +1197,15 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable editor.putBoolean(Helper.SET_DELAYED_NOTIFICATIONS, false); live_notif_per_account.setVisibility(View.VISIBLE); editor.apply(); + Intent streamingIntent = new Intent(context, LiveNotificationService.class); + context.startService(streamingIntent); break; case Helper.NOTIF_DELAYED: editor.putBoolean(Helper.SET_LIVE_NOTIFICATIONS, false); editor.putBoolean(Helper.SET_DELAYED_NOTIFICATIONS, true); live_notif_per_account.setVisibility(View.VISIBLE); + streamingIntent = new Intent(context, LiveNotificationDelayedService.class); + context.startService(streamingIntent); editor.apply(); break; case Helper.NOTIF_NONE: @@ -1201,6 +1213,12 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable editor.putBoolean(Helper.SET_DELAYED_NOTIFICATIONS, false); live_notif_per_account.setVisibility(View.GONE); editor.apply(); + if (Build.VERSION.SDK_INT >= 26) { + NotificationManager notif = ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)); + if (notif != null) { + notif.deleteNotificationChannel(LiveNotificationDelayedService.CHANNEL_ID); + } + } break; } switch (Helper.liveNotifType(context)){ 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 f107592ba..e8a0043b5 100644 --- a/app/src/main/java/app/fedilab/android/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/helper/Helper.java @@ -406,9 +406,9 @@ public class Helper { public static final int THEME_DARK = 2; public static final int THEME_BLACK = 3; - public static final int NOTIF_LIVE = 2; + public static final int NOTIF_LIVE = 0; public static final int NOTIF_DELAYED = 1; - public static final int NOTIF_NONE = 0; + public static final int NOTIF_NONE = 2; public static final int LED_COLOUR = 0; 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 ba6fbbe94..98cb8f603 100644 --- a/app/src/main/java/app/fedilab/android/services/LiveNotificationDelayedService.java +++ b/app/src/main/java/app/fedilab/android/services/LiveNotificationDelayedService.java @@ -101,16 +101,17 @@ public class LiveNotificationDelayedService extends Service { if( thread != null && !thread.isInterrupted()){ thread.interrupt(); } + final boolean[] fetch = {Helper.liveNotifType(getApplicationContext()) == Helper.NOTIF_DELAYED}; thread = new Thread() { @Override public void run() { - //noinspection InfiniteLoopStatement - while (true) { + while (fetch[0]) { for (final Account accountStream : accountStreams) { if (accountStream.getSocial() == null || accountStream.getSocial().equals("MASTODON") || accountStream.getSocial().equals("PLEROMA")) { taks(accountStream); } } + fetch[0] = (Helper.liveNotifType(getApplicationContext()) == Helper.NOTIF_DELAYED); SystemClock.sleep(30000); } } diff --git a/app/src/main/res/layout/fragment_settings_reveal.xml b/app/src/main/res/layout/fragment_settings_reveal.xml index c9ee0131d..56d4baa52 100644 --- a/app/src/main/res/layout/fragment_settings_reveal.xml +++ b/app/src/main/res/layout/fragment_settings_reveal.xml @@ -554,6 +554,7 @@ android:textColor="@color/mastodonC2" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginBottom="10dp" />