Better management of live notifications
This commit is contained in:
parent
1f7df5457a
commit
8e2d022302
|
@ -57,10 +57,6 @@ public class LiveNotificationSettingsAccountsActivity extends BaseActivity {
|
|||
setTheme(R.style.AppTheme_NoActionBar_Fedilab);
|
||||
getWindow().getDecorView().setBackgroundColor(ContextCompat.getColor(LiveNotificationSettingsAccountsActivity.this, R.color.mastodonC3__));
|
||||
break;
|
||||
case Helper.THEME_DARK:
|
||||
setTheme(R.style.AppThemeDark_NoActionBar);
|
||||
getWindow().getDecorView().setBackgroundColor(ContextCompat.getColor(LiveNotificationSettingsAccountsActivity.this, R.color.mastodonC1));
|
||||
break;
|
||||
case Helper.THEME_BLACK:
|
||||
setTheme(R.style.AppThemeBlack_NoActionBar);
|
||||
getWindow().getDecorView().setBackgroundColor(ContextCompat.getColor(LiveNotificationSettingsAccountsActivity.this, R.color.black_3));
|
||||
|
|
|
@ -31,7 +31,6 @@ import android.net.Uri;
|
|||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
|
|
|
@ -15,8 +15,11 @@ package app.fedilab.android.drawers;
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -29,6 +32,9 @@ import app.fedilab.android.R;
|
|||
import app.fedilab.android.client.Entities.Account;
|
||||
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 static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
|
||||
|
@ -74,6 +80,27 @@ public class AccountLiveAdapter extends RecyclerView.Adapter {
|
|||
} else {
|
||||
LiveNotificationDelayedService.totalAccount--;
|
||||
}
|
||||
int type = Helper.liveNotifType(context);
|
||||
context.sendBroadcast(new Intent(context, StopLiveNotificationReceiver.class));
|
||||
switch (type) {
|
||||
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);
|
||||
editor.apply();
|
||||
break;
|
||||
case Helper.NOTIF_NONE:
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
NotificationManager notif = ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE));
|
||||
if (notif != null) {
|
||||
notif.deleteNotificationChannel(LiveNotificationDelayedService.CHANNEL_ID);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ import android.net.Uri;
|
|||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -168,7 +167,6 @@ public class MediaSliderFragment extends Fragment implements MediaPlayer.OnCompl
|
|||
if( ! ((SlideMediaActivity)context).getFullScreen()) {
|
||||
((SlideMediaActivity) context).setFullscreen(true);
|
||||
}
|
||||
Log.v(Helper.TAG,"canSwipe! " + canSwipe);
|
||||
((SlideMediaActivity) context).enableSliding(false);
|
||||
}else{
|
||||
((SlideMediaActivity) context).enableSliding(true);
|
||||
|
|
|
@ -84,9 +84,12 @@ public class LiveNotificationDelayedService extends Service {
|
|||
public static HashMap<String, String> since_ids = new HashMap<>();
|
||||
private static Thread thread;
|
||||
private boolean fetch;
|
||||
public boolean zeroAccounts;
|
||||
|
||||
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
}
|
||||
|
||||
private void startStream() {
|
||||
|
@ -124,6 +127,7 @@ public class LiveNotificationDelayedService extends Service {
|
|||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
zeroAccounts = false;
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
channel = new NotificationChannel(CHANNEL_ID,
|
||||
"Live notifications",
|
||||
|
@ -142,13 +146,19 @@ public class LiveNotificationDelayedService extends Service {
|
|||
}
|
||||
}
|
||||
}
|
||||
android.app.Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
|
||||
.setShowWhen(false)
|
||||
.setContentTitle(getString(R.string.top_notification))
|
||||
.setSmallIcon(R.drawable.fedilab_notification_icon)
|
||||
.setContentText(getString(R.string.top_notification_message, String.valueOf(totalAccount), String.valueOf(eventsCount))).build();
|
||||
if( totalAccount > 0) {
|
||||
android.app.Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
|
||||
.setShowWhen(false)
|
||||
.setContentTitle(getString(R.string.top_notification))
|
||||
.setSmallIcon(R.drawable.fedilab_notification_icon)
|
||||
.setContentText(getString(R.string.top_notification_message, String.valueOf(totalAccount), String.valueOf(eventsCount))).build();
|
||||
|
||||
startForeground(1, notification);
|
||||
startForeground(1, notification);
|
||||
}else{
|
||||
stopSelf();
|
||||
zeroAccounts = true;
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
}
|
||||
startStream();
|
||||
return START_STICKY;
|
||||
|
@ -164,7 +174,9 @@ public class LiveNotificationDelayedService extends Service {
|
|||
@Override
|
||||
public void onTaskRemoved(Intent rootIntent) {
|
||||
super.onTaskRemoved(rootIntent);
|
||||
restart();
|
||||
if( !zeroAccounts) {
|
||||
restart();
|
||||
}
|
||||
}
|
||||
|
||||
private void restart() {
|
||||
|
|
|
@ -107,6 +107,7 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
public static int totalAccount = 0;
|
||||
public static int eventsCount = 0;
|
||||
public static int liveNotifBadge = 0;
|
||||
public boolean zeroAccounts;
|
||||
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
@ -140,6 +141,7 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
if (intent == null || intent.getBooleanExtra("stop", false)) {
|
||||
stopSelf();
|
||||
}
|
||||
zeroAccounts = false;
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
channel = new NotificationChannel(CHANNEL_ID,
|
||||
"Live notifications",
|
||||
|
@ -158,13 +160,18 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
}
|
||||
}
|
||||
}
|
||||
if( totalAccount > 0) {
|
||||
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();
|
||||
|
||||
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);
|
||||
startForeground(1, notification);
|
||||
}else{
|
||||
zeroAccounts = true;
|
||||
stopSelf();
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
}
|
||||
return START_STICKY;
|
||||
}
|
||||
|
@ -186,7 +193,9 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
@Override
|
||||
public void onTaskRemoved(Intent rootIntent) {
|
||||
super.onTaskRemoved(rootIntent);
|
||||
restart();
|
||||
if( !zeroAccounts) {
|
||||
restart();
|
||||
}
|
||||
}
|
||||
|
||||
private void restart() {
|
||||
|
|
|
@ -808,7 +808,7 @@
|
|||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_gravity="end"
|
||||
android:contentDescription="@string/bookmark_add"
|
||||
android:contentDescription="@string/live_notif"
|
||||
android:padding="5dp"
|
||||
android:src="@drawable/ic_account_circle_acct" />
|
||||
</LinearLayout>
|
||||
|
|
Loading…
Reference in New Issue