0
0
mirror of https://github.com/TrianguloY/UrlChecker.git synced 2024-09-19 20:02:16 +02:00

improved ProgressDialog

This commit is contained in:
TrianguloY 2024-01-29 23:12:56 +01:00
parent f964bb7579
commit 146892e948
2 changed files with 24 additions and 7 deletions

View File

@ -46,11 +46,12 @@ public class Hosts {
.setTitle(R.string.mHosts_buildTitle)
.setMessage(R.string.mHosts_buildDesc)
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
var progress = new ProgressDialog(cntx, cntx.getString(R.string.mHosts_buildProgress));
progress.setMessage(cntx.getString(R.string.mHosts_buildInit));
new Thread(() -> _build(progress, onFinished)).start();
});
.setPositiveButton(android.R.string.ok, (dialog, which) ->
ProgressDialog.run(cntx, R.string.mHosts_buildProgress, progress -> {
progress.setMessage(cntx.getString(R.string.mHosts_buildInit));
_build(progress, onFinished);
})
);
if (showEditor) builder
.setNeutralButton(R.string.json_edit, (dialog, which) -> data.showEditor());

View File

@ -2,16 +2,31 @@ package com.trianguloy.urlchecker.utilities.wrappers;
import android.app.Activity;
import com.trianguloy.urlchecker.utilities.methods.JavaUtils;
/**
* A wrapper around {@link android.app.ProgressDialog} with more useful functions
*/
public class ProgressDialog extends android.app.ProgressDialog {
/**
* Usage:
* <pre>
* ProgressDialog.run(cntx, R.string.text, progress -> {
* // do things
* });
* </pre>
*/
public static void run(Activity context, int title, JavaUtils.Consumer<ProgressDialog> consumer) {
new ProgressDialog(context, title, consumer);
}
private final Activity cntx;
/**
* Constructs and shows the dialog
*/
public ProgressDialog(Activity context, String title) {
private ProgressDialog(Activity context, int title, JavaUtils.Consumer<ProgressDialog> consumer) {
super(context);
cntx = context;
setTitle(title); // can't be changed later
@ -20,8 +35,9 @@ public class ProgressDialog extends android.app.ProgressDialog {
setCancelable(false); // disable cancelable by default
setCanceledOnTouchOutside(false);
// show immediately
// show & start
show();
new Thread(() -> consumer.accept(this)).start();
}
/**