-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #190: recreate apm-database now in nackground task with progress-di…
…alog
- Loading branch information
Showing
9 changed files
with
216 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
app/src/main/java/de/k3b/android/widget/ActivityWithAsyncTaskDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/> | ||
*/ | ||
|
||
package de.k3b.android.widget; | ||
|
||
import android.os.Bundle; | ||
|
||
import java.lang.ref.WeakReference; | ||
|
||
/** | ||
* {@link ActivityWithAsyncTaskDialog} is an Activity that shows a Progress-Dialog while | ||
* {@link AsyncTaskRunnerWithProgressDialog} runs a {@link ITaskRunner} in the Background | ||
*/ | ||
public abstract class ActivityWithAsyncTaskDialog extends ActivityWithAutoCloseDialogs { | ||
// only one current AsyncTaskDialog can exist at a time. | ||
private static WeakReference<AsyncTaskRunnerWithProgressDialog> runner = null; | ||
|
||
private static void setActivityIfActive(ActivityWithAsyncTaskDialog activity) { | ||
AsyncTaskRunnerWithProgressDialog task = (runner == null) ? null : runner.get(); | ||
if (task != null) { | ||
task.setActivity(activity); | ||
} | ||
} | ||
|
||
public static void setRunner(AsyncTaskRunnerWithProgressDialog runner) { | ||
ActivityWithAsyncTaskDialog.runner = (runner == null) ? null : new WeakReference<AsyncTaskRunnerWithProgressDialog>(runner); | ||
} | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
// After rotation the dialog will be destroyed. Make shure that a new progressDialog is created. | ||
setActivityIfActive(this); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
app/src/main/java/de/k3b/android/widget/AsyncTaskRunnerWithProgressDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/> | ||
*/ | ||
package de.k3b.android.widget; | ||
|
||
import android.content.Context; | ||
|
||
import de.k3b.io.IProgessListener; | ||
|
||
/** | ||
* {@link ActivityWithAsyncTaskDialog} is an Activity that shows a Progress-Dialog while | ||
* {@link AsyncTaskRunnerWithProgressDialog} runs a {@link ITaskRunner} in the Background | ||
*/ | ||
|
||
public class AsyncTaskRunnerWithProgressDialog extends AsyncTaskWithProgressDialog<ITaskRunner> implements IProgessListener { | ||
private final Context context; | ||
|
||
public AsyncTaskRunnerWithProgressDialog(ActivityWithAsyncTaskDialog activity, int idResourceTitle) { | ||
super(activity, idResourceTitle); | ||
context = activity.getApplicationContext(); | ||
} | ||
|
||
@Override | ||
protected Integer doInBackground(ITaskRunner... executers) { | ||
int result = 0; | ||
for (ITaskRunner executer : executers) { | ||
ActivityWithAsyncTaskDialog.setRunner(this); | ||
result += executer.run(context, this); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
setActivity(null); | ||
super.destroy(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/> | ||
*/ | ||
|
||
package de.k3b.android.widget; | ||
|
||
import android.content.Context; | ||
|
||
import de.k3b.io.IProgessListener; | ||
|
||
/** | ||
* {@link ActivityWithAsyncTaskDialog} is an Activity that shows a Progress-Dialog while | ||
* {@link AsyncTaskRunnerWithProgressDialog} runs a {@link ITaskRunner} in the Background | ||
*/ | ||
public interface ITaskRunner { | ||
int run(Context context, IProgessListener iProgessListener); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters