Commit d7f4139e539dc2be605e9a68f01c10eebaf25689
1 parent
c6b9ffa4
base测试
Showing
11 changed files
with
26 additions
and
376 deletions
core/base/src/main/java/com/cnlive/libs/base/frame/activity/MvpActivity.java
| ... | ... | @@ -4,7 +4,7 @@ import android.os.Bundle; |
| 4 | 4 | |
| 5 | 5 | import androidx.annotation.NonNull; |
| 6 | 6 | |
| 7 | -import com.cnlive.libs.base.mvp.ReflectUtil; | |
| 7 | +import com.cnlive.libs.base.util.ReflectUtil; | |
| 8 | 8 | import com.hannesdorfmann.mosby3.mvp.MvpPresenter; |
| 9 | 9 | import com.hannesdorfmann.mosby3.mvp.MvpView; |
| 10 | 10 | ... | ... |
core/base/src/main/java/com/cnlive/libs/base/frame/activity/MvpBindingActivity.java
| ... | ... | @@ -6,7 +6,7 @@ import androidx.annotation.NonNull; |
| 6 | 6 | import androidx.databinding.DataBindingUtil; |
| 7 | 7 | import androidx.databinding.ViewDataBinding; |
| 8 | 8 | |
| 9 | -import com.cnlive.libs.base.mvp.ReflectUtil; | |
| 9 | +import com.cnlive.libs.base.util.ReflectUtil; | |
| 10 | 10 | import com.hannesdorfmann.mosby3.mvp.MvpPresenter; |
| 11 | 11 | import com.hannesdorfmann.mosby3.mvp.MvpView; |
| 12 | 12 | ... | ... |
core/base/src/main/java/com/cnlive/libs/base/frame/fragment/MyFragment.java renamed to core/base/src/main/java/com/cnlive/libs/base/frame/fragment/BaseFragment.java
| ... | ... | @@ -5,10 +5,10 @@ import android.view.LayoutInflater; |
| 5 | 5 | import android.view.View; |
| 6 | 6 | import android.view.ViewGroup; |
| 7 | 7 | |
| 8 | -import androidx.annotation.NonNull; | |
| 9 | 8 | import androidx.annotation.Nullable; |
| 10 | 9 | |
| 11 | -import com.cnlive.libs.base.mvp.ReflectUtil; | |
| 10 | +import com.cnlive.libs.base.frame.presenter.BasePresenter; | |
| 11 | +import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; | |
| 12 | 12 | import com.hannesdorfmann.mosby3.mvp.MvpPresenter; |
| 13 | 13 | import com.hannesdorfmann.mosby3.mvp.MvpView; |
| 14 | 14 | |
| ... | ... | @@ -18,34 +18,27 @@ import com.hannesdorfmann.mosby3.mvp.MvpView; |
| 18 | 18 | * @param <V> MVP View {@link MvpView} |
| 19 | 19 | * @param <P> MVP Presenter {@link MvpPresenter} |
| 20 | 20 | */ |
| 21 | -public abstract class MyFragment<V extends MvpView, P extends MvpPresenter<V>> extends com.hannesdorfmann.mosby3.mvp.MvpFragment<V, P> { | |
| 21 | +public abstract class BaseFragment<V extends MvpView, P extends MvpBasePresenter<V>> extends com.hannesdorfmann.mosby3.mvp.MvpFragment<V, P> { | |
| 22 | 22 | |
| 23 | - public V view; | |
| 23 | + public View view; | |
| 24 | 24 | |
| 25 | 25 | @Nullable |
| 26 | 26 | @Override |
| 27 | 27 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
| 28 | - return inflater.inflate(getLayoutId(), container, false); | |
| 28 | + return view = inflater.inflate(getLayoutId(), container, false); | |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - protected abstract int getLayoutId(); | |
| 32 | - | |
| 33 | - @NonNull | |
| 34 | - public V createView() { | |
| 35 | - return ReflectUtil.instance(0, this.getClass(), this); | |
| 36 | - } | |
| 37 | - | |
| 38 | - @NonNull | |
| 39 | 31 | @Override |
| 40 | - public P createPresenter() { | |
| 41 | - return ReflectUtil.instance(1, this); | |
| 32 | + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | |
| 33 | + super.onViewCreated(view, savedInstanceState); | |
| 34 | + getPresenter(); | |
| 42 | 35 | } |
| 43 | 36 | |
| 44 | - @NonNull | |
| 45 | - @Override | |
| 46 | - public V getMvpView() { | |
| 47 | - if (view == null) view = createView(); | |
| 48 | - return view; | |
| 49 | - } | |
| 37 | +// @Override | |
| 38 | +// public P createPresenter() { | |
| 39 | +// return (P) new BasePresenter(); | |
| 40 | +// } | |
| 41 | + | |
| 42 | + protected abstract int getLayoutId(); | |
| 50 | 43 | |
| 51 | 44 | } |
| 52 | 45 | \ No newline at end of file | ... | ... |
core/base/src/main/java/com/cnlive/libs/base/frame/fragment/MvpBindingFragment.java deleted
100644 → 0
| 1 | -package com.cnlive.libs.base.frame.fragment; | |
| 2 | - | |
| 3 | -import android.os.Bundle; | |
| 4 | -import android.view.LayoutInflater; | |
| 5 | -import android.view.View; | |
| 6 | -import android.view.ViewGroup; | |
| 7 | - | |
| 8 | -import androidx.annotation.NonNull; | |
| 9 | -import androidx.annotation.Nullable; | |
| 10 | -import androidx.databinding.DataBindingUtil; | |
| 11 | -import androidx.databinding.ViewDataBinding; | |
| 12 | - | |
| 13 | -import com.cnlive.libs.base.mvp.ReflectUtil; | |
| 14 | -import com.hannesdorfmann.mosby3.mvp.MvpPresenter; | |
| 15 | -import com.hannesdorfmann.mosby3.mvp.MvpView; | |
| 16 | - | |
| 17 | -/** | |
| 18 | - * MVP Databinding Base Fragment | |
| 19 | - * | |
| 20 | - * @param <V> MVP View {@link MvpView} | |
| 21 | - * @param <P> MVP Presenter {@link MvpPresenter} | |
| 22 | - * @param <D> Databind Page Data | |
| 23 | - * @param <T> Databind Activity ViewDataBinding {@link ViewDataBinding} | |
| 24 | - */ | |
| 25 | -public abstract class MvpBindingFragment<V extends MvpView, P extends MvpPresenter<V>, D, T extends ViewDataBinding> extends MyFragment<V, P> { | |
| 26 | - | |
| 27 | - public T binding; | |
| 28 | - public D data; | |
| 29 | - | |
| 30 | - @Nullable | |
| 31 | - @Override | |
| 32 | - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |
| 33 | - binding = DataBindingUtil.inflate(inflater, getLayoutId(), container, false); | |
| 34 | - ReflectUtil.invoke(binding, "setData", getViewData()); | |
| 35 | - return binding.getRoot(); | |
| 36 | - } | |
| 37 | - | |
| 38 | - protected D initLayoutData() { | |
| 39 | - return ReflectUtil.instance(2, this); | |
| 40 | - } | |
| 41 | - | |
| 42 | - @NonNull | |
| 43 | - public D getViewData() { | |
| 44 | - if (data == null) data = initLayoutData(); | |
| 45 | - return data; | |
| 46 | - } | |
| 47 | -} | |
| 48 | 0 | \ No newline at end of file |
core/base/src/main/java/com/cnlive/libs/base/frame/presenter/BasePresenter.java
0 → 100644
core/base/src/main/java/com/cnlive/libs/base/frame/view/MvpBaseView.java renamed to core/base/src/main/java/com/cnlive/libs/base/frame/view/BaseView.java
core/base/src/main/java/com/cnlive/libs/base/mvp/BaseActivity.java deleted
100644 → 0
| 1 | -package com.cnlive.libs.base.mvp; | |
| 2 | - | |
| 3 | - | |
| 4 | -import android.annotation.SuppressLint; | |
| 5 | -import android.content.Context; | |
| 6 | -import android.content.pm.ActivityInfo; | |
| 7 | -import android.database.DatabaseUtils; | |
| 8 | -import android.os.Bundle; | |
| 9 | -import android.os.Looper; | |
| 10 | -import android.view.View; | |
| 11 | -import android.view.Window; | |
| 12 | -import android.view.WindowManager; | |
| 13 | -import android.view.inputmethod.InputMethodManager; | |
| 14 | -import android.widget.Toast; | |
| 15 | - | |
| 16 | -import androidx.annotation.Nullable; | |
| 17 | -import androidx.appcompat.app.AppCompatActivity; | |
| 18 | -import androidx.databinding.DataBindingUtil; | |
| 19 | -import androidx.databinding.ViewDataBinding; | |
| 20 | - | |
| 21 | -import com.cnlive.libs.base.util.lib_permisshelper.PermissionsUtils; | |
| 22 | -import com.cnlive.libs.base.util.ActivityCollector; | |
| 23 | - | |
| 24 | -/** | |
| 25 | - * @author ys | |
| 26 | - */ | |
| 27 | -public abstract class BaseActivity extends AppCompatActivity { | |
| 28 | - //获取TAG的activity名称 | |
| 29 | - protected final String TAG = this.getClass().getSimpleName(); | |
| 30 | - //是否显示标题栏 | |
| 31 | - private boolean isShowTitle = true; | |
| 32 | - //是否显示状态栏 | |
| 33 | - private boolean isShowStatusBar = true; | |
| 34 | - //是否允许旋转屏幕 | |
| 35 | - private boolean isAllowScreenRoate = true; | |
| 36 | - //封装Toast对象 | |
| 37 | - private static Toast toast; | |
| 38 | - public Context context; | |
| 39 | - private PermissionsUtils mPermissionsUtils;//权限申请 | |
| 40 | - private int stateBarColor = -1; | |
| 41 | - public ViewDataBinding binding; | |
| 42 | - | |
| 43 | - @Override | |
| 44 | - protected void onCreate(@Nullable Bundle savedInstanceState) { | |
| 45 | - super.onCreate(savedInstanceState); | |
| 46 | - context = this; | |
| 47 | - //activity管理 | |
| 48 | - ActivityCollector.addActivity(this); | |
| 49 | - if (!isShowTitle) { | |
| 50 | - requestWindowFeature(Window.FEATURE_NO_TITLE); | |
| 51 | - } | |
| 52 | - | |
| 53 | - if (!isShowStatusBar) { | |
| 54 | - getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | |
| 55 | - , WindowManager.LayoutParams.FLAG_FULLSCREEN); | |
| 56 | - } | |
| 57 | - //设置布局 | |
| 58 | - binding = DataBindingUtil.setContentView(this, initLayout()); | |
| 59 | - //设置屏幕是否可旋转 | |
| 60 | - if (!isAllowScreenRoate) { | |
| 61 | - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); | |
| 62 | - } else { | |
| 63 | - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); | |
| 64 | - } | |
| 65 | - mPermissionsUtils = new PermissionsUtils();//权限申请 | |
| 66 | - //初始化控件 | |
| 67 | - initView(); | |
| 68 | - //设置数据 | |
| 69 | - initData(); | |
| 70 | - } | |
| 71 | - | |
| 72 | - /** | |
| 73 | - * 初始化布局 | |
| 74 | - * | |
| 75 | - * @return 布局id | |
| 76 | - */ | |
| 77 | - protected abstract int initLayout(); | |
| 78 | - | |
| 79 | - /** | |
| 80 | - * 初始化控件 | |
| 81 | - */ | |
| 82 | - protected abstract void initView(); | |
| 83 | - | |
| 84 | - /** | |
| 85 | - * 设置数据 | |
| 86 | - */ | |
| 87 | - protected abstract void initData(); | |
| 88 | - | |
| 89 | - /** | |
| 90 | - * 设置是否显示标题栏 | |
| 91 | - * | |
| 92 | - * @param showTitle true or false | |
| 93 | - */ | |
| 94 | - public void setShowTitle(boolean showTitle) { | |
| 95 | - isShowTitle = showTitle; | |
| 96 | - } | |
| 97 | - | |
| 98 | - /** | |
| 99 | - * 设置是否显示状态栏 | |
| 100 | - * | |
| 101 | - * @param showStatusBar true or false | |
| 102 | - */ | |
| 103 | - public void setShowStatusBar(boolean showStatusBar) { | |
| 104 | - isShowStatusBar = showStatusBar; | |
| 105 | - } | |
| 106 | - | |
| 107 | - /** | |
| 108 | - * 是否允许屏幕旋转 | |
| 109 | - * | |
| 110 | - * @param allowScreenRoate true or false | |
| 111 | - */ | |
| 112 | - public void setAllowScreenRoate(boolean allowScreenRoate) { | |
| 113 | - isAllowScreenRoate = allowScreenRoate; | |
| 114 | - } | |
| 115 | - | |
| 116 | - /** | |
| 117 | - * 保证同一按钮在1秒内只会响应一次点击事件 | |
| 118 | - */ | |
| 119 | - public abstract class OnSingleClickListener implements View.OnClickListener { | |
| 120 | - //两次点击按钮之间的间隔,目前为1000ms | |
| 121 | - private static final int MIN_CLICK_DELAY_TIME = 1000; | |
| 122 | - private long lastClickTime; | |
| 123 | - | |
| 124 | - public abstract void onSingleClick(View view); | |
| 125 | - | |
| 126 | - @Override | |
| 127 | - public void onClick(View view) { | |
| 128 | - long curClickTime = System.currentTimeMillis(); | |
| 129 | - if ((curClickTime - lastClickTime) >= MIN_CLICK_DELAY_TIME) { | |
| 130 | - lastClickTime = curClickTime; | |
| 131 | - onSingleClick(view); | |
| 132 | - } | |
| 133 | - } | |
| 134 | - } | |
| 135 | - | |
| 136 | - /** | |
| 137 | - * 同一按钮在短时间内可重复响应点击事件 | |
| 138 | - */ | |
| 139 | - public abstract class OnMultiClickListener implements View.OnClickListener { | |
| 140 | - public abstract void onMultiClick(View view); | |
| 141 | - | |
| 142 | - @Override | |
| 143 | - public void onClick(View v) { | |
| 144 | - onMultiClick(v); | |
| 145 | - } | |
| 146 | - } | |
| 147 | - | |
| 148 | - /** | |
| 149 | - * 显示提示 toast | |
| 150 | - * | |
| 151 | - * @param msg 提示信息 | |
| 152 | - */ | |
| 153 | - @SuppressLint("ShowToast") | |
| 154 | - public void showToast(String msg) { | |
| 155 | - try { | |
| 156 | - if (null == toast) { | |
| 157 | - toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT); | |
| 158 | - } else { | |
| 159 | - toast.setText(msg); | |
| 160 | - } | |
| 161 | - runOnUiThread(new Runnable() { | |
| 162 | - @Override | |
| 163 | - public void run() { | |
| 164 | - toast.show(); | |
| 165 | - } | |
| 166 | - }); | |
| 167 | - } catch (Exception e) { | |
| 168 | - e.printStackTrace(); | |
| 169 | - //解决在子线程中调用Toast的异常情况处理 | |
| 170 | - Looper.prepare(); | |
| 171 | - Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); | |
| 172 | - Looper.loop(); | |
| 173 | - } | |
| 174 | - } | |
| 175 | - | |
| 176 | - | |
| 177 | - /** | |
| 178 | - * 隐藏软键盘 | |
| 179 | - */ | |
| 180 | - public void hideSoftInput() { | |
| 181 | - InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); | |
| 182 | - if (getCurrentFocus() != null && null != imm) { | |
| 183 | - imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); | |
| 184 | - } | |
| 185 | - } | |
| 186 | - | |
| 187 | - /** | |
| 188 | - * 显示软键盘 | |
| 189 | - */ | |
| 190 | - public void showSoftInput() { | |
| 191 | - InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); | |
| 192 | - if (getCurrentFocus() != null && null != imm) { | |
| 193 | - imm.showSoftInputFromInputMethod(getCurrentFocus().getWindowToken(), 0); | |
| 194 | - } | |
| 195 | - } | |
| 196 | - | |
| 197 | - /** | |
| 198 | - * 显示软键盘 | |
| 199 | - */ | |
| 200 | - public void showSoftInput(View view) { | |
| 201 | - // InputMethodManager.SHOW_FORCED); | |
| 202 | - InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); | |
| 203 | - imm.showSoftInput(view, InputMethodManager.SHOW_FORCED); | |
| 204 | - } | |
| 205 | - | |
| 206 | - @Override | |
| 207 | - protected void onDestroy() { | |
| 208 | - super.onDestroy(); | |
| 209 | - //activity管理 | |
| 210 | - ActivityCollector.removeActivity(this); | |
| 211 | - } | |
| 212 | -} | |
| 213 | 0 | \ No newline at end of file |
core/base/src/main/java/com/cnlive/libs/base/mvp/BaseFragment.java deleted
100644 → 0
| 1 | -package com.cnlive.libs.base.mvp; | |
| 2 | - | |
| 3 | -import android.os.Bundle; | |
| 4 | -import android.view.LayoutInflater; | |
| 5 | -import android.view.View; | |
| 6 | -import android.view.ViewGroup; | |
| 7 | - | |
| 8 | -import androidx.annotation.NonNull; | |
| 9 | -import androidx.annotation.Nullable; | |
| 10 | -import androidx.databinding.DataBindingUtil; | |
| 11 | -import androidx.databinding.ViewDataBinding; | |
| 12 | -/** | |
| 13 | - * @author ys | |
| 14 | - */ | |
| 15 | -public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V>> extends com.hannesdorfmann.mosby3.mvp.MvpFragment<V, P> { | |
| 16 | - public V v; | |
| 17 | - public P p; | |
| 18 | - public ViewDataBinding binding; | |
| 19 | - protected final String TAG = this.getClass().getSimpleName(); | |
| 20 | - | |
| 21 | - @Nullable | |
| 22 | - @Override | |
| 23 | - public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |
| 24 | - binding = DataBindingUtil.inflate(inflater, initLayout(), container, false); | |
| 25 | - return binding.getRoot(); | |
| 26 | - } | |
| 27 | - | |
| 28 | - @Override | |
| 29 | - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | |
| 30 | - super.onViewCreated(view, savedInstanceState); | |
| 31 | - if (null != getMvpView()&&null!=getPresenter()) { | |
| 32 | - init(); | |
| 33 | - } | |
| 34 | - } | |
| 35 | - | |
| 36 | - @Override | |
| 37 | - public P createPresenter() { | |
| 38 | - if (p == null) { | |
| 39 | - return ReflectUtil.instance(BasePresenter.class); | |
| 40 | - } else { | |
| 41 | - return ReflectUtil.instance(1, this); | |
| 42 | - } | |
| 43 | - } | |
| 44 | - | |
| 45 | - /** | |
| 46 | - * 初始化布局 | |
| 47 | - * | |
| 48 | - * @return 布局id | |
| 49 | - */ | |
| 50 | - protected abstract int initLayout(); | |
| 51 | - | |
| 52 | - protected abstract void init(); | |
| 53 | - | |
| 54 | -} |
core/base/src/main/java/com/cnlive/libs/base/mvp/BasePresenter.java deleted
100644 → 0
core/base/src/main/java/com/cnlive/libs/base/mvp/BaseView.java deleted
100644 → 0
| 1 | -package com.cnlive.libs.base.mvp; | |
| 2 | - | |
| 3 | -import android.app.Activity; | |
| 4 | - | |
| 5 | -import androidx.databinding.ViewDataBinding; | |
| 6 | - | |
| 7 | -import com.hannesdorfmann.mosby3.mvp.MvpView; | |
| 8 | -/** | |
| 9 | - * @author ys | |
| 10 | - */ | |
| 11 | -public abstract class BaseView implements MvpView { | |
| 12 | - private BaseFragment fragment; | |
| 13 | - protected ViewDataBinding binding; | |
| 14 | - | |
| 15 | - public BaseView(BaseFragment fragment) { | |
| 16 | - this.fragment = fragment; | |
| 17 | - this.binding = fragment.binding; | |
| 18 | - } | |
| 19 | - | |
| 20 | - public Activity getContext() { | |
| 21 | - return fragment == null ? null : fragment.getActivity(); | |
| 22 | - } | |
| 23 | - | |
| 24 | - protected abstract void initView(); | |
| 25 | - | |
| 26 | - protected abstract void initData(); | |
| 27 | - | |
| 28 | -} |