Update net module

This commit is contained in:
topjohnwu
2019-01-01 18:45:48 +08:00
parent 1df65940b9
commit 7bd52d0245
9 changed files with 81 additions and 100 deletions

View File

@ -71,12 +71,12 @@ class InstallMethodDialog extends AlertDialog.Builder {
Networking.get(Data.magiskLink)
.setDownloadProgressListener(progress)
.setErrorHandler(((conn, e) -> progress.dlFail()))
.getAsFile(f -> {
.getAsFile(zip, f -> {
progress.dlDone();
SnackbarMaker.make(a,
a.getString(R.string.internal_storage, "/Download/" + filename),
Snackbar.LENGTH_LONG).show();
}, zip);
});
});
}

View File

@ -46,14 +46,14 @@ public class UninstallDialog extends CustomAlertDialog {
Networking.get(Data.uninstallerLink)
.setDownloadProgressListener(progress)
.setErrorHandler(((conn, e) -> progress.dlFail()))
.getAsFile(f -> {
.getAsFile(zip, f -> {
progress.dismiss();
Intent intent = new Intent(activity, ClassMap.get(FlashActivity.class))
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.setData(Uri.fromFile(f))
.putExtra(Const.Key.FLASH_ACTION, Const.Value.UNINSTALL);
activity.startActivity(intent);
}, zip);
});
});
}
}

View File

@ -12,12 +12,8 @@ import com.topjohnwu.magisk.components.ProgressNotification;
import com.topjohnwu.net.Networking;
import com.topjohnwu.net.ResponseListener;
import com.topjohnwu.superuser.ShellUtils;
import com.topjohnwu.utils.JarMap;
import com.topjohnwu.utils.SignAPK;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import dalvik.system.DexClassLoader;
@ -36,37 +32,25 @@ public class DownloadApp {
private static void dlInstall(String name, ManagerDownloadListener listener) {
File apk = new File(App.self.getCacheDir(), "manager.apk");
ProgressNotification progress = new ProgressNotification(name);
listener.setProgressNotification(progress);
listener.progress = progress;
Networking.get(Data.managerLink)
.setExecutor(AsyncTask.THREAD_POOL_EXECUTOR)
.setDownloadProgressListener(progress)
.setErrorHandler((conn, e) -> progress.dlFail())
.getAsFile(listener, apk);
.getAsFile(apk, listener);
}
abstract static class ManagerDownloadListener implements ResponseListener<File> {
private abstract static class ManagerDownloadListener implements ResponseListener<File> {
ProgressNotification progress;
}
private ProgressNotification progress;
private void setProgressNotification(ProgressNotification progress) {
this.progress = progress;
}
public abstract void onDownloadComplete(File apk, ProgressNotification progress);
private static class PatchPackageName extends ManagerDownloadListener {
@Override
public void onResponse(File apk) {
onDownloadComplete(apk, progress);
}
}
static class PatchPackageName extends ManagerDownloadListener {
@Override
public void onDownloadComplete(File apk, ProgressNotification progress) {
File patched = apk;
App app = App.self;
if (!App.self.getPackageName().equals(BuildConfig.APPLICATION_ID)) {
if (!app.getPackageName().equals(BuildConfig.APPLICATION_ID)) {
progress.getNotificationBuilder()
.setProgress(0, 0, true)
.setContentTitle(app.getString(R.string.hide_manager_title))
@ -91,10 +75,10 @@ public class DownloadApp {
}
}
static class RestoreManager extends ManagerDownloadListener {
private static class RestoreManager extends ManagerDownloadListener {
@Override
public void onDownloadComplete(File apk, ProgressNotification progress) {
public void onResponse(File apk) {
App app = App.self;
progress.getNotificationBuilder()
.setProgress(0, 0, true)