Better download UI

This commit is contained in:
topjohnwu 2018-08-03 22:48:44 +08:00
parent d1b290b91a
commit 0e0240c4ab
2 changed files with 17 additions and 4 deletions

View File

@ -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;
} }
}; };

View File

@ -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 + "%");
} }
} }