Dismiss notification on error
This commit is contained in:
parent
1947860d61
commit
971cd73fb3
@ -46,9 +46,6 @@ abstract class NotificationService : Service() {
|
|||||||
) : Int {
|
) : Int {
|
||||||
val currentNotification = remove(id)?.run(editBody)
|
val currentNotification = remove(id)?.run(editBody)
|
||||||
|
|
||||||
updateForeground()
|
|
||||||
|
|
||||||
cancel(id)
|
|
||||||
var newId = -1
|
var newId = -1
|
||||||
currentNotification?.let {
|
currentNotification?.let {
|
||||||
newId = nextInt(Int.MAX_VALUE)
|
newId = nextInt(Int.MAX_VALUE)
|
||||||
@ -56,7 +53,6 @@ abstract class NotificationService : Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!hasNotifications) {
|
if (!hasNotifications) {
|
||||||
stopForeground(true)
|
|
||||||
stopSelf()
|
stopSelf()
|
||||||
}
|
}
|
||||||
return newId
|
return newId
|
||||||
@ -72,12 +68,16 @@ abstract class NotificationService : Service() {
|
|||||||
manager.cancel(id)
|
manager.cancel(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun remove(id: Int) = notifications.remove(id)
|
protected fun remove(id: Int) = notifications.remove(id).also {
|
||||||
.also { updateForeground() }
|
cancel(id)
|
||||||
|
updateForeground()
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateForeground() {
|
private fun updateForeground() {
|
||||||
if (notifications.isNotEmpty())
|
if (hasNotifications)
|
||||||
startForeground(notifications.keys.first(), notifications.values.first().build())
|
startForeground(notifications.keys.first(), notifications.values.first().build())
|
||||||
|
else
|
||||||
|
stopForeground(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// --
|
// --
|
||||||
|
@ -49,6 +49,7 @@ abstract class RemoteFileService : NotificationService() {
|
|||||||
.onErrorResumeNext(download(subject))
|
.onErrorResumeNext(download(subject))
|
||||||
.doOnSubscribe { update(subject.hashCode()) { it.setContentTitle(subject.title) } }
|
.doOnSubscribe { update(subject.hashCode()) { it.setContentTitle(subject.title) } }
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.doOnError { remove(subject.hashCode()) }
|
||||||
.doOnSuccess {
|
.doOnSuccess {
|
||||||
val id = finish(it, subject)
|
val id = finish(it, subject)
|
||||||
runCatching { onFinished(it, subject, id) }.onFailure { Timber.e(it) }
|
runCatching { onFinished(it, subject, id) }.onFailure { Timber.e(it) }
|
||||||
|
@ -7,6 +7,10 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
|
import androidx.core.app.NotificationCompat;
|
||||||
|
import androidx.core.app.NotificationManagerCompat;
|
||||||
|
import androidx.core.app.TaskStackBuilder;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.App;
|
import com.topjohnwu.magisk.App;
|
||||||
import com.topjohnwu.magisk.ClassMap;
|
import com.topjohnwu.magisk.ClassMap;
|
||||||
import com.topjohnwu.magisk.Const;
|
import com.topjohnwu.magisk.Const;
|
||||||
@ -16,17 +20,12 @@ import com.topjohnwu.magisk.model.receiver.GeneralReceiver;
|
|||||||
import com.topjohnwu.magisk.ui.SplashActivity;
|
import com.topjohnwu.magisk.ui.SplashActivity;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
import androidx.core.app.NotificationCompat;
|
|
||||||
import androidx.core.app.NotificationManagerCompat;
|
|
||||||
import androidx.core.app.TaskStackBuilder;
|
|
||||||
|
|
||||||
public class Notifications {
|
public class Notifications {
|
||||||
|
|
||||||
public static NotificationManagerCompat mgr = NotificationManagerCompat.from(App.self);
|
public static NotificationManagerCompat mgr = NotificationManagerCompat.from(App.self);
|
||||||
|
|
||||||
public static void setup(Context c) {
|
public static void setup(Context c) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
NotificationManager mgr = c.getSystemService(NotificationManager.class);
|
|
||||||
mgr.deleteNotificationChannel("magisk_notification");
|
mgr.deleteNotificationChannel("magisk_notification");
|
||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(Const.ID.UPDATE_NOTIFICATION_CHANNEL,
|
new NotificationChannel(Const.ID.UPDATE_NOTIFICATION_CHANNEL,
|
||||||
|
Loading…
Reference in New Issue
Block a user