Commit 0e0240c4 authored by topjohnwu's avatar topjohnwu

Better download UI

parent d1b290b9
...@@ -100,11 +100,23 @@ public class FlashActivity extends BaseActivity { ...@@ -100,11 +100,23 @@ public class FlashActivity extends BaseActivity {
logs = new ArrayList<>(); logs = new ArrayList<>();
CallbackList<String> console = new CallbackList<String>(new ArrayList<>()) { CallbackList<String> console = new CallbackList<String>(new ArrayList<>()) {
private void updateUI() {
flashLogs.setText(TextUtils.join("\n", this));
sv.postDelayed(() -> sv.fullScroll(ScrollView.FOCUS_DOWN), 10);
}
@Override @Override
public void onAddElement(String s) { public void onAddElement(String s) {
logs.add(s); logs.add(s);
flashLogs.setText(TextUtils.join("\n", this)); updateUI();
sv.postDelayed(() -> sv.fullScroll(ScrollView.FOCUS_DOWN), 10); }
@Override
public String set(int i, String s) {
String ret = super.set(i, s);
Data.mainHandler.post(this::updateUI);
return ret;
} }
}; };
......
...@@ -101,14 +101,15 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> { ...@@ -101,14 +101,15 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
private ProgressStream(HttpURLConnection conn) throws IOException { private ProgressStream(HttpURLConnection conn) throws IOException {
super(conn.getInputStream()); super(conn.getInputStream());
total = conn.getContentLength(); total = conn.getContentLength();
console.add("... 0%");
} }
private void update(int step) { private void update(int step) {
progress += step; progress += step;
int curr = (int) (10 * (double) progress / total); int curr = (int) (100 * (double) progress / total);
if (prev != curr) { if (prev != curr) {
prev = curr; prev = curr;
console.add("... " + prev * 10 + "%"); console.set(console.size() - 1, "... " + prev + "%");
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment