From 857e6e8345d5f168f9ac1f22793f23f1672ff7a4 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 2 Dec 2018 05:33:53 -0500 Subject: [PATCH] Tweak notifications --- .../magisk/components/InstallMethodDialog.java | 2 +- .../magisk/components/NotificationProgress.java | 15 +++++++++++---- .../magisk/components/UninstallDialog.java | 2 +- .../topjohnwu/magisk/utils/DlInstallManager.java | 8 +++++--- app/src/full/res/values/strings.xml | 1 + 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/src/full/java/com/topjohnwu/magisk/components/InstallMethodDialog.java b/app/src/full/java/com/topjohnwu/magisk/components/InstallMethodDialog.java index fce04e216..4ab1b55de 100644 --- a/app/src/full/java/com/topjohnwu/magisk/components/InstallMethodDialog.java +++ b/app/src/full/java/com/topjohnwu/magisk/components/InstallMethodDialog.java @@ -76,7 +76,7 @@ class InstallMethodDialog extends AlertDialog.Builder { .startDownload(new DownloadListener() { @Override public void onDownloadComplete() { - progress.defaultDone(); + progress.dlDone(); SnackbarMaker.make(a, a.getString(R.string.internal_storage, "/Download/" + filename), Snackbar.LENGTH_LONG).show(); diff --git a/app/src/full/java/com/topjohnwu/magisk/components/NotificationProgress.java b/app/src/full/java/com/topjohnwu/magisk/components/NotificationProgress.java index 676820bd3..85ec147a5 100644 --- a/app/src/full/java/com/topjohnwu/magisk/components/NotificationProgress.java +++ b/app/src/full/java/com/topjohnwu/magisk/components/NotificationProgress.java @@ -5,6 +5,8 @@ import android.widget.Toast; import com.androidnetworking.interfaces.DownloadProgressListener; import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.Data; +import com.topjohnwu.magisk.MagiskManager; +import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.utils.Notifications; import com.topjohnwu.magisk.utils.Utils; @@ -18,11 +20,12 @@ public class NotificationProgress implements DownloadProgressListener { private long prevTime; public NotificationProgress(String title) { - mgr = NotificationManagerCompat.from(Data.MM()); + MagiskManager mm = Data.MM(); + mgr = NotificationManagerCompat.from(mm); builder = Notifications.progress(title); mgr.notify(Const.ID.DOWNLOAD_PROGRESS_ID, builder.build()); prevTime = System.currentTimeMillis(); - Utils.toast("Downloading " + title, Toast.LENGTH_SHORT); + Utils.toast(mm.getString(R.string.downloading_toast, title), Toast.LENGTH_SHORT); } @Override @@ -44,9 +47,13 @@ public class NotificationProgress implements DownloadProgressListener { mgr.notify(Const.ID.DOWNLOAD_PROGRESS_ID, builder.build()); } - public void defaultDone() { + public void dlDone() { builder.setProgress(0, 0, false); - builder.setContentText("Download done"); + builder.setContentText(Data.MM().getString(R.string.download_complete)); update(); } + + public void dismiss() { + mgr.cancel(Const.ID.DOWNLOAD_PROGRESS_ID); + } } diff --git a/app/src/full/java/com/topjohnwu/magisk/components/UninstallDialog.java b/app/src/full/java/com/topjohnwu/magisk/components/UninstallDialog.java index b5de56256..e249a3714 100644 --- a/app/src/full/java/com/topjohnwu/magisk/components/UninstallDialog.java +++ b/app/src/full/java/com/topjohnwu/magisk/components/UninstallDialog.java @@ -50,7 +50,7 @@ public class UninstallDialog extends CustomAlertDialog { .startDownload(new DownloadListener() { @Override public void onDownloadComplete() { - progress.defaultDone(); + progress.dismiss(); Intent intent = new Intent(activity, Data.classMap.get(FlashActivity.class)) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .setData(Uri.fromFile(zip)) diff --git a/app/src/full/java/com/topjohnwu/magisk/utils/DlInstallManager.java b/app/src/full/java/com/topjohnwu/magisk/utils/DlInstallManager.java index 6c19331ea..d16079c08 100644 --- a/app/src/full/java/com/topjohnwu/magisk/utils/DlInstallManager.java +++ b/app/src/full/java/com/topjohnwu/magisk/utils/DlInstallManager.java @@ -8,6 +8,7 @@ import com.androidnetworking.interfaces.DownloadListener; import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.Data; import com.topjohnwu.magisk.MagiskManager; +import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.asyncs.PatchAPK; import com.topjohnwu.magisk.components.NotificationProgress; import com.topjohnwu.superuser.ShellUtils; @@ -72,7 +73,8 @@ public class DlInstallManager { if (!mm.getPackageName().equals(Const.ORIG_PKG_NAME)) { progress.getBuilder() .setProgress(0, 0, true) - .setContentText("Patching APK"); + .setContentTitle(mm.getString(R.string.hide_manager_toast)) + .setContentText(""); progress.update(); patched = new File(apk.getParent(), "patched.apk"); try { @@ -83,7 +85,7 @@ public class DlInstallManager { return; } } - progress.defaultDone(); + progress.dismiss(); APKInstall.install(mm, patched); } } @@ -92,7 +94,7 @@ public class DlInstallManager { @Override public void onDownloadComplete(File apk, NotificationProgress progress) { - progress.defaultDone(); + progress.dismiss(); Data.exportPrefs(); if (ShellUtils.fastCmdResult("pm install " + apk)) RootUtils.rmAndLaunch(Data.MM().getPackageName(), Const.ORIG_PKG_NAME); diff --git a/app/src/full/res/values/strings.xml b/app/src/full/res/values/strings.xml index 8a38f741c..8ccde553a 100644 --- a/app/src/full/res/values/strings.xml +++ b/app/src/full/res/values/strings.xml @@ -122,6 +122,7 @@ Error downloading file Downloading %1$s This feature will not work without permission to write external storage. + Download complete General