Small refactor of download repo and FlashZip

This commit is contained in:
topjohnwu
2016-11-20 22:13:29 +08:00
parent 8c077a7373
commit f5bee7b691
7 changed files with 61 additions and 58 deletions
@@ -87,7 +87,7 @@ public class Utils {
return ret;
}
public static void downloadAndReceive(Context context, DownloadReceiver receiver, String link, String filename) {
public static void dlAndReceive(Context context, DownloadReceiver receiver, String link, String filename) {
File file = new File(Environment.getExternalStorageDirectory() + "/MagiskManager/" + filename);
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(context, R.string.permissionNotGranted, Toast.LENGTH_LONG).show();
@@ -103,6 +103,7 @@ public class Utils {
request.setDestinationUri(Uri.fromFile(file));
receiver.setDownloadID(downloadManager.enqueue(request));
receiver.setFilename(filename);
context.registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}
@@ -129,4 +130,10 @@ public class Utils {
return secret;
}
public static String getLegalFilename(CharSequence filename) {
return filename.toString().replace(" ", "_").replace("'", "").replace("\"", "")
.replace("$", "").replace("`", "").replace("(", "").replace(")", "")
.replace("#", "").replace("@", "").replace("*", "");
}
}