use of de.mkrtchyan.utils.DownloadDialog in project Rashr by DsLNeXuS.
the class FlashFragment method FlashSupportedKernel.
/**
* Flash Kernels provided by Rashr like stock kernels for Nexus Devices
*
* @param card CardView that contains the Kernel type should be flashed for example: stock,
* bricked...
*/
public void FlashSupportedKernel(Card card) {
final File path;
final ArrayList<String> Versions;
ArrayAdapter<String> VersionsAdapter = new ArrayAdapter<>(mContext, R.layout.custom_list_item);
/**
* If there files be needed to flash download it and listing device specified recovery
* file for example stock-boot-grouper-4.4.img (read out from kernel_sums)
*/
String SYSTEM = card.getData().toString();
if (SYSTEM.equals(Device.KER_SYS_STOCK)) {
Versions = RashrApp.DEVICE.getStockKernelVersions();
path = Const.PathToStockKernel;
for (String i : Versions) {
try {
String version = i.split("-")[3].replace(RashrApp.DEVICE.getRecoveryExt(), "");
String deviceName = i.split("-")[2];
/** Readable name for user */
VersionsAdapter.add("Stock Kernel " + version + " (" + deviceName + ")");
} catch (ArrayIndexOutOfBoundsException e) {
/** Add the normal filename if something went wrong */
VersionsAdapter.add(i);
}
}
} else {
/** Only stock kernel is supported at the moment, why are you here?
* Something went wrong better return :)
*/
return;
}
final AlertDialog.Builder KernelDialog = new AlertDialog.Builder(mContext);
KernelDialog.setTitle(SYSTEM);
KernelDialog.setAdapter(VersionsAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final File kernel = new File(path, Versions.get(which));
if (!kernel.exists()) {
try {
URL url = new URL(Const.KERNEL_URL + "/" + kernel.getName());
Downloader downloader = new Downloader(url, kernel);
final DownloadDialog KernelDownloader = new DownloadDialog(mContext, downloader);
KernelDownloader.setOnDownloadListener(new DownloadDialog.OnDownloadListener() {
@Override
public void onSuccess(File file) {
flashKernel(file);
}
@Override
public void onFail(Exception e) {
KernelDownloader.retry();
}
});
KernelDownloader.setAskBeforeDownload(true);
downloader.setChecksumFile(Const.KernelCollectionFile);
KernelDownloader.ask();
} catch (MalformedURLException ignored) {
}
} else {
flashKernel(kernel);
}
}
});
KernelDialog.show();
//}
}
use of de.mkrtchyan.utils.DownloadDialog in project Rashr by DsLNeXuS.
the class RecoverySystemFragment method flashSupportedRecovery.
/**
* Flash a Recovery provided by Rashr, like ClockworkMod, TWRP, PhilZ, CM, Stock
*
* @param system String containing the Recovery-System type for example:
* clockwork, cm, twrp, philz, stock....
* @param fileUrl File that will be flashed
*/
public void flashSupportedRecovery(final String system, String fileUrl) {
/*
* If there files be needed to flash download it and listing device specified
* recovery file for example recovery-clockwork-touch-6.0.3.1-grouper.img
* (read out from RECOVERY_SUMS)
*/
if (system.equals(Device.REC_SYS_XZDUAL)) {
AlertDialog.Builder alert = new AlertDialog.Builder(mContext);
alert.setTitle(R.string.warning);
if (App.Device.isXZDualInstalled()) {
alert.setMessage(R.string.xzdual_uninstall_alert);
alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
AlertDialog.Builder abuilder = new AlertDialog.Builder(mContext);
abuilder.setTitle(R.string.info);
abuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
try {
FlashUtil.uninstallXZDual();
abuilder.setMessage(R.string.xzdual_uninstall_successfull);
} catch (FailedExecuteCommand failedExecuteCommand) {
abuilder.setMessage(getString(R.string.xzdual_uninstall_failed) + "\n" + failedExecuteCommand.toString());
failedExecuteCommand.printStackTrace();
App.ERRORS.add(failedExecuteCommand.toString() + " Error uninstalling XZDual");
}
abuilder.show();
}
});
alert.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
return;
}
}
String fileName = "";
if (system.equals(Device.REC_SYS_CM) || system.equals(Device.REC_SYS_TWRP)) {
fileName = fileUrl.substring(fileUrl.lastIndexOf("/") + 1);
}
final File recovery = new File(mImagePath, fileName);
if (!recovery.exists()) {
try {
URL url = new URL(fileUrl);
final Downloader downloader = new Downloader(url, recovery);
final DownloadDialog RecoveryDownloader = new DownloadDialog(mContext, downloader);
if (system.equals(Device.REC_SYS_TWRP)) {
downloader.setReferrer(fileUrl);
}
RecoveryDownloader.setOnDownloadListener(new DownloadDialog.OnDownloadListener() {
@Override
public void onSuccess(File file) {
if (system.equals(Device.REC_SYS_XZDUAL)) {
FlashUtil flasher = new FlashUtil(getActivity(), file, FlashUtil.JOB_INSTALL_XZDUAL);
flasher.execute();
mActivity.onBackPressed();
} else {
flashRecovery(file);
}
}
@Override
public void onFail(Exception e) {
if (e != null) {
App.ERRORS.add(e.toString());
Snackbar.make(mView.getView(), e.getMessage(), Snackbar.LENGTH_SHORT).show();
}
RecoveryDownloader.retry();
}
});
RecoveryDownloader.setAskBeforeDownload(true);
downloader.setChecksumFile(App.RecoveryCollectionFile);
RecoveryDownloader.ask();
} catch (MalformedURLException ignored) {
}
} else {
flashRecovery(recovery);
}
}
Aggregations