Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Material Design #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions reamplib/src/main/java/etr/android/reamp/mvp/ReampAppActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package etr.android.reamp.mvp;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.util.Log;

import etr.android.reamp.R;

/**
* A base Activity which is {@link ReampView}.
*/
public abstract class ReampAppActivity<P extends ReampPresenter<SM>, SM extends ReampStateModel> extends Activity implements ReampView<SM> {

private MvpDelegate delegate = new MvpDelegate(this);

@Override
protected void onCreate(Bundle savedInstanceState) {
delegate.onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
}

@Override
protected void onStart() {
super.onStart();
delegate.connect();
}

@Override
protected void onStop() {
super.onStop();
delegate.disconnect();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
delegate.onSaveInstanceState(outState);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
delegate.onResult(requestCode, resultCode, data);
}

@Override
protected void onDestroy() {
delegate.onDestroy();
super.onDestroy();
}

@Override
public Context getContext() {
return this;
}

public P getPresenter() {
return delegate.<P, SM>getPresenter();
}

@Override
public void onError(Throwable throwable) {
new AlertDialog.Builder(this)
.setTitle(getString(R.string.reamp_common_error_title))
.setMessage(Log.getStackTraceString(throwable))
.show();

}

public String getMvpId() {
return delegate.getId();
}
}