use of com.afollestad.materialdialogs.MaterialDialog.SingleButtonCallback in project XposedInstaller by rovo89.
the class DownloadsUtil method showDownloadDialog.
private static void showDownloadDialog(final Builder b, final long id) {
final Context context = b.mContext;
final DownloadDialog dialog = new DownloadDialog(new MaterialDialog.Builder(context).title(b.mTitle).content(R.string.download_view_waiting).progress(false, 0, true).progressNumberFormat(context.getString(R.string.download_progress)).canceledOnTouchOutside(false).negativeText(R.string.download_view_cancel).onNegative(new SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
dialog.cancel();
}
}).cancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
removeById(context, id);
}
}));
dialog.setShowProcess(false);
dialog.show();
new Thread("DownloadDialog") {
@Override
public void run() {
while (true) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
return;
}
final DownloadInfo info = getById(context, id);
if (info == null) {
dialog.cancel();
return;
} else if (info.status == DownloadManager.STATUS_FAILED) {
dialog.cancel();
XposedApp.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(context, context.getString(R.string.download_view_failed, info.reason), Toast.LENGTH_LONG).show();
}
});
return;
} else if (info.status == DownloadManager.STATUS_SUCCESSFUL) {
dialog.dismiss();
// Hack to reset stat information.
new File(info.localFilename).setExecutable(false);
if (b.mCallback != null) {
b.mCallback.onDownloadFinished(context, info);
}
return;
}
XposedApp.runOnUiThread(new Runnable() {
@Override
public void run() {
if (info.totalSize <= 0 || info.status != DownloadManager.STATUS_RUNNING) {
dialog.setContent(R.string.download_view_waiting);
dialog.setShowProcess(false);
} else {
dialog.setContent(R.string.download_running);
dialog.setProgress(info.bytesDownloaded / 1024);
dialog.setMaxProgress(info.totalSize / 1024);
dialog.setShowProcess(true);
}
}
});
}
}
}.start();
}
Aggregations