Better progress notifications

This commit is contained in:
topjohnwu
2018-12-02 15:15:42 -05:00
parent fc314cc248
commit ee2c801fe0
34 changed files with 126 additions and 107 deletions

View File

@@ -62,7 +62,8 @@ public class Const {
public static final int APK_UPDATE_NOTIFICATION_ID = 5;
public static final int DTBO_NOTIFICATION_ID = 7;
public static final int DOWNLOAD_PROGRESS_ID = 8;
public static final String NOTIFICATION_CHANNEL = "magisk_notification";
public static final String UPDATE_NOTIFICATION_CHANNEL = "update";
public static final String PROGRESS_NOTIFICATION_CHANNEL = "progress";
}
public static class Url {

View File

@@ -1,10 +1,7 @@
package com.topjohnwu.magisk;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
@@ -14,6 +11,7 @@ import com.topjohnwu.magisk.components.BaseActivity;
import com.topjohnwu.magisk.receivers.ShortcutReceiver;
import com.topjohnwu.magisk.utils.Download;
import com.topjohnwu.magisk.utils.LocaleManager;
import com.topjohnwu.magisk.utils.Notifications;
import com.topjohnwu.magisk.utils.RootUtils;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.superuser.Shell;
@@ -51,11 +49,7 @@ public class SplashActivity extends BaseActivity {
LocaleManager.loadAvailableLocales();
// Create notification channel on Android O
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(Const.ID.NOTIFICATION_CHANNEL,
getString(R.string.magisk_updates), NotificationManager.IMPORTANCE_DEFAULT);
getSystemService(NotificationManager.class).createNotificationChannel(channel);
}
Notifications.setup(this);
// Setup shortcuts
sendBroadcast(new Intent(this, Data.classMap.get(ShortcutReceiver.class)));

View File

@@ -126,8 +126,8 @@ public class PatchAPK {
public static void hideManager(Activity activity) {
ProgressDialog dialog = ProgressDialog.show(activity,
activity.getString(R.string.hide_manager_toast),
activity.getString(R.string.hide_manager_toast2));
activity.getString(R.string.hide_manager_title),
activity.getString(R.string.hide_manager_msg));
AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> {
boolean b = patchAndHide();
Data.mainHandler.post(() -> {

View File

@@ -33,13 +33,14 @@ public class NotificationProgress implements DownloadProgressListener {
long cur = System.currentTimeMillis();
if (cur - prevTime >= 1000) {
prevTime = cur;
builder.setProgress((int) totalBytes, (int) bytesDownloaded, false);
builder.setContentText(bytesDownloaded * 100 / totalBytes + "%");
int progress = (int) (bytesDownloaded * 100 / totalBytes);
builder.setProgress(100, progress, false);
builder.setContentText(progress + "%");
update();
}
}
public NotificationCompat.Builder getBuilder() {
public NotificationCompat.Builder getNotification() {
return builder;
}
@@ -48,8 +49,9 @@ public class NotificationProgress implements DownloadProgressListener {
}
public void dlDone() {
builder.setProgress(0, 0, false);
builder.setContentText(Data.MM().getString(R.string.download_complete));
builder.setProgress(0, 0, false)
.setContentText(Data.MM().getString(R.string.download_complete))
.setSmallIcon(R.drawable.ic_check_circle);
update();
}

View File

@@ -71,9 +71,9 @@ public class DlInstallManager {
File patched = apk;
MagiskManager mm = Data.MM();
if (!mm.getPackageName().equals(Const.ORIG_PKG_NAME)) {
progress.getBuilder()
progress.getNotification()
.setProgress(0, 0, true)
.setContentTitle(mm.getString(R.string.hide_manager_toast))
.setContentTitle(mm.getString(R.string.hide_manager_title))
.setContentText("");
progress.update();
patched = new File(apk.getParent(), "patched.apk");

View File

@@ -1,7 +1,11 @@
package com.topjohnwu.magisk.utils;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import com.topjohnwu.magisk.Const;
import com.topjohnwu.magisk.Data;
@@ -17,6 +21,20 @@ import androidx.core.app.TaskStackBuilder;
public class Notifications {
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,
c.getString(R.string.update_channel), NotificationManager.IMPORTANCE_DEFAULT);
mgr.createNotificationChannel(channel);
channel = new NotificationChannel(Const.ID.PROGRESS_NOTIFICATION_CHANNEL,
c.getString(R.string.progress_channel), NotificationManager.IMPORTANCE_LOW);
mgr.createNotificationChannel(channel);
}
}
public static void magiskUpdate() {
MagiskManager mm = Data.MM();
@@ -28,7 +46,7 @@ public class Notifications {
PendingIntent pendingIntent = stackBuilder.getPendingIntent(Const.ID.MAGISK_UPDATE_NOTIFICATION_ID,
PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, Const.ID.NOTIFICATION_CHANNEL);
NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, Const.ID.UPDATE_NOTIFICATION_CHANNEL);
builder.setSmallIcon(R.drawable.ic_magisk_outline)
.setContentTitle(mm.getString(R.string.magisk_update_title))
.setContentText(mm.getString(R.string.magisk_update_available, Data.remoteMagiskVersionString))
@@ -51,7 +69,7 @@ public class Notifications {
PendingIntent pendingIntent = PendingIntent.getBroadcast(mm,
Const.ID.APK_UPDATE_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, Const.ID.NOTIFICATION_CHANNEL);
NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, Const.ID.UPDATE_NOTIFICATION_CHANNEL);
builder.setSmallIcon(R.drawable.ic_magisk_outline)
.setContentTitle(mm.getString(R.string.manager_update_title))
.setContentText(mm.getString(R.string.manager_download_install))
@@ -70,7 +88,7 @@ public class Notifications {
PendingIntent pendingIntent = PendingIntent.getBroadcast(mm,
Const.ID.DTBO_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, Const.ID.NOTIFICATION_CHANNEL);
NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, Const.ID.UPDATE_NOTIFICATION_CHANNEL);
builder.setSmallIcon(R.drawable.ic_magisk_outline)
.setContentTitle(mm.getString(R.string.dtbo_patched_title))
.setContentText(mm.getString(R.string.dtbo_patched_reboot))
@@ -83,8 +101,9 @@ public class Notifications {
public static NotificationCompat.Builder progress(String title) {
MagiskManager mm = Data.MM();
NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, Const.ID.NOTIFICATION_CHANNEL);
builder.setSmallIcon(R.drawable.ic_magisk_outline)
NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, Const.ID.PROGRESS_NOTIFICATION_CHANNEL);
builder.setPriority(NotificationCompat.PRIORITY_LOW)
.setSmallIcon(android.R.drawable.stat_sys_download)
.setContentTitle(title)
.setProgress(0, 0, true);
return builder;