Show progress while downloading modules

This commit is contained in:
topjohnwu 2017-10-01 02:38:25 +08:00
parent ab7fd9799d
commit 64da9281a4
11 changed files with 60 additions and 20 deletions

View File

@ -6,6 +6,7 @@ import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.widget.Toast;
import com.topjohnwu.magisk.FlashActivity;
@ -21,16 +22,21 @@ import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
public class ProcessRepoZip extends ParallelTask<Void, Void, Boolean> {
public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
private ProgressDialog progressDialog;
private boolean mInstall;
private String mLink;
private File mFile;
private int progress = 0, total;
private static final int UPDATE_DL_PROG = 0;
private static final int SHOW_PROCESSING = 1;
public ProcessRepoZip(Activity context, String link, String filename, boolean install) {
super(context);
@ -43,15 +49,23 @@ public class ProcessRepoZip extends ParallelTask<Void, Void, Boolean> {
@Override
protected void onPreExecute() {
Activity activity = getActivity();
progressDialog = ProgressDialog.show(activity,
activity.getString(R.string.zip_download_title),
activity.getString(R.string.zip_download_msg));
progressDialog = ProgressDialog.show(activity, activity.getString(R.string.zip_download_title), activity.getString(R.string.zip_download_msg, 0));
}
@Override
protected void onProgressUpdate(Void... values) {
progressDialog.setTitle(R.string.zip_process_title);
progressDialog.setMessage(getActivity().getString(R.string.zip_process_msg));
protected void onProgressUpdate(Object... values) {
int mode = (int) values[0];
switch (mode) {
case UPDATE_DL_PROG:
int add = (int) values[1];
progress += add;
progressDialog.setMessage(getActivity().getString(R.string.zip_download_msg, 100 * progress / total));
break;
case SHOW_PROCESSING:
progressDialog.setTitle(R.string.zip_process_title);
progressDialog.setMessage(getActivity().getString(R.string.zip_process_msg));
break;
}
}
@Override
@ -63,7 +77,8 @@ public class ProcessRepoZip extends ParallelTask<Void, Void, Boolean> {
// Request zip from Internet
HttpURLConnection conn = WebService.request(mLink, null);
if (conn == null) return false;
InputStream in = new BufferedInputStream(conn.getInputStream());
total = conn.getContentLength();
InputStream in = new ProgressUpdateInputStream(conn.getInputStream());
// Temp files
File temp1 = new File(activity.getCacheDir(), "1.zip");
@ -74,7 +89,7 @@ public class ProcessRepoZip extends ParallelTask<Void, Void, Boolean> {
ZipUtils.removeTopFolder(in, temp1);
conn.disconnect();
publishProgress();
publishProgress(SHOW_PROCESSING);
// Then sign the zip for the first time, temp1 -> temp2
ZipUtils.signZip(activity, temp1, temp2, false);
@ -128,8 +143,33 @@ public class ProcessRepoZip extends ParallelTask<Void, Void, Boolean> {
}
@Override
public ParallelTask<Void, Void, Boolean> exec(Void... voids) {
public ParallelTask<Void, Object, Boolean> exec(Void... voids) {
Utils.runWithPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE, () -> super.exec(voids));
return this;
}
private class ProgressUpdateInputStream extends BufferedInputStream {
ProgressUpdateInputStream(@NonNull InputStream in) {
super(in);
}
@Override
public synchronized int read() throws IOException {
publishProgress(UPDATE_DL_PROG, 1);
return super.read();
}
@Override
public int read(@NonNull byte[] b) throws IOException {
return read(b, 0, b.length);
}
@Override
public synchronized int read(@NonNull byte[] b, int off, int len) throws IOException {
int read = super.read(b, off, len);
publishProgress(UPDATE_DL_PROG, read);
return read;
}
}
}

View File

@ -99,7 +99,7 @@
<string name="process_error">Prozessfehler</string>
<string name="internal_storage">Die zip-Datei ist gespeichert unter:\n[Interner Speicher]%1$s</string>
<string name="zip_download_title">Herunterladen</string>
<string name="zip_download_msg">Lade Zip-Datei herunter…</string>
<string name="zip_download_msg">Lade Zip-Datei herunter (%1$d%%) </string>
<string name="zip_process_title">Verarbeite</string>
<string name="zip_process_msg">Verarbeite Zip-Datei…</string>
<string name="manual_boot_image">Bitte Boot-Image auswählen!</string>

View File

@ -99,7 +99,7 @@
<string name="process_error">Error de proceso</string>
<string name="internal_storage">El zip es almacenado en:\n[Internal Storage]%1$s</string>
<string name="zip_download_title">Descargando</string>
<string name="zip_download_msg">Descargando el archivo zip …</string>
<string name="zip_download_msg">Descargando el archivo zip (%1$d%%) </string>
<string name="zip_process_title">Procesando</string>
<string name="manual_boot_image">¡Selecciona manualmente una imagen boot!</string>
<string name="manager_update_title">Nueva actualización de Magisk Manager disponible!</string>

View File

@ -92,7 +92,7 @@
<string name="zip_process_title">Exécution</string>
<string name="manual_boot_image">Veuillez sélectionner l\'image boot manuellement !</string>
<string name="zip_download_title">Téléchargement</string>
<string name="zip_download_msg">Téléchargement du fichier zip...</string>
<string name="zip_download_msg">Téléchargement du fichier zip (%1$d%%) ...</string>
<string name="manager_update_title">Nouvelle mise à jour Magisk Manager disponible !</string>
<string name="manager_download_install">Appuyez pour télécharger et installer</string>
<string name="magisk_updates">Mises à jour Magisk</string>

View File

@ -98,7 +98,7 @@
<string name="process_error">Verwerkingsfout</string>
<string name="internal_storage">De zip is opgeslagen in:\n[Interne opslag]%1$s</string>
<string name="zip_download_title">Downloaden</string>
<string name="zip_download_msg">Zip-bestand downloaden…</string>
<string name="zip_download_msg">Zip-bestand downloaden (%1$d%%) </string>
<string name="zip_process_title">Verwerken</string>
<string name="zip_process_msg">Zip-bestand verwerken…</string>
<string name="manual_boot_image">Gelieve handmatig een boot image te selecteren!</string>

View File

@ -101,7 +101,7 @@
<string name="process_error">Błąd procesu</string>
<string name="internal_storage">Zip jest przechowywany w:\n[Pamięć Wewnętrzna]%1$s</string>
<string name="zip_download_title">Pobieranie</string>
<string name="zip_download_msg">Pobieranie pliku zip …</string>
<string name="zip_download_msg">Pobieranie pliku zip (%1$d%%) </string>
<string name="zip_process_title">Przetwarzanie</string>
<string name="zip_process_msg">Przetwarzanie pliku zip …</string>
<string name="manual_boot_image">Proszę ręcznie wybrać boot image!</string>

View File

@ -98,7 +98,7 @@
<string name="process_error">Ошибка обработки</string>
<string name="internal_storage">Архив расположен:\n[Внутреннее Хранилище]%1$s</string>
<string name="zip_download_title">Загрузка</string>
<string name="zip_download_msg">Загрузка архива…</string>
<string name="zip_download_msg">Загрузка архива (%1$d%%) </string>
<string name="zip_process_title">Обработка</string>
<string name="zip_process_msg">Обработка архива…</string>
<string name="manual_boot_image">Пожалуйста, выберите вручную boot-образ!</string>

View File

@ -97,7 +97,7 @@
<string name="process_error">İşlem hatası</string>
<string name="internal_storage">Zip şuraya depolandı:\n[Dahili Hafıza]%1$s</string>
<string name="zip_download_title">İndiriliyor</string>
<string name="zip_download_msg">Zip dosyası indiriliyor …</string>
<string name="zip_download_msg">Zip dosyası indiriliyor (%1$d%%) </string>
<string name="zip_process_title">İşleniyor</string>
<string name="zip_process_msg">Zip dosyası işleniyor …</string>
<string name="manual_boot_image">Lütfen elle bir boot imajı seçin!</string>

View File

@ -98,7 +98,7 @@
<string name="repo_cache_cleared">Кеш репозиторію очищено</string>
<string name="safetyNet_hide_notice">Ця програма використовує SafetyNet.\nВже опрацьовано MagiskHide за замовчуванням</string>
<string name="zip_download_title">Завантаження</string>
<string name="zip_download_msg">Завантаження zip файлу …</string>
<string name="zip_download_msg">Завантаження zip файлу (%1$d%%) </string>
<string name="process_error">Помилка опрацювання</string>
<string name="internal_storage">Архів розташований:\n[Внутрішнє Сховище]%1$s</string>
<string name="zip_process_title">Опрацювання</string>

View File

@ -206,7 +206,7 @@
<string name="settings_update">更新設定</string>
<string name="settings_boot_format_title">已補丁 Boot 映像輸出格式</string>
<string name="zip_download_title">正在下載</string>
<string name="zip_download_msg">正在下載 Zip 文件 …</string>
<string name="zip_download_msg">正在下載 Zip 文件 (%1$d%%) </string>
<string name="settings_boot_format_summary">選擇已補丁 Boot 映像文件輸出格式\n若要透過 fastboot/download 模式刷入,請選擇 .img 格式;若要透過 ODIN 刷入,則選擇 .img.tar\n</string>
<string name="complete_uninstall">完全解除安裝</string>
<string name="restore_stock_boot">還原原廠 boot 映像</string>

View File

@ -101,7 +101,7 @@
<string name="process_error">Process error</string>
<string name="internal_storage">The zip is stored in:\n[Internal Storage]%1$s</string>
<string name="zip_download_title">Downloading</string>
<string name="zip_download_msg">Downloading zip file …</string>
<string name="zip_download_msg">Downloading zip file (%1$d%%) </string>
<string name="zip_process_title">Processing</string>
<string name="zip_process_msg">Processing zip file …</string>
<string name="manual_boot_image">Please manually select a boot image!</string>