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