Some improvements

This commit is contained in:
tom79 2019-09-11 16:30:29 +02:00
parent da0e9d5a09
commit 4345c8c5ea
5 changed files with 58 additions and 24 deletions

View File

@ -2513,23 +2513,37 @@ public abstract class BaseMainActivity extends BaseActivity
public void startSreaming() { public void startSreaming() {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); int liveNotifications = Helper.liveNotifType(getApplicationContext());
boolean liveNotifications = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, true); switch (liveNotifications){
if (liveNotifications) { case Helper.NOTIF_LIVE:
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
assert manager != null; assert manager != null;
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (LiveNotificationDelayedService.class.getName().equals(service.service.getClassName())) { if (LiveNotificationDelayedService.class.getName().equals(service.service.getClassName())) {
return; return;
}
} }
} try {
try { Intent streamingIntent = new Intent(this, LiveNotificationService.class);
Intent streamingIntent = new Intent(this, LiveNotificationDelayedService.class); startService(streamingIntent);
startService(streamingIntent); } catch (Exception ignored) {
} 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) { public void manageFloatingButton(boolean display) {

View File

@ -88,6 +88,7 @@ import app.fedilab.android.filelister.FileListerDialog;
import app.fedilab.android.filelister.OnFileSelectedListener; import app.fedilab.android.filelister.OnFileSelectedListener;
import app.fedilab.android.helper.Helper; import app.fedilab.android.helper.Helper;
import app.fedilab.android.services.LiveNotificationDelayedService; import app.fedilab.android.services.LiveNotificationDelayedService;
import app.fedilab.android.services.LiveNotificationService;
import app.fedilab.android.services.StopLiveNotificationReceiver; import app.fedilab.android.services.StopLiveNotificationReceiver;
import app.fedilab.android.sqlite.AccountDAO; import app.fedilab.android.sqlite.AccountDAO;
import app.fedilab.android.sqlite.Sqlite; import app.fedilab.android.sqlite.Sqlite;
@ -1133,11 +1134,17 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
if (isChecked) { if (isChecked) {
notification_settings.setVisibility(View.VISIBLE); notification_settings.setVisibility(View.VISIBLE);
try { try {
Intent streamingIntent = new Intent(context, LiveNotificationDelayedService.class); switch (Helper.liveNotifType(context)) {
context.startService(streamingIntent); case Helper.NOTIF_LIVE:
} catch (Exception ignored) { Intent streamingIntent = new Intent(context, LiveNotificationService.class);
ignored.printStackTrace(); context.startService(streamingIntent);
} break;
case Helper.NOTIF_DELAYED:
streamingIntent = new Intent(context, LiveNotificationDelayedService.class);
context.startService(streamingIntent);
break;
}
} catch (Exception ignored) {}
}else { }else {
notification_settings.setVisibility(View.GONE); notification_settings.setVisibility(View.GONE);
context.sendBroadcast(new Intent(context, StopLiveNotificationReceiver.class)); context.sendBroadcast(new Intent(context, StopLiveNotificationReceiver.class));
@ -1182,6 +1189,7 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (count2 > 0) { if (count2 > 0) {
context.sendBroadcast(new Intent(context, StopLiveNotificationReceiver.class));
SharedPreferences.Editor editor = sharedpreferences.edit(); SharedPreferences.Editor editor = sharedpreferences.edit();
switch (position) { switch (position) {
case Helper.NOTIF_LIVE: case Helper.NOTIF_LIVE:
@ -1189,11 +1197,15 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
editor.putBoolean(Helper.SET_DELAYED_NOTIFICATIONS, false); editor.putBoolean(Helper.SET_DELAYED_NOTIFICATIONS, false);
live_notif_per_account.setVisibility(View.VISIBLE); live_notif_per_account.setVisibility(View.VISIBLE);
editor.apply(); editor.apply();
Intent streamingIntent = new Intent(context, LiveNotificationService.class);
context.startService(streamingIntent);
break; break;
case Helper.NOTIF_DELAYED: case Helper.NOTIF_DELAYED:
editor.putBoolean(Helper.SET_LIVE_NOTIFICATIONS, false); editor.putBoolean(Helper.SET_LIVE_NOTIFICATIONS, false);
editor.putBoolean(Helper.SET_DELAYED_NOTIFICATIONS, true); editor.putBoolean(Helper.SET_DELAYED_NOTIFICATIONS, true);
live_notif_per_account.setVisibility(View.VISIBLE); live_notif_per_account.setVisibility(View.VISIBLE);
streamingIntent = new Intent(context, LiveNotificationDelayedService.class);
context.startService(streamingIntent);
editor.apply(); editor.apply();
break; break;
case Helper.NOTIF_NONE: case Helper.NOTIF_NONE:
@ -1201,6 +1213,12 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
editor.putBoolean(Helper.SET_DELAYED_NOTIFICATIONS, false); editor.putBoolean(Helper.SET_DELAYED_NOTIFICATIONS, false);
live_notif_per_account.setVisibility(View.GONE); live_notif_per_account.setVisibility(View.GONE);
editor.apply(); 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; break;
} }
switch (Helper.liveNotifType(context)){ switch (Helper.liveNotifType(context)){

View File

@ -406,9 +406,9 @@ public class Helper {
public static final int THEME_DARK = 2; public static final int THEME_DARK = 2;
public static final int THEME_BLACK = 3; 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_DELAYED = 1;
public static final int NOTIF_NONE = 0; public static final int NOTIF_NONE = 2;
public static final int LED_COLOUR = 0; public static final int LED_COLOUR = 0;

View File

@ -101,16 +101,17 @@ public class LiveNotificationDelayedService extends Service {
if( thread != null && !thread.isInterrupted()){ if( thread != null && !thread.isInterrupted()){
thread.interrupt(); thread.interrupt();
} }
final boolean[] fetch = {Helper.liveNotifType(getApplicationContext()) == Helper.NOTIF_DELAYED};
thread = new Thread() { thread = new Thread() {
@Override @Override
public void run() { public void run() {
//noinspection InfiniteLoopStatement while (fetch[0]) {
while (true) {
for (final Account accountStream : accountStreams) { for (final Account accountStream : accountStreams) {
if (accountStream.getSocial() == null || accountStream.getSocial().equals("MASTODON") || accountStream.getSocial().equals("PLEROMA")) { if (accountStream.getSocial() == null || accountStream.getSocial().equals("MASTODON") || accountStream.getSocial().equals("PLEROMA")) {
taks(accountStream); taks(accountStream);
} }
} }
fetch[0] = (Helper.liveNotifType(getApplicationContext()) == Helper.NOTIF_DELAYED);
SystemClock.sleep(30000); SystemClock.sleep(30000);
} }
} }

View File

@ -554,6 +554,7 @@
android:textColor="@color/mastodonC2" android:textColor="@color/mastodonC2"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
/> />
<LinearLayout <LinearLayout