说明:我使用的软件是android studio3.1版本,可能部分软件使用的并不是最新的,主要是思想。并不讲基础怎么用
首先依赖,butterknife的详细依赖我就不说了,若不懂自己看官网即可
//butterknife
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
//utils
implementation 'com.blankj:utilcode:1.9.6'
//RxLifecycle
implementation 'com.trello.rxlifecycle2:rxlifecycle:2.2.1'
implementation 'com.trello.rxlifecycle2:rxlifecycle-components:2.2.1'
//ARouter
implementation 'com.alibaba:arouter-api:1.3.1'
annotationProcessor 'com.alibaba:arouter-compiler:1.1.4'
//dagger2
implementation 'com.google.dagger:dagger:2.11'
annotationProcessor 'com.google.dagger:dagger-compiler:2.11'
//retrofit
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
//rxjava
implementation 'io.reactivex.rxjava2:rxjava:2.1.11'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'com.jakewharton.rxbinding2:rxbinding:2.1.1'
//logging-interceptor
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
//logger
implementation 'com.orhanobut:logger:2.2.0'
//Cookie拦截
implementation 'com.github.franmontiel:PersistentCookieJar:v1.0.1'
第一步,我个人的习惯,首先定义一个di包,写dagger2
首先是ApplicationModule,我不讲软件的具体使用,网上有很多详细介绍和使用
@Module
public class ApplicationModule {
private App mApplication;
public ApplicationModule(App application) {
mApplication = application;
}
@Provides
@PerApp
@ContextLife("Application")
public Context provideApplicationContext(){
return mApplication.getApplicationContext();
}
}
注解PerApp,若不知道怎么写的可以去拷贝dagger中提供的注解@Singleton,一模一样的代码,名字不一样而已
@Scope
@Documented
@Retention(RUNTIME)
public @interface PerApp {
}
ContextLife注解,用来标识
@Qualifier
@Documented
@Retention(RetentionPolicy.RUNTIME)
public @interface ContextLife {
String value() default "Application";
}
接下来的PerActivity和PerFragment和PerApp是一样的代码,我就不贴代码了
modulecen层写完了接下来写Component中的ApplicationComponent
@PerApp
@Component(modules = ApplicationModule.class)
public interface ApplicationComponent {
@ContextLife("Application")
Context getApplication();
}
ActivityModule层
@Module
public class ActivityModule {
private Activity mActivity;
public ActivityModule(Activity activity) {
mActivity = activity;
}
@PerActivity
@Provides
@ContextLife("Activity")
public Context provideActivityContext(){
return mActivity;
}
@Provides
@PerActivity
public Activity provideActivity() {
return mActivity;
}
}
ActivityComponent层
@PerActivity
@Component(dependencies = ApplicationComponent.class,modules = ActivityModule.class)
public interface ActivityComponent {
@ContextLife("Activity")
Context getActivityContext();
@ContextLife("Application")
Context getApplicationContext();
Activity getActivity();
//这个部分可以先不写,未来需要注入哪个activity写下就可以了
void inject(LoginActivity activity);
void inject(RegisterActivity activity);
}
FragmentModule层
@Module
public class FragmentModule {
private Fragment mFragment;
public FragmentModule(Fragment fragment) {
mFragment = fragment;
}
@PerFragment
@Provides
@ContextLife("Activity")
public Context provideActivityContext(){
return mFragment.getActivity();
}
@Provides
@PerFragment
public Activity provideActivity(){
return mFragment.getActivity();
}
@Provides
@PerFragment
public Fragment provideFragment(){
return mFragment;
}
}
FragmentComponent层
@PerFragment
@Component(dependencies = ApplicationComponent.class,modules = FragmentModule.class)
public interface FragmentComponent {
@ContextLife("Activity")
Context getAcitivtyContext();
@ContextLife("Application")
Context getApplicationContext();
Activity getAcitivty();
void inject(UndoneFragment fragment);
void inject(DoneFragment fragment);
}
好了,以上我们就写完dagger层架构了,然后重新构建下就可以了,一定要重新构建
第二步写Applicaion
首先初始化刚才写的ApplicationComponent
private void initApplicationComponent() {
mApplicationComponent = DaggerApplicationComponent.builder().applicationModule(new ApplicationModule(this)).build();
}
初始化路由器ARoute
private void intARouter() {
// 这两行必须写在init之前,否则这些配置在init过程中将无效
ARouter.openLog(); // 打印日志
ARouter.openDebug(); // 开启调试模式(如果在InstantRun模式下运行,必须开启调试模式!线上版本需要关闭,否则有安全风险)
ARouter.init(this); // 尽可能早,推荐在Application中初始化
}
接下来的配置看自己的需要,比如初始化工具类,打印日志或者Toast等,看自己项目的需要,当然全局上下文是一般都需要配置的,代码我就不贴了
第三步:MVP搭建基本的Activity,Fragment等
我们看Google提供的mvp代码,它提供了一个协议类,这里我也使用一个协议类,当然可以不用,看自己的习惯。我这里使用了一个框架RxLifecycle,解决Rxjava的内存泄漏的问题
协议类BaseContract
public interface BaseContract {
public interface BasePresenter<T extends BaseContract.BaseView>{
void attachView(T view);
void detachView();
}
public interface BaseView {
//显示进度中
void showLoading();
//隐藏进度
void hideLoading();
//显示请求成功
void showSuccess(String message);
//失败重试
void showFaild(String message);
//显示当前网络不可用
void showNoNet();
//重试
void onRetry();
/**
* 绑定生命周期
*
* @param <T>
* @return
*/
<T> LifecycleTransformer<T> bindToLife();
/**
* 跳转到登录页面
*/
void jumpToLogin();
}
}
BaseActivity框架的搭建,直接贴代码
public abstract class BaseActivity<T extends BaseContract.BasePresenter> extends RxAppCompatActivity implements BaseContract.BaseView {
@Nullable
@Inject
protected T mPresenter;
protected ActivityComponent mActivityComponent;
/**
* LoadingView
*/
protected LoadingView mLoadingView;
@Nullable
protected Toolbar mToolbar;
private Unbinder unbinder;
protected abstract void initView();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initActivityComponent();
ARouter.getInstance().inject(this);
int layoutId=getLayoutId();
setContentView(layoutId);
initInjector();
unbinder = ButterKnife.bind(this);
initToolBar();
attachView();
initView();
if (!NetworkUtils.isConnected()) showNoNet();
}
@Override
public void showLoading() {
mLoadingView.setVisibility(View.VISIBLE);
mLoadingView.start();
}
@Override
public void hideLoading() {
mLoadingView.setVisibility(View.GONE);
mLoadingView.stop();
}
@Override
protected void onDestroy() {
super.onDestroy();
unbinder.unbind();
detachView();
}
private void attachView() {
if (mPresenter != null) {
mPresenter.attachView(this);
}
}
/**
* 跳转到登录页面
*/
@Override
public void jumpToLogin() {
ARouter.getInstance().build("/activity/LoginActivity")
.navigation();
}
@Override
public void showFaild(String errorMsg) {
ToastUtils.showShort(errorMsg);
}
@Override
public void onRetry() {
}
@Override
public <T> LifecycleTransformer<T> bindToLife() {
return this.bindToLifecycle();
}
@Override
public void showNoNet() {
ToastUtils.showShort(R.string.no_network_connection);
}
protected void setToolbarTitle(String title) {
getSupportActionBar().setTitle(title);
}
@Override
public void showSuccess(String successMsg) {
ToastUtils.showShort(successMsg);
}
/**
* 分离view
*/
private void detachView() {
if (mPresenter != null) {
mPresenter.detachView();
}
}
/**
* 初始化toolbar
*/
protected void initToolBar(){
mToolbar = (Toolbar) findViewById(R.id.toolbar);
if (mToolbar == null) {
throw new NullPointerException("toolbar can not be null");
}
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(showHomeAsUp());
/**toolbar除掉阴影*/
getSupportActionBar().setElevation(0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mToolbar.setElevation(0);
}
mLoadingView = findViewById(R.id.lv_loading_view);
if (mLoadingView==null){
throw new NullPointerException("loadingView can not be null");
}
mLoadingView.addBitmap(R.drawable.round_green);
mLoadingView.addBitmap(R.drawable.triangle);
mLoadingView.addBitmap(R.drawable.round_red);
}
/**
* 是否显示返回键
*
* @return
*/
protected boolean showHomeAsUp() {
return false;
}
protected abstract void initInjector();
protected abstract int getLayoutId();
/**
* 初始化ActivityComponent
*/
private void initActivityComponent() {
mActivityComponent= DaggerActivityComponent.builder()
.applicationComponent(((App)getApplication()).getApplicationComponent())
.activityModule(new ActivityModule(this))
.build();
}
}
,loading大家可以按自己的想法去做,也可以去使用开源库,使用的时候就不要去new了而是添加注解@Inject就可以了
//loadview
implementation 'com.classic.common:multiple-status-view:1.5.1'
BaseFragment框架搭建,代码简单,本人也懒,就直接贴代码了
public abstract class BaseFragment<T extends BaseContract.BasePresenter> extends RxFragment implements BaseContract.BaseView {
private static final String STATE_SAVE_IS_HIDDEN = "STATE_SAVE_IS_HIDDEN";
@Nullable
@Inject
protected T mPresenter;
protected FragmentComponent mFragmentComponent;
private Unbinder unbinder;
private View mRootView, mErrorView, mEmptyView;
protected abstract int getLayoutId();
protected abstract void initInjector();
protected abstract void initView(View view);
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initFragmentComponent();
ARouter.getInstance().inject(this);
initInjector();
attachView();
if (!NetworkUtils.isConnected()) showNoNet();
if (savedInstanceState != null) {
boolean isSupportHidden = savedInstanceState.getBoolean(STATE_SAVE_IS_HIDDEN);
FragmentTransaction ft = getFragmentManager().beginTransaction();
if (isSupportHidden) {
ft.hide(this);
} else {
ft.show(this);
}
ft.commit();
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putBoolean(STATE_SAVE_IS_HIDDEN, isHidden());
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
inflaterView(inflater, container);
unbinder = ButterKnife.bind(this, mRootView);
initView(mRootView);
return mRootView;
}
@Override
public void onDestroy() {
super.onDestroy();
unbinder.unbind();
detachView();
}
@Override
public void showLoading() {
ToastUtils.showShort("showLoading");
}
@Override
public void hideLoading() {
ToastUtils.showShort("hideLoading");
}
@Override
public void showSuccess(String successMsg) {
ToastUtils.showShort(successMsg);
}
@Override
public void showFaild(String errorMsg) {
ToastUtils.showShort(errorMsg);
}
@Override
public void showNoNet() {
ToastUtils.showShort(R.string.no_network_connection);
}
@Override
public void onRetry() {
ToastUtils.showShort("onRetry");
}
@Override
public <T> LifecycleTransformer<T> bindToLife() {
return this.bindToLifecycle();
}
/**
* 设置加载数据结果
*
* @param baseQuickAdapter
* @param refreshLayout
* @param list
* @param loadType
*/
protected void setLoadDataResult(BaseQuickAdapter baseQuickAdapter, SwipeRefreshLayout refreshLayout, List list, @LoadType.checker int loadType) {
baseQuickAdapter.openLoadAnimation(BaseQuickAdapter.SLIDEIN_BOTTOM);
switch (loadType) {
case LoadType.TYPE_REFRESH_SUCCESS:
baseQuickAdapter.setNewData(list);
refreshLayout.setRefreshing(false);
ToastUtils.showShort(R.string.refresh_success);
break;
case LoadType.TYPE_REFRESH_ERROR:
refreshLayout.setRefreshing(false);
ToastUtils.showShort(R.string.refresh_error);
break;
case LoadType.TYPE_LOAD_MORE_SUCCESS:
if (list != null) baseQuickAdapter.addData(list);
ToastUtils.showShort(R.string.load_more_success);
break;
case LoadType.TYPE_LOAD_MORE_ERROR:
baseQuickAdapter.loadMoreFail();
ToastUtils.showShort(R.string.load_more_error);
break;
}
if (list == null || list.isEmpty() || list.size() < Constant.PAGE_SIZE) {
baseQuickAdapter.loadMoreEnd(false);
} else {
baseQuickAdapter.loadMoreComplete();
}
}
/**
* 初始化FragmentComponent
*/
private void initFragmentComponent() {
mFragmentComponent = DaggerFragmentComponent.builder()
.applicationComponent(((App) getActivity().getApplication()).getApplicationComponent())
.fragmentModule(new FragmentModule(this))
.build();
}
/**
* 贴上view
*/
private void attachView() {
if (mPresenter != null) {
mPresenter.attachView(this);
}
}
/**
* 分离view
*/
private void detachView() {
if (mPresenter != null) {
mPresenter.detachView();
}
}
/**
* 设置View
*
* @param inflater
* @param container
*/
private void inflaterView(LayoutInflater inflater, @Nullable ViewGroup container) {
if (mRootView == null) {
mRootView = inflater.inflate(getLayoutId(), container, false);
}
}
@Override
public void jumpToLogin() {
ARouter.getInstance().build("/activity/LoginActivity")
.navigation();
}
}
这里讲下setLoadDataResult,因为这里我使用的框架是BaseRecyclerViewAdapterHelper
//baseAdapterHelper
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30'
implementation 'com.android.support:preference-v14:26.1.0'
LoadType 代码
public class LoadType {
public static final int TYPE_REFRESH_SUCCESS = 1;
public static final int TYPE_REFRESH_ERROR = 2;
public static final int TYPE_LOAD_MORE_SUCCESS = 3;
public static final int TYPE_LOAD_MORE_ERROR = 4;
@IntDef({TYPE_REFRESH_SUCCESS, TYPE_REFRESH_ERROR, TYPE_LOAD_MORE_SUCCESS, TYPE_LOAD_MORE_ERROR})
@Retention(RetentionPolicy.SOURCE)
public @interface checker {
}
}
第四步:上面的Base基本写完了,接下来是Rxjava+retrofit的使用,这里我以登录注册为例写,首先我们写个RetorfitManager类
public class RetrofitManager {
private static long CONNECT_TIMEOUT = 60L;
private static long READ_TIMEOUT = 10L;
private static long WRITE_TIMEOUT = 10L;
//设缓存有效期为1天
private static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1;
//查询缓存的Cache-Control设置,为only-if-cached时只查询缓存而不会请求服务器,max-stale可以配合设置缓存失效时间
public static final String CACHE_CONTROL_CACHE = "only-if-cached, max-stale=" + CACHE_STALE_SEC;
//查询网络的Cache-Control设置
//(假如请求了服务器并在a时刻返回响应结果,则在max-age规定的秒数内,浏览器将不会发送对应的请求到服务器,数据由缓存直接返回)
public static final String CACHE_CONTROL_NETWORK = "Cache-Control: public, max-age=10";
// 避免出现 HTTP 403 Forbidden,参考:http://stackoverflow.com/questions/13670692/403-forbidden-with-java-but-not-web-browser
private static final String AVOID_HTTP403_FORBIDDEN = "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11";
private static volatile OkHttpClient mOkHttpClient;
/**
* 云端响应头拦截器,用来配置缓存策略
*/
private static final Interceptor mRewriteCacheControlInterceptor = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();//获得上一个请求
if (!NetworkUtils.isConnected()) {
request = request.newBuilder()
.cacheControl(CacheControl.FORCE_CACHE)
.build();
}
Response originalResponse = chain.proceed(request);
if (NetworkUtils.isConnected()) {
//有网的时候读接口上的@Headers里的配置,可以在这里进行统一的设置
String cacheControl = request.cacheControl().toString();
return originalResponse.newBuilder()
.header("Cache-Control", cacheControl)
.removeHeader("Pragma")
.build();
} else {
return originalResponse.newBuilder()
.header("Cache-Control", "public, only-if-cached, max-stale=" + CACHE_CONTROL_CACHE)
.removeHeader("Pragma")
.build();
}
}
};
private static final HttpLoggingInterceptor mLoggingInterceptor = new HttpLoggingInterceptor()
.setLevel(HttpLoggingInterceptor.Level.BODY);
/**
* 日志拦截器
*/
private static final Interceptor mLoggingIntercepter = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Response response = chain.proceed(request);
String isSuccess = response.isSuccessful() ? "true" : "false";
Logger.w(isSuccess);
ResponseBody body = response.body();
BufferedSource source = body.source();
source.request(Long.MAX_VALUE);
Buffer buffer = source.buffer();
Charset charset = Charset.defaultCharset();
MediaType contentType = body.contentType();
if (contentType != null) {
charset = contentType.charset();
}
String bodyString = buffer.clone().readString(charset);
Logger.w(String.format("Received response json string " + bodyString));
return response;
}
};
/**
* 获取OkHttpClient实例
*
* @return
*/
private static OkHttpClient getOkHttpClient() {
if (mOkHttpClient == null) {
synchronized (RetrofitManager.class) {
ClearableCookieJar cookieJar =
new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(App.getAppContext()));
Cache cache = new Cache(new File(App.getAppContext().getCacheDir(), "HttpCache"), 1024 * 1024 * 100);
if (mOkHttpClient == null) {
mOkHttpClient = new OkHttpClient.Builder()
.cache(cache)
.connectTimeout(CONNECT_TIMEOUT, TimeUnit.SECONDS)
.readTimeout(READ_TIMEOUT, TimeUnit.SECONDS)
.writeTimeout(WRITE_TIMEOUT, TimeUnit.SECONDS)
.addInterceptor(mRewriteCacheControlInterceptor)
.addInterceptor(mLoggingIntercepter)
// .addInterceptor(interceptor)
// .cookieJar(new CookiesManager())
.cookieJar(cookieJar)
.build();
}
}
}
return mOkHttpClient;
}
/**
* 获取Service
*
* @param clazz
* @param <T>
* @return
*/
public static <T> T create(Class<T> clazz) {
//http://wanandroid.com/
Retrofit retrofit = new Retrofit.Builder().baseUrl(Constant.REQUEST_BASE_URL)
.client(getOkHttpClient())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
return retrofit.create(clazz);
}
}
ApiService接口,用来存放访问的接口
/**
* 登录接口
* http://www.wanandroid.com/user/login
*
* @param username 用户名
* @param password 密码
* @return
*/
@POST("/user/login")
@FormUrlEncoded
Observable<DataResponse<User>> login(@Field("username") String username, @Field("password") String password);
/**
* 注册用户的方法
* http://www.wanandroid.com/user/register
*
* @param username 用户名
* @param password 密码
* @param repassword 确认密码
* @return
*/
@POST("/user/register")
@FormUrlEncoded
Observable<DataResponse> register(@Field("username") String username, @Field("password") String password, @Field("repassword") String repassword);
接下来以登录为例
首先我们会写个登录的协议类继承于基本的的协议类的view和Presenter,实现登录自己的view和请求
public interface LoginActivityContract {
interface View extends BaseContract.BaseView {
/**
* 登录成功
*/
void showLoginSuccess();
}
interface Presenter extends BaseContract.BasePresenter<View> {
/**
* 登录用户
*
* @param account 用户名
* @param password 密码
*/
void Login(String account, String password);
}
}
LoginActivity需要一个属于自己Presenter去实现访问网络,首先写个基本的Presenter
public class BasePresenter<T extends BaseContract.BaseView> implements BaseContract.BasePresenter<T> {
protected T mView;
@Override
public void attachView(T view) {
this.mView = view;
}
@Override
public void detachView() {
if (mView != null) {
mView = null;
}
}
}
LoginActivityImp登录的实现类
public class LoginActivityImp extends BasePresenter<LoginActivityContract.View> implements LoginActivityContract.Presenter {
@Inject
public LoginActivityImp(){
}
@Override
public void Login(String account, String password) {
mView.showLoading();
RetrofitManager.create(ApiService.class).login(account,password)
.compose(mView.<DataResponse<User>>bindToLife())
.compose(RxSchedulers.<DataResponse<User>>applySchedulers())
.subscribe(new Consumer<DataResponse<User>>() {
@Override
public void accept(DataResponse<User> userDataResponse) throws Exception {
if (userDataResponse.getErrorCode()!=0){
//表示出错
mView.showFaild(userDataResponse.getErrorMsg().toString());
}else{
mView.showLoginSuccess();
}
mView.hideLoading();
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
mView.showFaild("请检查网络,稍后重试!");
mView.hideLoading();
}
});
}
}
RxSchedulers通用的Rx线程转换类
public class RxSchedulers {
static final ObservableTransformer schedulersTransformer=new ObservableTransformer() {
@Override
public ObservableSource apply(Observable upstream) {
return (upstream).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
};
public static <T> ObservableTransformer<T, T> applySchedulers() {
return (ObservableTransformer<T, T>)schedulersTransformer;
}
}
接下来就是写LoginActivity,只贴了部分代码,主要看核心代码,其他看自己界面来写
@Route(path = "/activity/LoginActivity")
public class LoginActivity extends BaseActivity<LoginActivityImp> implements LoginActivityContract.View {
@Override
protected void initInjector() {
ARouter.getInstance().inject(this);
mActivityComponent.inject(this);
}
}
登录的时候只需要
mPresenter.Login(tvAlAccount.getText().toString().trim(), tvAlPassword.getText().toString().trim());
登录成功的时候
@Override
public void showLoginSuccess() {
showSuccess("登录成功!");
SPUtils.getInstance().put("account",tvAlAccount.getText().toString().trim());
SPUtils.getInstance().put("password",tvAlPassword.getText().toString().trim());
ARouter.getInstance().build("/activity/MainActivity")
.navigation();
finish();
}
这里再举个注册
协议类
public interface RegisterActivityContract {
public interface View extends BaseContract.BaseView {
/**
* 注册成功后业务逻辑
*/
void showRegisterSuccess();
}
interface Presenter extends BaseContract.BasePresenter<View> {
/**
* 注册接口
*/
void register(String account, String password, String rePassword);
}
}
RegisterActivityImp
public class RegisterActivityImp extends BasePresenter<RegisterActivityContract.View> implements RegisterActivityContract.Presenter{
@Inject
public RegisterActivityImp(){
}
@Override
public void register(String account, String password, String rePassword) {
mView.showLoading();
RetrofitManager.create(ApiService.class).register(account,password,rePassword)
.compose(mView.bindToLife())
.compose(RxSchedulers.applySchedulers())
.subscribe(new Consumer<DataResponse>() {
@Override
public void accept(DataResponse dataResponse) throws Exception {
if (dataResponse.getErrorCode()!=0){
mView.showFaild(dataResponse.getErrorMsg().toString());
}else {
mView.showRegisterSuccess();
}
mView.hideLoading();
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
mView.showFaild(throwable.getMessage().toString());
mView.hideLoading();
}
});
}
}
RegisterActivity
@Route(path = "/activity/RegisterActivity")
public class RegisterActivity extends BaseActivity<RegisterActivityImp> implements RegisterActivityContract.View{
@Override
protected void initInjector() {
ARouter.getInstance().inject(this);
mActivityComponent.inject(this);
}
}
注册
mPresenter.register(account.getText().toString().trim(),password.getText().toString().trim(),repassword.getText().toString().trim());
注册成功
@Override
public void showRegisterSuccess() {
showSuccess("注册成功,重新登录!");
SPUtils.getInstance().put("account",account.getText().toString().trim());
//跳转到登录页面
ARouter.getInstance().build("/activity/LoginActivity")
.navigation();
}
其实呢,基本上呢都是一些套路。大家可以多看看别人写的demo然后自己去敲一遍