Skip to content

Instantly share code, notes, and snippets.

@ryands
Created October 24, 2016 21:00
Show Gist options
  • Save ryands/1b22048e3dcce8857b5b7247f080707d to your computer and use it in GitHub Desktop.
Save ryands/1b22048e3dcce8857b5b7247f080707d to your computer and use it in GitHub Desktop.
super simple base presenter (similar to Mortar's Presenter class)
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