Clean up
This commit is contained in:
parent
b6034f7484
commit
614f28e0c9
23 changed files with 220 additions and 89 deletions
|
|
@ -2,7 +2,6 @@ package com.kabouzeid.gramophone.misc;
|
|||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
|
@ -12,9 +11,8 @@ import java.lang.ref.WeakReference;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public abstract class DialogAsyncTask<Params, Progress, Result> extends AsyncTask<Params, Progress, Result> {
|
||||
public abstract class DialogAsyncTask<Params, Progress, Result> extends WeakContextAsyncTask<Params, Progress, Result> {
|
||||
private final int delay;
|
||||
private WeakReference<Context> contextWeakReference;
|
||||
private WeakReference<Dialog> dialogWeakReference;
|
||||
|
||||
private boolean supposedToBeDismissed;
|
||||
|
|
@ -24,8 +22,8 @@ public abstract class DialogAsyncTask<Params, Progress, Result> extends AsyncTas
|
|||
}
|
||||
|
||||
public DialogAsyncTask(Context context, int showDelay) {
|
||||
super(context);
|
||||
this.delay = showDelay;
|
||||
contextWeakReference = new WeakReference<>(context);
|
||||
dialogWeakReference = new WeakReference<>(null);
|
||||
}
|
||||
|
||||
|
|
@ -62,11 +60,6 @@ public abstract class DialogAsyncTask<Params, Progress, Result> extends AsyncTas
|
|||
protected void onProgressUpdate(@NonNull Dialog dialog, Progress... values) {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Context getContext() {
|
||||
return contextWeakReference.get();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Dialog getDialog() {
|
||||
return dialogWeakReference.get();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
package com.kabouzeid.gramophone.misc;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public abstract class WeakContextAsyncTask<Params, Progress, Result> extends AsyncTask<Params, Progress, Result> {
|
||||
private WeakReference<Context> contextWeakReference;
|
||||
|
||||
public WeakContextAsyncTask(Context context) {
|
||||
contextWeakReference = new WeakReference<>(context);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Context getContext() {
|
||||
return contextWeakReference.get();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue