Skip to content

Instantly share code, notes, and snippets.

@parahall
Created May 13, 2017 15:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save parahall/699862187251d7388e713eb6815a0d74 to your computer and use it in GitHub Desktop.
Save parahall/699862187251d7388e713eb6815a0d74 to your computer and use it in GitHub Desktop.
public abstract class BasePresenter<T extends MvpView> {
HandlerThread thread;
Looper looper;
Handler handler;
private T mView;
public BasePresenter() {
}
public HandlerThread getThread() {
return thread;
}
public Looper getLooper() {
return looper;
}
public Handler getHandler() {
return handler;
}
public void setHandler(Handler handler) {
this.handler = handler;
}
public void attachView(T t) {
thread = new HandlerThread(getClass().getName(), android.os.Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
looper = thread.getLooper();
mView = t;
}
public void detachView() {
mView = null;
if (handler != null) {
handler.removeCallbacksAndMessages(null);
handler = null;
}
if (thread != null) thread.quit();
}
public T getView() {
return mView;
}
public boolean isViewAttached() {
return mView != null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment