Created
May 13, 2017 15:00
-
-
Save parahall/699862187251d7388e713eb6815a0d74 to your computer and use it in GitHub Desktop.
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
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