From 0e0240c4abf3c9ffbdd2220648f0cfb5cb46fc49 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Fri, 3 Aug 2018 22:48:44 +0800 Subject: [PATCH] Better download UI --- .../java/com/topjohnwu/magisk/FlashActivity.java | 16 ++++++++++++++-- .../topjohnwu/magisk/asyncs/InstallMagisk.java | 5 +++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/src/full/java/com/topjohnwu/magisk/FlashActivity.java b/app/src/full/java/com/topjohnwu/magisk/FlashActivity.java index ab45565e2..0e419330a 100644 --- a/app/src/full/java/com/topjohnwu/magisk/FlashActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/FlashActivity.java @@ -100,11 +100,23 @@ public class FlashActivity extends BaseActivity { logs = new ArrayList<>(); CallbackList console = new CallbackList(new ArrayList<>()) { + + private void updateUI() { + flashLogs.setText(TextUtils.join("\n", this)); + sv.postDelayed(() -> sv.fullScroll(ScrollView.FOCUS_DOWN), 10); + } + @Override public void onAddElement(String s) { logs.add(s); - flashLogs.setText(TextUtils.join("\n", this)); - sv.postDelayed(() -> sv.fullScroll(ScrollView.FOCUS_DOWN), 10); + updateUI(); + } + + @Override + public String set(int i, String s) { + String ret = super.set(i, s); + Data.mainHandler.post(this::updateUI); + return ret; } }; diff --git a/app/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java b/app/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java index 98002f83a..e295229c4 100644 --- a/app/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java +++ b/app/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java @@ -101,14 +101,15 @@ public class InstallMagisk extends ParallelTask { private ProgressStream(HttpURLConnection conn) throws IOException { super(conn.getInputStream()); total = conn.getContentLength(); + console.add("... 0%"); } private void update(int step) { progress += step; - int curr = (int) (10 * (double) progress / total); + int curr = (int) (100 * (double) progress / total); if (prev != curr) { prev = curr; - console.add("... " + prev * 10 + "%"); + console.set(console.size() - 1, "... " + prev + "%"); } }