Fix issue for stopping delayed/live notifications
This commit is contained in:
parent
3cdd467769
commit
59bc06c77c
|
@ -89,7 +89,13 @@
|
|||
<action android:name="StopLiveNotificationReceiver" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<receiver
|
||||
android:name="app.fedilab.android.services.StopDelayedNotificationReceiver"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="StopDelayedNotificationReceiver" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<service
|
||||
android:name="app.fedilab.android.services.StreamingHomeTimelineService"
|
||||
android:exported="false" />
|
||||
|
|
|
@ -646,9 +646,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
}
|
||||
|
||||
|
||||
if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
|
||||
Helper.startStreaming(BaseMainActivity.this);
|
||||
}
|
||||
Helper.startStreaming(BaseMainActivity.this);
|
||||
|
||||
if (hidde_menu != null)
|
||||
LocalBroadcastManager.getInstance(getApplicationContext()).unregisterReceiver(hidde_menu);
|
||||
|
|
|
@ -1351,11 +1351,12 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
|
|||
boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true);
|
||||
final SwitchCompat switchCompatNotify = rootView.findViewById(R.id.set_notify);
|
||||
switchCompatNotify.setChecked(notify);
|
||||
final LinearLayout notification_settings = rootView.findViewById(R.id.notification_settings);
|
||||
if (notify)
|
||||
notification_settings.setVisibility(View.VISIBLE);
|
||||
else
|
||||
notification_settings.setVisibility(View.GONE);
|
||||
final LinearLayout notification_container = rootView.findViewById(R.id.notification_container);
|
||||
if (notify) {
|
||||
notification_container.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
notification_container.setVisibility(View.GONE);
|
||||
}
|
||||
switchCompatNotify.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
|
@ -1364,9 +1365,15 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
|
|||
editor.putBoolean(Helper.SET_NOTIFY, isChecked);
|
||||
editor.apply();
|
||||
if (isChecked) {
|
||||
notification_settings.setVisibility(View.VISIBLE);
|
||||
notification_container.setVisibility(View.VISIBLE);
|
||||
notification_container.setVisibility(View.VISIBLE);
|
||||
Helper.startStreaming(context);
|
||||
}else {
|
||||
context.sendBroadcast(new Intent(context, StopLiveNotificationReceiver.class));
|
||||
context.sendBroadcast(new Intent(context, StopDelayedNotificationReceiver.class));
|
||||
ApplicationJob.cancelAllJob(NotificationsSyncJob.NOTIFICATION_REFRESH);
|
||||
notification_container.setVisibility(View.GONE);
|
||||
}
|
||||
Helper.startStreaming(context);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -4696,8 +4696,8 @@ public class Helper {
|
|||
} else {
|
||||
context.startService(streamingIntent);
|
||||
}
|
||||
context.startService(streamingIntent);
|
||||
} catch (Exception ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,7 +88,12 @@ public class LiveNotificationDelayedService extends Service {
|
|||
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true);
|
||||
if( !notify ){
|
||||
stopSelf();
|
||||
return;
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
channel = new NotificationChannel(CHANNEL_ID,
|
||||
"Live notifications",
|
||||
|
@ -102,7 +107,6 @@ public class LiveNotificationDelayedService extends Service {
|
|||
if( accountStreams != null) {
|
||||
for (Account account : accountStreams) {
|
||||
if (account.getSocial() == null || account.getSocial().equals("MASTODON") || account.getSocial().equals("PLEROMA") || account.getSocial().equals("PIXELFED")) {
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean allowStream = sharedpreferences.getBoolean(Helper.SET_ALLOW_STREAM + account.getId() + account.getInstance(), true);
|
||||
if (allowStream) {
|
||||
totalAccount++;
|
||||
|
@ -136,10 +140,16 @@ public class LiveNotificationDelayedService extends Service {
|
|||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
|
||||
if (intent == null || intent.getBooleanExtra("stop", false)) {
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true);
|
||||
if (!notify || intent == null || intent.getBooleanExtra("stop", false)) {
|
||||
totalAccount = 0;
|
||||
stopForeground(true);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
stopForeground(true);
|
||||
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
assert notificationManager != null;
|
||||
notificationManager.deleteNotificationChannel(CHANNEL_ID);
|
||||
}
|
||||
stopSelf();
|
||||
}
|
||||
if (totalAccount > 0) {
|
||||
|
|
|
@ -106,14 +106,17 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true);
|
||||
if( !notify ){
|
||||
stopSelf();
|
||||
return;
|
||||
}
|
||||
networkStateReceiver = new NetworkStateReceiver();
|
||||
networkStateReceiver.addListener(this);
|
||||
registerReceiver(networkStateReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION));
|
||||
|
||||
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
channel = new NotificationChannel(CHANNEL_ID,
|
||||
"Live notifications",
|
||||
|
@ -172,10 +175,16 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
|
||||
if (intent == null || intent.getBooleanExtra("stop", false)) {
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true);
|
||||
if (!notify || intent == null || intent.getBooleanExtra("stop", false)) {
|
||||
totalAccount = 0;
|
||||
stopForeground(true);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
stopForeground(true);
|
||||
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
assert notificationManager != null;
|
||||
notificationManager.deleteNotificationChannel(CHANNEL_ID);
|
||||
}
|
||||
stopSelf();
|
||||
}
|
||||
if (totalAccount > 0) {
|
||||
|
@ -187,8 +196,10 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
networkStateReceiver.removeListener(this);
|
||||
unregisterReceiver(networkStateReceiver);
|
||||
if( networkStateReceiver != null) {
|
||||
networkStateReceiver.removeListener(this);
|
||||
unregisterReceiver(networkStateReceiver);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 18/10/2019.
|
||||
* BroadcastReceiver for restarting delayed notification service
|
||||
|
@ -34,8 +35,7 @@ public class StopDelayedNotificationReceiver extends BroadcastReceiver {
|
|||
streamingServiceIntent.putExtra("stop", true);
|
||||
try {
|
||||
context.startService(streamingServiceIntent);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
}
|
|
@ -20,6 +20,7 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 22/09/2017.
|
||||
* BroadcastReceiver for restarting the service
|
||||
|
@ -34,9 +35,7 @@ public class StopLiveNotificationReceiver extends BroadcastReceiver {
|
|||
streamingServiceIntent.putExtra("stop", true);
|
||||
try {
|
||||
context.startService(streamingServiceIntent);
|
||||
} catch (Exception ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue