Created
October 24, 2016 21:00
-
-
Save ryands/1b22048e3dcce8857b5b7247f080707d to your computer and use it in GitHub Desktop.
super simple base presenter (similar to Mortar's Presenter class)
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
import android.os.Bundle; | |
import android.support.annotation.NonNull; | |
import android.view.View; | |
public abstract class Presenter<V extends View> { | |
private V view; | |
public final void takeView(@NonNull V view) { | |
if (view == null) throw new NullPointerException("View must not be null"); | |
if (this.view != view) { | |
if (this.view != null) { | |
dropView(this.view); | |
} | |
this.view = view; | |
} | |
} | |
public final void dropView(V view) { | |
if (view == null) throw new NullPointerException("dropped view must not be null"); | |
this.view = null; | |
} | |
protected final boolean hasView() { | |
return view != null; | |
} | |
protected final V getView() { | |
return view; | |
} | |
protected void onLoad(Bundle savedInstanceState) { | |
} | |
protected void onSave(Bundle outState) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment