mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-23 07:19:13 +00:00
Abstract some parts of the AsyncTasks away into ProgressDialogTask
This commit is contained in:
parent
ca210de78e
commit
4f98d8764c
3 changed files with 40 additions and 30 deletions
|
@ -1,8 +1,6 @@
|
|||
package me.impy.aegis;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Process;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
|
@ -10,14 +8,12 @@ import javax.crypto.SecretKey;
|
|||
import me.impy.aegis.crypto.CryptoUtils;
|
||||
import me.impy.aegis.crypto.slots.PasswordSlot;
|
||||
|
||||
public class DerivationTask extends AsyncTask<DerivationTask.Params, Void, SecretKey> {
|
||||
public class DerivationTask extends ProgressDialogTask<DerivationTask.Params, SecretKey> {
|
||||
private Callback _cb;
|
||||
private ProgressDialog _dialog;
|
||||
|
||||
public DerivationTask(Context context, Callback cb) {
|
||||
super(context, "Deriving key from password");
|
||||
_cb = cb;
|
||||
_dialog = new ProgressDialog(context);
|
||||
_dialog.setCancelable(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -35,17 +31,9 @@ public class DerivationTask extends AsyncTask<DerivationTask.Params, Void, Secre
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
_dialog.setMessage("Deriving key from password");
|
||||
_dialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(SecretKey key) {
|
||||
if (_dialog.isShowing()) {
|
||||
_dialog.dismiss();
|
||||
}
|
||||
super.onPostExecute(key);
|
||||
_cb.onTaskFinished(key);
|
||||
}
|
||||
|
||||
|
|
34
app/src/main/java/me/impy/aegis/ProgressDialogTask.java
Normal file
34
app/src/main/java/me/impy/aegis/ProgressDialogTask.java
Normal file
|
@ -0,0 +1,34 @@
|
|||
package me.impy.aegis;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.annotation.CallSuper;
|
||||
|
||||
public abstract class ProgressDialogTask<Params, Result> extends AsyncTask<Params, Void, Result> {
|
||||
private ProgressDialog _dialog;
|
||||
|
||||
public ProgressDialogTask(Context context, String message) {
|
||||
_dialog = new ProgressDialog(context);
|
||||
_dialog.setCancelable(false);
|
||||
_dialog.setMessage(message);
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
_dialog.show();
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
protected void onPostExecute(Result result) {
|
||||
if (_dialog.isShowing()) {
|
||||
_dialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
protected final ProgressDialog getDialog() {
|
||||
return _dialog;
|
||||
}
|
||||
}
|
|
@ -1,8 +1,6 @@
|
|||
package me.impy.aegis;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Process;
|
||||
|
||||
import java.lang.reflect.UndeclaredThrowableException;
|
||||
|
@ -18,16 +16,14 @@ import me.impy.aegis.crypto.slots.Slot;
|
|||
import me.impy.aegis.crypto.slots.SlotCollection;
|
||||
import me.impy.aegis.crypto.slots.SlotIntegrityException;
|
||||
|
||||
public class SlotCollectionTask<T extends Slot> extends AsyncTask<SlotCollectionTask.Params, Void, MasterKey> {
|
||||
public class SlotCollectionTask<T extends Slot> extends ProgressDialogTask<SlotCollectionTask.Params, MasterKey> {
|
||||
private Callback _cb;
|
||||
private Class<T> _type;
|
||||
private ProgressDialog _dialog;
|
||||
|
||||
public SlotCollectionTask(Class<T> type, Context context, Callback cb) {
|
||||
super(context, "Decrypting database");
|
||||
_cb = cb;
|
||||
_type = type;
|
||||
_dialog = new ProgressDialog(context);
|
||||
_dialog.setCancelable(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -70,17 +66,9 @@ public class SlotCollectionTask<T extends Slot> extends AsyncTask<SlotCollection
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
_dialog.setMessage("Decrypting database");
|
||||
_dialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(MasterKey masterKey) {
|
||||
if (_dialog.isShowing()) {
|
||||
_dialog.dismiss();
|
||||
}
|
||||
super.onPostExecute(masterKey);
|
||||
_cb.onTaskFinished(masterKey);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue