* Created by k3b on 09.07.2017.
*/
abstract public class AsyncTaskWithProgressDialog extends AsyncTask
- implements Closeable{
+ implements Closeable, IProgessListener {
private final int idResourceTitle;
private WeakReference
+ * called every time when command makes some little progress in non gui thread.
+ * return true to continue
+ */
+ @Override
+ public boolean onProgress(int itemCount, int total, String message) {
+ return publishProgress(itemCount, total, message);
+ }
+
+ public boolean publishProgress(int itemCount, int total, Object message) {
+ final boolean cancelled = this.isCancelled();
+ if (cancelled) {
+ if (LibZipGlobal.debugEnabled) {
+ Log.d(LibZipGlobal.LOG_TAG, this.getClass().getSimpleName() + " cancel pressed ");
+ }
+ }
StringBuilder msg = new StringBuilder();
if (itemCount > 0) {
msg.append("(").append(itemCount);
@@ -90,23 +121,28 @@ protected void publishProgress(int itemCount, int total, Object message) {
msg.append(message);
}
publishProgress(msg.toString());
+ return !cancelled;
}
+
protected Activity getActivity() {
if (activity == null) return null;
return activity.get();
}
- public void setActivity(Activity activity) {
+ public AsyncTaskWithProgressDialog setActivity(Activity activity) {
boolean isActive = isNotFinishedYet();
- if (isActive && (activity == getActivity())) {
+ Activity oldActivity = getActivity();
+ if (isActive && (activity == oldActivity)) {
// no change
- return;
+ return this;
}
+
this.activity = (isActive && (activity != null)) ? new WeakReference<>(activity) : null;
if ((dlg != null) && dlg.isShowing()) {
dlg.dismiss();
+ setDialog(activity, null);
}
dlg = null;
@@ -114,6 +150,7 @@ public void setActivity(Activity activity) {
dlg = new ProgressDialog(activity);
dlg.setTitle(idResourceTitle);
}
+ return this;
}
public boolean isNotFinishedYet() {
diff --git a/app/src/main/java/de/k3b/android/widget/FilePermissionActivity.java b/app/src/main/java/de/k3b/android/widget/FilePermissionActivity.java
index fac14f99..e7859757 100644
--- a/app/src/main/java/de/k3b/android/widget/FilePermissionActivity.java
+++ b/app/src/main/java/de/k3b/android/widget/FilePermissionActivity.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020 by k3b.
+ * Copyright (c) 2020-2021 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
@@ -46,7 +46,7 @@
* * write to external-storage and
* * write to sdcard/usbstick,....
*/
-public abstract class FilePermissionActivity extends ActivityWithAutoCloseDialogs {
+public abstract class FilePermissionActivity extends ActivityWithAsyncTaskDialog {
private static final int REQUEST_ROOT_DIR = 2001;
public static final String TAG = "k3b.FilePermAct";
private static IOnDirectoryPermissionGrantedHandler currentPermissionGrantedHandler = null;
diff --git a/app/src/main/java/de/k3b/android/widget/ITaskRunner.java b/app/src/main/java/de/k3b/android/widget/ITaskRunner.java
new file mode 100644
index 00000000..c8eb020f
--- /dev/null
+++ b/app/src/main/java/de/k3b/android/widget/ITaskRunner.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2021 by k3b.
+ *
+ * This file is part of AndroFotoFinder / #APhotoManager.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see