1.AbstractMvpActivity.java 改为继承BaseActivity.java AbstractMvpFragment.java继承BaseFragment.java 2.设置页UI修改
This commit is contained in:
@@ -1,109 +0,0 @@
|
||||
package com.yizhuan.xchat_android_library.base;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.yizhuan.xchat_android_library.base.factory.BaseMvpProxy;
|
||||
import com.yizhuan.xchat_android_library.base.factory.PresenterMvpFactory;
|
||||
import com.yizhuan.xchat_android_library.base.factory.PresenterMvpFactoryImpl;
|
||||
import com.yizhuan.xchat_android_library.base.factory.PresenterProxyInterface;
|
||||
import com.trello.rxlifecycle3.components.support.RxAppCompatActivity;
|
||||
|
||||
/**
|
||||
* <p> 1. 子类的Presenter必须继承自AbstractMvpPresenter;
|
||||
* 2. 子类的View必须继承自IMvpBaseView
|
||||
* </p>
|
||||
*
|
||||
* @author jiahui
|
||||
* @date 2017/12/7
|
||||
*/
|
||||
public abstract class AbstractMvpActivity<V extends IMvpBaseView, P extends AbstractMvpPresenter<V>> extends RxAppCompatActivity
|
||||
implements PresenterProxyInterface<V, P> {
|
||||
public static final boolean DEBUG = false;
|
||||
protected boolean afterOnSavedInstanceState = false;
|
||||
private static final String TAG_LOG = "Super-mvp";
|
||||
private static final String KEY_SAVE_PRESENTER = "key_save_presenter";
|
||||
|
||||
/** 创建代理对象,传入默认的Presenter工厂 */
|
||||
private BaseMvpProxy<V, P> mMvpProxy = new BaseMvpProxy<>(PresenterMvpFactoryImpl.<V, P>createFactory(getClass()));
|
||||
private final String activityName = getClass().getName();
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
logInfo(activityName + " V onCreate...");
|
||||
logInfo(activityName + " V onCreate... mProxy=" + mMvpProxy);
|
||||
logInfo(activityName + " V onCreate... this=" + this.hashCode());
|
||||
if (savedInstanceState != null) {
|
||||
mMvpProxy.onRestoreInstanceState(savedInstanceState.getBundle(KEY_SAVE_PRESENTER));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
logInfo(activityName + " V onStart...");
|
||||
mMvpProxy.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
logInfo(activityName + " V onResume...");
|
||||
mMvpProxy.onResume((V) this);
|
||||
afterOnSavedInstanceState = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
mMvpProxy.onPause();
|
||||
super.onPause();
|
||||
logInfo(activityName + " V onPause...");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
mMvpProxy.onStop();
|
||||
super.onStop();
|
||||
logInfo(activityName + " V onStop...");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
mMvpProxy.onDestroy();
|
||||
super.onDestroy();
|
||||
logInfo(activityName + " V onDestroy...");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
logInfo(activityName + " V onSaveInstanceState...");
|
||||
outState.putBundle(KEY_SAVE_PRESENTER, mMvpProxy.onSaveInstanceState());
|
||||
afterOnSavedInstanceState = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPresenterFactory(PresenterMvpFactory<V, P> presenterFactory) {
|
||||
logInfo(activityName + " V setPresenterFactory...");
|
||||
mMvpProxy.setPresenterFactory(presenterFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PresenterMvpFactory<V, P> getPresenterFactory() {
|
||||
logInfo(activityName + " V getPresenterFactory...");
|
||||
return mMvpProxy.getPresenterFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public P getMvpPresenter() {
|
||||
logInfo(activityName + " V getMvpPresenter...");
|
||||
return mMvpProxy.getMvpPresenter();
|
||||
}
|
||||
|
||||
private void logInfo(String msg) {
|
||||
if (DEBUG)
|
||||
Log.e(TAG_LOG, msg);
|
||||
}
|
||||
}
|
@@ -1,105 +0,0 @@
|
||||
package com.yizhuan.xchat_android_library.base;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.yizhuan.xchat_android_library.base.factory.BaseMvpProxy;
|
||||
import com.yizhuan.xchat_android_library.base.factory.PresenterMvpFactory;
|
||||
import com.yizhuan.xchat_android_library.base.factory.PresenterMvpFactoryImpl;
|
||||
import com.yizhuan.xchat_android_library.base.factory.PresenterProxyInterface;
|
||||
import com.trello.rxlifecycle3.components.support.RxFragment;
|
||||
|
||||
/**
|
||||
* <p> 1. 子类的Presenter必须继承自AbstractMvpPresenter;
|
||||
* 2. 子类的View必须继承自IMvpBaseView
|
||||
* </p>
|
||||
*
|
||||
* @author jiahui
|
||||
* @date 2017/12/8
|
||||
*/
|
||||
public class AbstractMvpFragment<V extends IMvpBaseView, P extends AbstractMvpPresenter<V>> extends RxFragment
|
||||
implements PresenterProxyInterface<V, P> {
|
||||
protected final String TAG = getClass().getSimpleName();
|
||||
private static final String TAG_LOG = "Super-mvp";
|
||||
private static final String KEY_SAVE_PRESENTER = "key_save_presenter";
|
||||
/** 创建代理对象,传入默认的Presenter工厂 */
|
||||
private BaseMvpProxy<V, P> mMvpProxy = new BaseMvpProxy<>(PresenterMvpFactoryImpl.<V, P>createFactory(getClass()));
|
||||
private String mFragmentName = getClass().getName();
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
logInfo(mFragmentName + " V onCreate...");
|
||||
logInfo(mFragmentName + " V onCreate... mProxy=" + mMvpProxy);
|
||||
logInfo(mFragmentName + " V onCreate... this=" + this.hashCode());
|
||||
if (savedInstanceState != null) {
|
||||
mMvpProxy.onRestoreInstanceState(savedInstanceState.getBundle(KEY_SAVE_PRESENTER));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
logInfo(mFragmentName + " V onStart...");
|
||||
mMvpProxy.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
logInfo(mFragmentName + " V onResume...");
|
||||
mMvpProxy.onResume((V) this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
mMvpProxy.onPause();
|
||||
super.onPause();
|
||||
logInfo(mFragmentName + " V onPause...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
mMvpProxy.onStop();
|
||||
super.onStop();
|
||||
logInfo(mFragmentName + " V onStop...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
mMvpProxy.onDestroy();
|
||||
super.onDestroy();
|
||||
logInfo(mFragmentName + " V onDestroy...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
logInfo(mFragmentName + " V onSaveInstanceState...");
|
||||
outState.putBundle(KEY_SAVE_PRESENTER, mMvpProxy.onSaveInstanceState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPresenterFactory(PresenterMvpFactory<V, P> presenterFactory) {
|
||||
logInfo(mFragmentName + " V setPresenterFactory...");
|
||||
mMvpProxy.setPresenterFactory(presenterFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PresenterMvpFactory<V, P> getPresenterFactory() {
|
||||
logInfo(mFragmentName + " V getPresenterFactory...");
|
||||
return mMvpProxy.getPresenterFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public P getMvpPresenter() {
|
||||
logInfo(mFragmentName + " V getMvpPresenter...");
|
||||
return mMvpProxy.getMvpPresenter();
|
||||
}
|
||||
|
||||
private void logInfo(String msg) {
|
||||
if (AbstractMvpActivity.DEBUG)
|
||||
Log.e(TAG_LOG, msg);
|
||||
}
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
package com.yizhuan.xchat_android_library.base;
|
||||
package com.yizhuan.xchat_android_library.base.factory;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -9,6 +9,9 @@ import com.trello.rxlifecycle3.LifecycleProvider;
|
||||
import com.trello.rxlifecycle3.LifecycleTransformer;
|
||||
import com.trello.rxlifecycle3.OutsideLifecycleException;
|
||||
import com.trello.rxlifecycle3.RxLifecycle;
|
||||
import com.yizhuan.xchat_android_library.BuildConfig;
|
||||
import com.yizhuan.xchat_android_library.base.IMvpBaseView;
|
||||
import com.yizhuan.xchat_android_library.base.PresenterEvent;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.functions.Function;
|
||||
@@ -135,7 +138,7 @@ public abstract class AbstractMvpPresenter<V extends IMvpBaseView> implements Li
|
||||
};
|
||||
|
||||
private void logInfo(String msg) {
|
||||
if (AbstractMvpActivity.DEBUG)
|
||||
if (BuildConfig.DEBUG)
|
||||
Log.e(TAG, msg);
|
||||
}
|
||||
|
@@ -3,8 +3,7 @@ package com.yizhuan.xchat_android_library.base.factory;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.yizhuan.xchat_android_library.base.AbstractMvpActivity;
|
||||
import com.yizhuan.xchat_android_library.base.AbstractMvpPresenter;
|
||||
import com.yizhuan.xchat_android_library.BuildConfig;
|
||||
import com.yizhuan.xchat_android_library.base.IMvpBaseView;
|
||||
|
||||
|
||||
@@ -138,7 +137,7 @@ public class BaseMvpProxy<V extends IMvpBaseView, P extends AbstractMvpPresenter
|
||||
}
|
||||
|
||||
private void logInfo(String msg) {
|
||||
if (AbstractMvpActivity.DEBUG)
|
||||
if (BuildConfig.DEBUG)
|
||||
Log.e(TAG, msg);
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package com.yizhuan.xchat_android_library.base.factory;
|
||||
|
||||
import com.yizhuan.xchat_android_library.base.AbstractMvpPresenter;
|
||||
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package com.yizhuan.xchat_android_library.base.factory;
|
||||
|
||||
|
||||
import com.yizhuan.xchat_android_library.base.AbstractMvpPresenter;
|
||||
import com.yizhuan.xchat_android_library.base.IMvpBaseView;
|
||||
|
||||
/**
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package com.yizhuan.xchat_android_library.base.factory;
|
||||
|
||||
|
||||
import com.yizhuan.xchat_android_library.base.AbstractMvpPresenter;
|
||||
import com.yizhuan.xchat_android_library.base.IMvpBaseView;
|
||||
|
||||
/**
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package com.yizhuan.xchat_android_library.base.factory;
|
||||
|
||||
|
||||
import com.yizhuan.xchat_android_library.base.AbstractMvpPresenter;
|
||||
import com.yizhuan.xchat_android_library.base.IMvpBaseView;
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user