Last active
April 14, 2017 14:06
-
-
Save marcherdiego/a466cb64b4ae18358b8a144cc0c1fbd5 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
//MainActivity.java | |
public class MainActivity extends AppCompatActivity { | |
private MainPresenter presenter; | |
//Simply a singleton of Bus | |
private Bus bus = BusManager.getInstance(); | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main_activity); | |
presenter = new MainPresenter( | |
new MainView(this, bus), | |
new MainModel(bus) | |
); | |
} | |
@Override | |
protected void onResume() { | |
super.onResume(); | |
register(presenter); | |
} | |
@Override | |
protected void onPause() { | |
super.onPause(); | |
unregister(presenter); | |
} | |
} | |
//MainPresenter.java | |
public class MainPresenter { | |
private final MainModel model; | |
private final MainView view; | |
public MainPresenter(MainView view, MainModel model) { | |
this.view = view; | |
this.model = model; | |
} | |
} | |
//MainView.java | |
public class MainView { | |
private final Bus bus; | |
private WeakReference<AppCompatActivity> activityRef; | |
public MainView(AppCompatActivity activity, Bus bus) { | |
activityRef = new WeakReference<>(activity); | |
this.bus = bus; | |
} | |
@Nullable | |
public AppCompatActivity getActivity() { | |
return activityRef.get(); | |
} | |
} | |
//MainModel.java | |
public class MainModel { | |
private final Bus bus; | |
public MainModel(Bus bus) { | |
this.bus = bus; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment