Skip to content

Instantly share code, notes, and snippets.

@senneco
Created October 26, 2016 14:42
Show Gist options
  • Save senneco/7aa086ba23c6ef2b37eabc623f21a7d4 to your computer and use it in GitHub Desktop.
Save senneco/7aa086ba23c6ef2b37eabc623f21a7d4 to your computer and use it in GitHub Desktop.
public class PlayerActivity extends MvpAppCompatActivity implements PlayerView {
@InjectPresenter
PlayerPresenter mPlayerPresenter;
Player mPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello);
mPlayer = new Player();
}
@Override
protected void onStart() {
super.onStart();
mPlayerPresenter.onStart();
}
@Override
protected void onStop() {
super.onStop();
mPlayerPresenter.onStop(mPlayer.playPosition());
}
@Override
public void play(String url, long position) {
mPlayer.play(url, position);
}
@Override
public void stop() {
mPlayer.stop();
}
}
@InjectViewState
public class PlayerPresenter extends MvpPresenter<PlayerView>{
private long mLastPlayPosition;
public void onStart() {
getViewState().play(selectUrl(), mLastPlayPosition);
}
public void onStop(long lastPlayPosition) {
mLastPlayPosition = lastPlayPosition;
getViewState().stop();
}
private String selectUrl() {
return "http://google.com";
}
}
public interface PlayerView extends MvpView {
void play(String url, long position);
void stop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment