void postStickMessage(final T bean) {
50 | EventBus.getDefault().postSticky(bean);
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/java/com/yzs/yzsbaseactivitylib/util/SizeUtils.java:
--------------------------------------------------------------------------------
1 | package com.yzs.yzsbaseactivitylib.util;
2 |
3 | import android.util.DisplayMetrics;
4 | import android.util.TypedValue;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | /**
9 | *
10 | * author: Blankj
11 | * blog : http://blankj.com
12 | * time : 2016/08/02
13 | * desc : 尺寸相关工具类
14 | *
15 | */
16 | public final class SizeUtils {
17 |
18 | private SizeUtils() {
19 | throw new UnsupportedOperationException("u can't instantiate me...");
20 | }
21 |
22 | /**
23 | * dp转px
24 | *
25 | * @param dpValue dp值
26 | * @return px值
27 | */
28 | public static int dp2px(final float dpValue) {
29 | final float scale = Utils.getContext().getResources().getDisplayMetrics().density;
30 | return (int) (dpValue * scale + 0.5f);
31 | }
32 |
33 | /**
34 | * px转dp
35 | *
36 | * @param pxValue px值
37 | * @return dp值
38 | */
39 | public static int px2dp(final float pxValue) {
40 | final float scale = Utils.getContext().getResources().getDisplayMetrics().density;
41 | return (int) (pxValue / scale + 0.5f);
42 | }
43 |
44 | /**
45 | * sp转px
46 | *
47 | * @param spValue sp值
48 | * @return px值
49 | */
50 | public static int sp2px(final float spValue) {
51 | final float fontScale = Utils.getContext().getResources().getDisplayMetrics().scaledDensity;
52 | return (int) (spValue * fontScale + 0.5f);
53 | }
54 |
55 | /**
56 | * px转sp
57 | *
58 | * @param pxValue px值
59 | * @return sp值
60 | */
61 | public static int px2sp(final float pxValue) {
62 | final float fontScale = Utils.getContext().getResources().getDisplayMetrics().scaledDensity;
63 | return (int) (pxValue / fontScale + 0.5f);
64 | }
65 |
66 | /**
67 | * 各种单位转换
68 | * 该方法存在于TypedValue
69 | *
70 | * @param unit 单位
71 | * @param value 值
72 | * @param metrics DisplayMetrics
73 | * @return 转换结果
74 | */
75 | public static float applyDimension(final int unit, final float value, final DisplayMetrics metrics) {
76 | switch (unit) {
77 | case TypedValue.COMPLEX_UNIT_PX:
78 | return value;
79 | case TypedValue.COMPLEX_UNIT_DIP:
80 | return value * metrics.density;
81 | case TypedValue.COMPLEX_UNIT_SP:
82 | return value * metrics.scaledDensity;
83 | case TypedValue.COMPLEX_UNIT_PT:
84 | return value * metrics.xdpi * (1.0f / 72);
85 | case TypedValue.COMPLEX_UNIT_IN:
86 | return value * metrics.xdpi;
87 | case TypedValue.COMPLEX_UNIT_MM:
88 | return value * metrics.xdpi * (1.0f / 25.4f);
89 | }
90 | return 0;
91 | }
92 |
93 | /**
94 | * 在onCreate中获取视图的尺寸
95 | * 需回调onGetSizeListener接口,在onGetSize中获取view宽高
96 | * 用法示例如下所示
97 | *
98 | * SizeUtils.forceGetViewSize(view, new SizeUtils.onGetSizeListener() {
99 | * Override
100 | * public void onGetSize(final View view) {
101 | * view.getWidth();
102 | * }
103 | * });
104 | *
105 | *
106 | * @param view 视图
107 | * @param listener 监听器
108 | */
109 | public static void forceGetViewSize(final View view, final onGetSizeListener listener) {
110 | view.post(new Runnable() {
111 | @Override
112 | public void run() {
113 | if (listener != null) {
114 | listener.onGetSize(view);
115 | }
116 | }
117 | });
118 | }
119 |
120 | /**
121 | * 获取到View尺寸的监听
122 | */
123 | public interface onGetSizeListener {
124 | void onGetSize(View view);
125 | }
126 |
127 | /**
128 | * 测量视图尺寸
129 | *
130 | * @param view 视图
131 | * @return arr[0]: 视图宽度, arr[1]: 视图高度
132 | */
133 | public static int[] measureView(final View view) {
134 | ViewGroup.LayoutParams lp = view.getLayoutParams();
135 | if (lp == null) {
136 | lp = new ViewGroup.LayoutParams(
137 | ViewGroup.LayoutParams.MATCH_PARENT,
138 | ViewGroup.LayoutParams.WRAP_CONTENT
139 | );
140 | }
141 | int widthSpec = ViewGroup.getChildMeasureSpec(0, 0, lp.width);
142 | int lpHeight = lp.height;
143 | int heightSpec;
144 | if (lpHeight > 0) {
145 | heightSpec = View.MeasureSpec.makeMeasureSpec(lpHeight, View.MeasureSpec.EXACTLY);
146 | } else {
147 | heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
148 | }
149 | view.measure(widthSpec, heightSpec);
150 | return new int[]{view.getMeasuredWidth(), view.getMeasuredHeight()};
151 | }
152 |
153 | /**
154 | * 获取测量视图宽度
155 | *
156 | * @param view 视图
157 | * @return 视图宽度
158 | */
159 | public static int getMeasuredWidth(final View view) {
160 | return measureView(view)[0];
161 | }
162 |
163 | /**
164 | * 获取测量视图高度
165 | *
166 | * @param view 视图
167 | * @return 视图高度
168 | */
169 | public static int getMeasuredHeight(final View view) {
170 | return measureView(view)[1];
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/java/com/yzs/yzsbaseactivitylib/util/StringUtils.java:
--------------------------------------------------------------------------------
1 | package com.yzs.yzsbaseactivitylib.util;
2 |
3 | /**
4 | *
5 | * author: Blankj
6 | * blog : http://blankj.com
7 | * time : 2016/8/16
8 | * desc : 字符串相关工具类
9 | *
10 | */
11 | public class StringUtils {
12 |
13 | private StringUtils() {
14 | throw new UnsupportedOperationException("u can't instantiate me...");
15 | }
16 |
17 | /**
18 | * 判断字符串是否为null或长度为0
19 | *
20 | * @param s 待校验字符串
21 | * @return {@code true}: 空
{@code false}: 不为空
22 | */
23 | public static boolean isEmpty(CharSequence s) {
24 | return s == null || s.length() == 0;
25 | }
26 |
27 | /**
28 | * 判断字符串是否为null或全为空格
29 | *
30 | * @param s 待校验字符串
31 | * @return {@code true}: null或全空格
{@code false}: 不为null且不全空格
32 | */
33 | public static boolean isSpace(String s) {
34 | return (s == null || s.trim().length() == 0);
35 | }
36 |
37 | /**
38 | * 判断两字符串是否相等
39 | *
40 | * @param a 待校验字符串a
41 | * @param b 待校验字符串b
42 | * @return {@code true}: 相等
{@code false}: 不相等
43 | */
44 | public static boolean equals(CharSequence a, CharSequence b) {
45 | if (a == b) return true;
46 | int length;
47 | if (a != null && b != null && (length = a.length()) == b.length()) {
48 | if (a instanceof String && b instanceof String) {
49 | return a.equals(b);
50 | } else {
51 | for (int i = 0; i < length; i++) {
52 | if (a.charAt(i) != b.charAt(i)) return false;
53 | }
54 | return true;
55 | }
56 | }
57 | return false;
58 | }
59 |
60 | /**
61 | * 判断两字符串忽略大小写是否相等
62 | *
63 | * @param a 待校验字符串a
64 | * @param b 待校验字符串b
65 | * @return {@code true}: 相等
{@code false}: 不相等
66 | */
67 | public static boolean equalsIgnoreCase(String a, String b) {
68 | return (a == b) || (b != null) && (a.length() == b.length()) && a.regionMatches(true, 0, b, 0, b.length());
69 | }
70 |
71 | /**
72 | * null转为长度为0的字符串
73 | *
74 | * @param s 待转字符串
75 | * @return s为null转为长度为0字符串,否则不改变
76 | */
77 | public static String null2Length0(String s) {
78 | return s == null ? "" : s;
79 | }
80 |
81 | /**
82 | * 返回字符串长度
83 | *
84 | * @param s 字符串
85 | * @return null返回0,其他返回自身长度
86 | */
87 | public static int length(CharSequence s) {
88 | return s == null ? 0 : s.length();
89 | }
90 |
91 | /**
92 | * 首字母大写
93 | *
94 | * @param s 待转字符串
95 | * @return 首字母大写字符串
96 | */
97 | public static String upperFirstLetter(String s) {
98 | if (isEmpty(s) || !Character.isLowerCase(s.charAt(0))) return s;
99 | return String.valueOf((char) (s.charAt(0) - 32)) + s.substring(1);
100 | }
101 |
102 | /**
103 | * 首字母小写
104 | *
105 | * @param s 待转字符串
106 | * @return 首字母小写字符串
107 | */
108 | public static String lowerFirstLetter(String s) {
109 | if (isEmpty(s) || !Character.isUpperCase(s.charAt(0))) {
110 | return s;
111 | }
112 | return String.valueOf((char) (s.charAt(0) + 32)) + s.substring(1);
113 | }
114 |
115 | /**
116 | * 反转字符串
117 | *
118 | * @param s 待反转字符串
119 | * @return 反转字符串
120 | */
121 | public static String reverse(String s) {
122 | int len = length(s);
123 | if (len <= 1) return s;
124 | int mid = len >> 1;
125 | char[] chars = s.toCharArray();
126 | char c;
127 | for (int i = 0; i < mid; ++i) {
128 | c = chars[i];
129 | chars[i] = chars[len - i - 1];
130 | chars[len - i - 1] = c;
131 | }
132 | return new String(chars);
133 | }
134 |
135 | /**
136 | * 转化为半角字符
137 | *
138 | * @param s 待转字符串
139 | * @return 半角字符串
140 | */
141 | public static String toDBC(String s) {
142 | if (isEmpty(s)) {
143 | return s;
144 | }
145 | char[] chars = s.toCharArray();
146 | for (int i = 0, len = chars.length; i < len; i++) {
147 | if (chars[i] == 12288) {
148 | chars[i] = ' ';
149 | } else if (65281 <= chars[i] && chars[i] <= 65374) {
150 | chars[i] = (char) (chars[i] - 65248);
151 | } else {
152 | chars[i] = chars[i];
153 | }
154 | }
155 | return new String(chars);
156 | }
157 |
158 | /**
159 | * 转化为全角字符
160 | *
161 | * @param s 待转字符串
162 | * @return 全角字符串
163 | */
164 | public static String toSBC(String s) {
165 | if (isEmpty(s)) {
166 | return s;
167 | }
168 | char[] chars = s.toCharArray();
169 | for (int i = 0, len = chars.length; i < len; i++) {
170 | if (chars[i] == ' ') {
171 | chars[i] = (char) 12288;
172 | } else if (33 <= chars[i] && chars[i] <= 126) {
173 | chars[i] = (char) (chars[i] + 65248);
174 | } else {
175 | chars[i] = chars[i];
176 | }
177 | }
178 | return new String(chars);
179 | }
180 | }
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/java/com/yzs/yzsbaseactivitylib/util/TUtil.java:
--------------------------------------------------------------------------------
1 | package com.yzs.yzsbaseactivitylib.util;
2 |
3 | import java.lang.reflect.ParameterizedType;
4 |
5 | /**
6 | * 类转换初始化
7 | */
8 | public class TUtil {
9 | public static T getT(Object o, int i) {
10 | try {
11 | return ((Class) ((ParameterizedType) (o.getClass()
12 | .getGenericSuperclass())).getActualTypeArguments()[i])
13 | .newInstance();
14 | } catch (InstantiationException e) {
15 | e.printStackTrace();
16 | } catch (IllegalAccessException e) {
17 | e.printStackTrace();
18 | } catch (ClassCastException e) {
19 | e.printStackTrace();
20 | }
21 | return null;
22 | }
23 |
24 | public static Class> forName(String className) {
25 | try {
26 | return Class.forName(className);
27 | } catch (ClassNotFoundException e) {
28 | e.printStackTrace();
29 | }
30 | return null;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/java/com/yzs/yzsbaseactivitylib/util/Utils.java:
--------------------------------------------------------------------------------
1 | package com.yzs.yzsbaseactivitylib.util;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 |
6 | import androidx.annotation.NonNull;
7 |
8 | /**
9 | *
10 | * author: Blankj
11 | * blog : http://blankj.com
12 | * time : 16/12/08
13 | * desc : Utils初始化相关
14 | *
15 | */
16 | public final class Utils {
17 |
18 | @SuppressLint("StaticFieldLeak")
19 | private static Context context;
20 |
21 | private Utils() {
22 | throw new UnsupportedOperationException("u can't instantiate me...");
23 | }
24 |
25 | /**
26 | * 初始化工具类
27 | *
28 | * @param context 上下文
29 | */
30 | public static void init(@NonNull final Context context) {
31 | Utils.context = context.getApplicationContext();
32 | }
33 |
34 | /**
35 | * 获取ApplicationContext
36 | *
37 | * @return ApplicationContext
38 | */
39 | public static Context getContext() {
40 | if (context != null) return context;
41 | throw new NullPointerException("u should init first");
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/java/com/yzs/yzsbaseactivitylib/view/ColorFilterImageView.java:
--------------------------------------------------------------------------------
1 | package com.yzs.yzsbaseactivitylib.view;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.graphics.PorterDuff.Mode;
6 | import android.util.AttributeSet;
7 | import android.view.MotionEvent;
8 | import android.view.View;
9 | import android.view.View.OnTouchListener;
10 |
11 | import androidx.appcompat.widget.AppCompatImageView;
12 |
13 |
14 | /**
15 | *
16 | * @ClassName: ColorFilterImageView
17 | * @Description: 实现图像根据按下抬起动作变化颜色
18 | * @author huym
19 | *
20 | *
21 | */
22 | public class ColorFilterImageView extends AppCompatImageView implements OnTouchListener {
23 | public ColorFilterImageView(Context context) {
24 | this(context, null, 0);
25 | }
26 |
27 | public ColorFilterImageView(Context context, AttributeSet attrs) {
28 | this(context, attrs, 0);
29 | }
30 |
31 | public ColorFilterImageView(Context context, AttributeSet attrs, int defStyle) {
32 | super(context, attrs, defStyle);
33 | init();
34 | }
35 |
36 | private void init() {
37 | setOnTouchListener(this);
38 | }
39 |
40 | @Override
41 | public boolean onTouch(View v, MotionEvent event) {
42 | switch (event.getAction()) {
43 | case MotionEvent.ACTION_DOWN: // 按下时图像变灰
44 | setColorFilter(Color.LTGRAY, Mode.MULTIPLY);
45 | break;
46 | case MotionEvent.ACTION_UP: // 手指离开或取消操作时恢复原色
47 | case MotionEvent.ACTION_CANCEL:
48 | setColorFilter(Color.TRANSPARENT);
49 | break;
50 | default:
51 | break;
52 | }
53 | return false;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/java/com/yzs/yzsbaseactivitylib/view/RecyclerViewLoaderMoreView.java:
--------------------------------------------------------------------------------
1 | package com.yzs.yzsbaseactivitylib.view;
2 |
3 | import com.chad.library.adapter.base.loadmore.LoadMoreView;
4 | import com.yzs.yzsbaseactivitylib.R;
5 |
6 | /**
7 | * Author: 姚智胜
8 | * Version: V1.0版本
9 | * Description: 默认recyclerview加载各种状态布局
10 | * Date: 2017/6/16
11 | * Email: 541567595@qq.com
12 | */
13 |
14 | public class RecyclerViewLoaderMoreView extends LoadMoreView {
15 | @Override
16 | public int getLayoutId() {
17 | return R.layout.quick_view_load_more;
18 | }
19 |
20 | @Override
21 | protected int getLoadingViewId() {
22 | return R.id.load_more_loading_view;
23 | }
24 |
25 | @Override
26 | protected int getLoadFailViewId() {
27 | return R.id.load_more_load_fail_view;
28 | }
29 |
30 | @Override
31 | protected int getLoadEndViewId() {
32 | return R.id.load_more_load_end_view;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/java/com/yzs/yzsbaseactivitylib/yzsbase/YzsBaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.yzs.yzsbaseactivitylib.yzsbase;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewStub;
8 | import android.widget.FrameLayout;
9 |
10 | import androidx.annotation.LayoutRes;
11 | import androidx.annotation.Nullable;
12 | import androidx.appcompat.widget.Toolbar;
13 |
14 | import com.yzs.yzsbaseactivitylib.R;
15 | import com.yzs.yzsbaseactivitylib.basemvp.BaseModel;
16 | import com.yzs.yzsbaseactivitylib.basemvp.BasePresenter;
17 | import com.yzs.yzsbaseactivitylib.util.AppManager;
18 | import com.yzs.yzsbaseactivitylib.util.TUtil;
19 |
20 | import me.yokeyword.fragmentation.SupportActivity;
21 |
22 | /**
23 | * Author: 姚智胜
24 | * Version: V1.0版本
25 | * Description:
26 | * Date: 2018/1/10
27 | * Email: 541567595@qq.com
28 | */
29 |
30 | public abstract class YzsBaseActivity extends SupportActivity {
31 |
32 | /**
33 | * 在使用自定义toolbar时候的根布局 =toolBarView+childView
34 | */
35 | protected View rootView;
36 | public T mPresenter;
37 | public E mModel;
38 | public Context mContext;
39 | public Toolbar mToolbar;
40 |
41 | @Override
42 | protected void onCreate(@Nullable Bundle savedInstanceState) {
43 | super.onCreate(savedInstanceState);
44 | AppManager.getAppManager().addActivity(this);
45 | Bundle extras = getIntent().getExtras();
46 | if (null != getIntent().getExtras()) {
47 | getBundleExtras(extras);
48 | }
49 | setContentView(getContentViewResId());
50 |
51 | initImmersion();
52 | if (showToolBar()) {
53 | mToolbar = (Toolbar) findViewById(R.id.toolbar);
54 | if (null != mToolbar) {
55 | setSupportActionBar(mToolbar);
56 | getSupportActionBar().setDisplayShowTitleEnabled(false);
57 | // initTitle();
58 | }
59 | }
60 |
61 |
62 | mContext = this;
63 | mPresenter = TUtil.getT(this, 0);
64 | mModel = TUtil.getT(this, 1);
65 | if (mPresenter != null) {
66 | mPresenter.mContext = this;
67 | }
68 | this.initPresenter();
69 | this.initView();
70 |
71 | }
72 |
73 | @Override
74 | public void setContentView(@LayoutRes int layoutResID) {
75 | if (layoutResID == 0) {
76 | throw new RuntimeException("layoutResID==-1 have u create your layout?");
77 | }
78 |
79 | if (showToolBar() && getToolBarResId() != -1) {
80 | //如果需要显示自定义toolbar,并且资源id存在的情况下,实例化baseView;
81 | rootView = LayoutInflater.from(this).inflate(toolbarCover() ?
82 | R.layout.ac_base_toolbar_cover : R.layout.ac_base, null, false);//根布局
83 | ViewStub mVs_toolbar = (ViewStub) rootView.findViewById(R.id.vs_toolbar);//toolbar容器
84 | FrameLayout fl_container = (FrameLayout) rootView.findViewById(R.id.fl_container);//子布局容器
85 | mVs_toolbar.setLayoutResource(getToolBarResId());//toolbar资源id
86 | mVs_toolbar.inflate();//填充toolbar
87 | LayoutInflater.from(this).inflate(layoutResID, fl_container, true);//子布局
88 | setContentView(rootView);
89 | } else {
90 | //不显示通用toolbar
91 | super.setContentView(layoutResID);
92 |
93 | }
94 | }
95 |
96 | /**
97 | * 初始化沉浸式
98 | */
99 | public void initImmersion() {
100 | }
101 |
102 | ;
103 |
104 | /**
105 | * 获取contentView 资源id
106 | */
107 | public abstract int getContentViewResId();
108 |
109 | /**
110 | * 是否显示通用toolBar
111 | */
112 | public boolean showToolBar() {
113 | return false;
114 | }
115 |
116 | //获取自定义toolbarview 资源id 默认为-1,showToolBar()方法必须返回true才有效
117 | public int getToolBarResId() {
118 | return R.layout.layout_common_toolbar;
119 | }
120 |
121 | /**
122 | * Bundle 传递数据
123 | *
124 | * @param extras
125 | */
126 | protected void getBundleExtras(Bundle extras) {
127 | }
128 |
129 | ;
130 |
131 | @Override
132 | protected void onDestroy() {
133 | super.onDestroy();
134 | rootView = null;
135 |
136 | AppManager.getAppManager().finishActivity(this);
137 | }
138 |
139 | /**
140 | * toolbar是否覆盖在内容区上方
141 | *
142 | * @return false 不覆盖 true 覆盖
143 | */
144 | protected boolean toolbarCover() {
145 | return false;
146 | }
147 |
148 | /**
149 | * 简单页面无需mvp就不用管此方法即可,完美兼容各种实际场景的变通
150 | */
151 | public void initPresenter() {
152 | }
153 |
154 | ;
155 |
156 | /**
157 | * 初始化view
158 | */
159 | public abstract void initView();
160 |
161 |
162 | }
163 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/java/com/yzs/yzsbaseactivitylib/yzsbase/YzsBaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.yzs.yzsbaseactivitylib.yzsbase;
2 |
3 | import android.os.Bundle;
4 | import android.text.TextUtils;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.view.ViewStub;
9 | import android.view.inputmethod.InputMethodManager;
10 | import android.widget.FrameLayout;
11 | import android.widget.ImageView;
12 | import android.widget.LinearLayout;
13 | import android.widget.TextView;
14 |
15 | import androidx.annotation.DrawableRes;
16 | import androidx.annotation.Nullable;
17 | import androidx.appcompat.widget.Toolbar;
18 |
19 | import com.gyf.barlibrary.ImmersionBar;
20 | import com.yzs.yzsbaseactivitylib.R;
21 | import com.yzs.yzsbaseactivitylib.basemvp.BaseModel;
22 | import com.yzs.yzsbaseactivitylib.basemvp.BasePresenter;
23 | import com.yzs.yzsbaseactivitylib.util.TUtil;
24 |
25 | import me.yokeyword.fragmentation.SupportFragment;
26 |
27 | import static android.content.Context.INPUT_METHOD_SERVICE;
28 |
29 | /**
30 | * Author: 姚智胜
31 | * Version: V1.0版本
32 | * Description: 通用的basefragment
33 | * Date: 2018/1/9
34 | * Email: 541567595@qq.com
35 | */
36 |
37 | public abstract class YzsBaseFragment extends SupportFragment {
38 |
39 | protected ImmersionBar mImmersionBar;
40 | protected View rootView;//在使用自定义toolbar时候的根布局 =toolBarView+childView
41 | protected Toolbar toolbar;
42 | private TextView tv_title, tv_rightTitle;
43 | private ImageView iv_rightTitle;
44 | private LinearLayout ll_base_root;
45 | public T mPresenter;
46 | public E mModel;
47 | private boolean isMvp = false;
48 | protected View emptyView;
49 |
50 | public LinearLayout getLl_base_root() {
51 | return ll_base_root;
52 | }
53 |
54 | @Nullable
55 | @Override
56 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
57 |
58 | if (null != getArguments()) {
59 | getBundleExtras(getArguments());
60 | }
61 | if (rootView == null) {
62 | //为空时初始化。
63 | if (showToolBar() && getToolBarResId() != 0) {
64 | //如果需要显示自定义toolbar,并且资源id存在的情况下,实例化baseView;
65 | rootView = inflater.inflate(toolbarCover() ? R.layout.ac_base_toolbar_cover :
66 | R.layout.ac_base, container, false);//根布局
67 | ll_base_root = (LinearLayout) rootView.findViewById(R.id.ll_base_root);
68 | ViewStub mVs_toolbar = (ViewStub) rootView.findViewById(R.id.vs_toolbar);//toolbar容器
69 | FrameLayout fl_container = (FrameLayout) rootView.findViewById(R.id.fl_container);//子布局容器
70 | mVs_toolbar.setLayoutResource(getToolBarResId());//toolbar资源id
71 | mVs_toolbar.inflate();//填充toolbar
72 | inflater.inflate(getLayoutRes(), fl_container, true);//子布局
73 | } else {
74 | //不显示通用toolbar
75 | rootView = inflater.inflate(getLayoutRes(), container, false);
76 |
77 | }
78 | }
79 | initToolBar(rootView);
80 | initView(rootView);
81 | mvpCreate();
82 | return rootView;
83 | }
84 |
85 | /**
86 | * 初始化toolbar可重写覆盖自定的toolbar,base中实现的是通用的toolbar
87 | */
88 | public void initToolBar(View rootView) {
89 | toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
90 | if (toolbar == null) {
91 | return;
92 | }
93 | toolbar.setTitle("");
94 | tv_title = (TextView) toolbar.findViewById(R.id.toolbar_title);
95 | tv_rightTitle = (TextView) toolbar.findViewById(R.id.tv_toolbar_right);
96 | iv_rightTitle = (ImageView) toolbar.findViewById(R.id.iv_toolbar_right);
97 |
98 | }
99 |
100 |
101 | @Override
102 | public void onLazyInitView(@Nullable Bundle savedInstanceState) {
103 | super.onLazyInitView(savedInstanceState);
104 | initLogic();
105 | }
106 |
107 | @Override
108 | public void onSupportVisible() {
109 | super.onSupportVisible();
110 | if (immersionEnabled()) {
111 | mImmersionBar = ImmersionBar.with(this);
112 | immersionInit(mImmersionBar);
113 | }
114 | hideInput();
115 | }
116 |
117 | /**
118 | * 逻辑内容初始化,懒加载模式
119 | */
120 | protected abstract void initLogic();
121 |
122 | @Override
123 | public void onSupportInvisible() {
124 | super.onSupportInvisible();
125 | }
126 |
127 | /**
128 | * 关闭软键盘
129 | */
130 | public void hideInput() {
131 | if (getActivity().getCurrentFocus() == null) return;
132 | ((InputMethodManager) getActivity().getSystemService(INPUT_METHOD_SERVICE))
133 | .hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
134 | InputMethodManager.HIDE_NOT_ALWAYS);
135 | }
136 |
137 | @Override
138 | public void onDestroy() {
139 | super.onDestroy();
140 | if (mImmersionBar != null)
141 | mImmersionBar.destroy();
142 | }
143 |
144 | /**
145 | * 当前页面Fragment支持沉浸式初始化。默认返回false,可设置支持沉浸式初始化
146 | * Immersion bar enabled boolean.
147 | *
148 | * @return the boolean
149 | */
150 | protected boolean immersionEnabled() {
151 | return false;
152 | }
153 |
154 | /**
155 | * 状态栏初始化(immersionEnabled默认为false时不走该方法)
156 | */
157 | protected void immersionInit(ImmersionBar mImmersionBar) {
158 | }
159 |
160 | /**
161 | * 是否显示通用toolBar
162 | */
163 | public boolean showToolBar() {
164 | return false;
165 | }
166 |
167 | /**
168 | * 获取自定义toolbarview 资源id 默认为0,showToolBar()方法必须返回true才有效
169 | */
170 | public int getToolBarResId() {
171 | return R.layout.layout_common_toolbar;
172 | }
173 |
174 | /**
175 | * toolbar是否覆盖在内容区上方
176 | *
177 | * @return false 不覆盖 true 覆盖
178 | */
179 | protected boolean toolbarCover() {
180 | return false;
181 | }
182 |
183 |
184 | /**
185 | * 获取布局文件
186 | */
187 | protected abstract int getLayoutRes();
188 |
189 | /**
190 | * 初始化view
191 | */
192 | protected abstract void initView(View rootView);
193 |
194 | /**
195 | * 获取bundle信息
196 | *
197 | * @param bundle
198 | */
199 | protected void getBundleExtras(Bundle bundle) {
200 | }
201 |
202 | /**
203 | * 设置界面是否使用mvp模式(不用关注这个方法,这个方法是专门处理列表类界面的)
204 | *
205 | * @param mvp
206 | */
207 | public void setMvp(boolean mvp) {
208 | isMvp = mvp;
209 | }
210 |
211 | /**
212 | * mvp架构的初始化
213 | */
214 | public void mvpCreate() {
215 | if (isMvp) {
216 | mPresenter = TUtil.getT(this, 0);
217 | mModel = TUtil.getT(this, 1);
218 | }
219 |
220 | if (mPresenter != null) {
221 | mPresenter.mContext = this.getActivity();
222 | }
223 |
224 | initPresenter();
225 | }
226 |
227 | /**
228 | * 简单页面无需mvp就不用管此方法即可,完美兼容各种实际场景的变通
229 | */
230 | public void initPresenter() {
231 | }
232 |
233 | @Override
234 | public void onDestroyView() {
235 | super.onDestroyView();
236 | if (mPresenter != null) {
237 | mPresenter.onDestroy();
238 | }
239 | }
240 |
241 |
242 | public View getEmptyView(String str, @DrawableRes int drawRes) {
243 | if (emptyView != null) {
244 | return emptyView;
245 | }
246 | emptyView = LayoutInflater.from(_mActivity).inflate(R.layout.layout_empty_view, null, false);
247 | if (!TextUtils.isEmpty(str)) {
248 | TextView textView = (TextView) emptyView.findViewById(R.id.tv_text);
249 | ImageView imageView = (ImageView) emptyView.findViewById(R.id.iv_empty);
250 | imageView.setImageResource(drawRes);
251 | textView.setText(str);
252 | }
253 | return emptyView;
254 | }
255 |
256 | }
257 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/java/com/yzs/yzsbaseactivitylib/yzsbase/YzsBaseHomeFragment.java:
--------------------------------------------------------------------------------
1 | package com.yzs.yzsbaseactivitylib.yzsbase;
2 |
3 | import android.os.Bundle;
4 | import android.util.Log;
5 | import android.view.View;
6 | import android.widget.FrameLayout;
7 |
8 | import androidx.annotation.Nullable;
9 | import androidx.fragment.app.Fragment;
10 | import androidx.fragment.app.FragmentManager;
11 | import androidx.fragment.app.FragmentPagerAdapter;
12 | import androidx.viewpager.widget.ViewPager;
13 |
14 | import com.flyco.tablayout.CommonTabLayout;
15 | import com.flyco.tablayout.listener.CustomTabEntity;
16 | import com.flyco.tablayout.listener.OnTabSelectListener;
17 | import com.orhanobut.logger.Logger;
18 | import com.yzs.yzsbaseactivitylib.R;
19 | import com.yzs.yzsbaseactivitylib.basemvp.BaseModel;
20 | import com.yzs.yzsbaseactivitylib.basemvp.BasePresenter;
21 | import com.yzs.yzsbaseactivitylib.entity.TabEntity;
22 |
23 | import java.util.ArrayList;
24 |
25 | import me.yokeyword.fragmentation.SupportFragment;
26 |
27 | /**
28 | * Author: 姚智胜
29 | * Version: V1.0版本
30 | * Description: 首页的baseActivity类型 提供下方导航条用户只需放入图标与fragment,也支持固定title的导航条
31 | * Date: 2017/7/3
32 | * Email: 541567595@qq.com
33 | */
34 |
35 | public abstract class YzsBaseHomeFragment extends
36 | YzsBaseFragment {
37 |
38 | private static final String TAG = "BaseHomeFragment";
39 | private String[] mTitles;//title文字部分
40 | private int[] mIconUnSelectIds = new int[]{};//未选中图标数组
41 | private int[] mIconSelectIds = new int[]{};//选中图标数组
42 | protected YzsBaseFragment[] mFragments;//fragment集合
43 | protected CommonTabLayout mTabLayout;//导航条
44 | private ArrayList mTabEntities = new ArrayList<>();//图标信息对象
45 | protected ViewPager mViewPager;
46 | protected FrameLayout mFrameLayout;
47 | private Bundle bundle;
48 | private int initChooseTab;
49 | private boolean isFirst = true;//是不是程序默认选中
50 |
51 | /**
52 | * 如果使用viewpager,初始化选中必须用该方法
53 | *
54 | * @param initChooseTab 选中position
55 | */
56 | public void setInitChooseTab(int initChooseTab) {
57 | this.initChooseTab = initChooseTab;
58 | }
59 |
60 |
61 | @Override
62 | public void onCreate(@Nullable Bundle savedInstanceState) {
63 | super.onCreate(savedInstanceState);
64 | setBundle(savedInstanceState);
65 | }
66 |
67 |
68 | @Override
69 | protected void initView(View view) {
70 | mTabLayout = (CommonTabLayout) view.findViewById(R.id.yzs_base_tabLayout);
71 | mViewPager = (ViewPager) view.findViewById(R.id.yzs_base_tabLayout_viewPager);
72 | mFrameLayout = (FrameLayout) view.findViewById(R.id.yzs_base_tabLayout_frameLayout);
73 | initTab();
74 | if (null == mFragments || mFragments.length == 0) {
75 | throw new RuntimeException("mFragments is null!");
76 | }
77 | initTabEntities();
78 | if (null == mTabLayout) {
79 | throw new RuntimeException("CommonTabLayout is null!");
80 | }
81 | if (null == mTitles || mTitles.length == 0) {
82 | mTabLayout.setTextsize(0);
83 | }
84 | if (null != mViewPager) {
85 | Log.e(TAG, "Choose_ViewPager");
86 | initViewpagerAdapter();
87 | } else {
88 | initFragments();
89 | Log.e(TAG, "Choose_frameLayout");
90 | }
91 | setTabSelect();
92 | if (null != mViewPager) {
93 | mViewPager.setCurrentItem(initChooseTab);
94 | } else {
95 | mTabLayout.setCurrentTab(initChooseTab);
96 | }
97 | }
98 |
99 | /**
100 | * 初始化图标图片文字fragment数据
101 | */
102 | private void initTabEntities() {
103 | if (null == mFragments || mFragments.length == 0) {
104 | throw new RuntimeException("mFragments is null");
105 | }
106 |
107 | if (null != mIconSelectIds & mFragments.length == mIconSelectIds.length
108 | && null != mIconUnSelectIds & mFragments.length == mIconUnSelectIds.length) {
109 | for (int i = 0; i < mFragments.length; i++) {
110 | mTabEntities.add(new TabEntity(mTitles == null ? "" : mTitles[i], mIconSelectIds[i], mIconUnSelectIds[i]));
111 | }
112 | mTabLayout.setTabData(mTabEntities);
113 | } else {
114 | Logger.d("Fragments and the number of ICONS do not meet");
115 | for (int i = 0; i < mFragments.length; i++) {
116 | mTabEntities.add(new TabEntity(mTitles == null ? "" : mTitles[i], 0, 0));
117 | }
118 | mTabLayout.setIconVisible(false);
119 | mTabLayout.setTabData(mTabEntities);
120 | }
121 |
122 | }
123 |
124 | /**
125 | * 初始化Fragments
126 | */
127 | private void initFragments() {
128 | //加载mFragments
129 | SupportFragment firstFragment = findChildFragment(mFragments[0].getClass());
130 | if (firstFragment == null) {
131 | loadMultipleRootFragment(R.id.yzs_base_tabLayout_frameLayout, initChooseTab, mFragments);
132 | } else {
133 | // 这里库已经做了Fragment恢复,所有不需要额外的处理了, 不会出现重叠问题
134 | for (int i = 0; i < mFragments.length; i++) {
135 | Log.e(TAG, "initFragments" + i);
136 | mFragments[i] = findFragment(mFragments[i].getClass());
137 | }
138 | }
139 | }
140 |
141 | /**
142 | * 初始化viewpager的adapter
143 | */
144 | private void initViewpagerAdapter() {
145 | mViewPager.setAdapter(new MyPagerAdapter(getChildFragmentManager()));
146 | mViewPager.setOffscreenPageLimit(mFragments.length - 1);
147 | mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
148 | @Override
149 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
150 |
151 | }
152 |
153 | @Override
154 | public void onPageSelected(int position) {
155 | mTabLayout.setCurrentTab(position);
156 | }
157 |
158 | /**
159 | * viewpager滑动状态判断,1为滑动状态,2为滑动完成,0为停止
160 | */
161 | @Override
162 | public void onPageScrollStateChanged(int state) {
163 | if (state == 0) {
164 | YzsBaseHomeFragment.this.onTabSelect(mViewPager.getCurrentItem());
165 | }
166 |
167 | }
168 | });
169 |
170 | }
171 |
172 | /**
173 | * 点击事件是否执行
174 | *
175 | * @param position 点击的下标
176 | * @return 是否可向下执行
177 | */
178 | public void beforeOnclick(int position, int toDoHidden) {
179 | //这是方法是显示隐藏调用,如果你不不需要进行判断就不用处理这个方法,如果你的app切换需要状态判断
180 | //才能确定是否允许切换就需要在这个方法写文章了举个例子,下面的例子是判断登录正常调整,不登录跳转登录页
181 | // if ((position == 3 || position == 4)&&!isLogin){
182 | // LoginActivity.Start(_mActivity);
183 | // mTabLayout.setCurrentTab(toDoHidden);
184 | // return;
185 | // }else {
186 | // showHideFragment(mFragments[position], mFragments[toDoHidden]);
187 | // }
188 | showHideFragment(mFragments[position], mFragments[toDoHidden]);
189 | }
190 |
191 | /**
192 | * 为mTabLayout设置监听
193 | */
194 | private void setTabSelect() {
195 | Log.e(TAG, "setTabSelect");
196 | mTabLayout.setOnTabSelectListener(new OnTabSelectListener() {
197 | @Override
198 | public void onTabSelect(int position) {
199 | if (null != mViewPager) {
200 | mViewPager.setCurrentItem(position);
201 | } else {
202 | int toDoHidden = -1;
203 | for (int i = 0; i < mFragments.length; i++) {
204 | if (!mFragments[i].isHidden()) {
205 | toDoHidden = i;
206 | Log.e(TAG, "查找显示中的fragment-------" + toDoHidden);
207 | }
208 | }
209 | Log.e(TAG, "选中的fragment-------" + position);
210 | Log.e(TAG, "确定显示中的fragment-------" + toDoHidden);
211 | beforeOnclick(position, toDoHidden);
212 |
213 | }
214 | YzsBaseHomeFragment.this.onTabSelect(position);
215 | }
216 |
217 | @Override
218 | public void onTabReselect(int position) {
219 |
220 | Log.e(TAG, "再次选中项" + position);
221 | YzsBaseHomeFragment.this.onTabReselect(position);
222 | }
223 | });
224 | }
225 |
226 |
227 | // public void
228 |
229 | /**
230 | * tab的选中回调
231 | */
232 | protected abstract void onTabSelect(int position);
233 |
234 | /**
235 | * tab的再次选中回调
236 | */
237 | protected abstract void onTabReselect(int position);
238 |
239 |
240 | /**
241 | * 设置TabLayout属性,所有关于TabLayout属性在这里设置
242 | */
243 | protected abstract void initTab();
244 |
245 | /**
246 | * 获取Fragment数组
247 | *
248 | * @return mFragments
249 | */
250 | public YzsBaseFragment[] getmFragments() {
251 | return mFragments;
252 | }
253 |
254 | /**
255 | * 放入Fragment数组(必须继承YzsBaseFragment)
256 | *
257 | * @param mFragments
258 | */
259 | public void setmFragments(YzsBaseFragment[] mFragments) {
260 | this.mFragments = mFragments;
261 | }
262 |
263 | /**
264 | * 获取选中图标数组
265 | *
266 | * @return mIconSelectIds
267 | */
268 | public int[] getmIconSelectIds() {
269 | return mIconSelectIds;
270 | }
271 |
272 | /**
273 | * 放入选中图标数组
274 | *
275 | * @param mIconSelectIds
276 | */
277 | public void setmIconSelectIds(int[] mIconSelectIds) {
278 | this.mIconSelectIds = mIconSelectIds;
279 | }
280 |
281 | /**
282 | * 获取未选中图标数组
283 | *
284 | * @return mIconUnSelectIds
285 | */
286 | public int[] getmIconUnSelectIds() {
287 | return mIconUnSelectIds;
288 | }
289 |
290 | /**
291 | * 放入未选中图标数组
292 | *
293 | * @param mIconUnSelectIds
294 | */
295 | public void setmIconUnSelectIds(int[] mIconUnSelectIds) {
296 | this.mIconUnSelectIds = mIconUnSelectIds;
297 | }
298 |
299 | /**
300 | * 获取mTitles数组
301 | *
302 | * @return mTitles
303 | */
304 | public String[] getmTitles() {
305 | return mTitles;
306 | }
307 |
308 | /**
309 | * 放入mTitles数组
310 | *
311 | * @param mTitles
312 | */
313 | public void setmTitles(String[] mTitles) {
314 | this.mTitles = mTitles;
315 | }
316 |
317 | public Bundle getBundle() {
318 | return bundle;
319 | }
320 |
321 | public void setBundle(Bundle bundle) {
322 | this.bundle = bundle;
323 | }
324 |
325 | private class MyPagerAdapter extends FragmentPagerAdapter {
326 | public MyPagerAdapter(FragmentManager fm) {
327 | super(fm);
328 | }
329 |
330 | @Override
331 | public int getCount() {
332 | return mFragments.length;
333 | }
334 |
335 | @Override
336 | public CharSequence getPageTitle(int position) {
337 | return mTitles == null ? "" : mTitles[position];
338 | }
339 |
340 | @Override
341 | public Fragment getItem(int position) {
342 | return mFragments[position];
343 | }
344 | }
345 |
346 | }
347 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/java/com/yzs/yzsbaseactivitylib/yzsbase/YzsBaseListFragment.java:
--------------------------------------------------------------------------------
1 | package com.yzs.yzsbaseactivitylib.yzsbase;
2 |
3 | import com.yzs.yzsbaseactivitylib.basemvp.BaseModel;
4 | import com.yzs.yzsbaseactivitylib.basemvp.BasePresenter;
5 |
6 | /**
7 | * Author: 姚智胜
8 | * Version: V1.0版本
9 | * Description: 列表类fragment(不使用mvp架构)
10 | * Date: 2017/6/13
11 | * Email: 541567595@qq.com
12 | */
13 |
14 | public abstract class YzsBaseListFragment extends YzsBaseMvpListFragment {
15 |
16 | @Override
17 | protected int getLayoutRes() {
18 | setMvp(false);
19 | return super.getLayoutRes();
20 | }
21 |
22 | @Override
23 | public void initPresenter() {
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/java/com/yzs/yzsbaseactivitylib/yzsbase/YzsBaseListTypeFragment.java:
--------------------------------------------------------------------------------
1 | package com.yzs.yzsbaseactivitylib.yzsbase;
2 |
3 | import com.chad.library.adapter.base.entity.MultiItemEntity;
4 | import com.yzs.yzsbaseactivitylib.basemvp.BaseModel;
5 | import com.yzs.yzsbaseactivitylib.basemvp.BasePresenter;
6 |
7 | /**
8 | * Author: 姚智胜
9 | * Version: V1.0版本
10 | * Description: 列表类多重子布局fragment(不使用mvp架构)
11 | * Date: 2017/6/13
12 | * Email: 541567595@qq.com
13 | */
14 |
15 | public abstract class YzsBaseListTypeFragment extends
16 | YzsBaseMvpListTypeFragment {
17 |
18 | // @Override
19 | // protected int getLayoutResource() {
20 | // setMvp(false);
21 | // return getLayoutRes();
22 | // }
23 |
24 |
25 | @Override
26 | protected int getLayoutRes() {
27 | setMvp(false);
28 | return super.getLayoutRes();
29 | }
30 |
31 | @Override
32 | public void initPresenter() {
33 |
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/java/com/yzs/yzsbaseactivitylib/yzsbase/YzsBaseMvpListFragment.java:
--------------------------------------------------------------------------------
1 | package com.yzs.yzsbaseactivitylib.yzsbase;
2 |
3 | import android.view.View;
4 |
5 | import androidx.annotation.DrawableRes;
6 | import androidx.annotation.LayoutRes;
7 | import androidx.annotation.Nullable;
8 | import androidx.recyclerview.widget.GridLayoutManager;
9 | import androidx.recyclerview.widget.LinearLayoutManager;
10 | import androidx.recyclerview.widget.RecyclerView;
11 | import androidx.recyclerview.widget.StaggeredGridLayoutManager;
12 |
13 | import com.chad.library.adapter.base.BaseQuickAdapter;
14 | import com.chad.library.adapter.base.BaseViewHolder;
15 | import com.chad.library.adapter.base.loadmore.LoadMoreView;
16 | import com.orhanobut.logger.Logger;
17 | import com.scwang.smartrefresh.layout.api.RefreshLayout;
18 | import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
19 | import com.scwang.smartrefresh.layout.listener.OnRefreshLoadmoreListener;
20 | import com.yzs.yzsbaseactivitylib.R;
21 | import com.yzs.yzsbaseactivitylib.annotations.ListType;
22 | import com.yzs.yzsbaseactivitylib.basemvp.BaseModel;
23 | import com.yzs.yzsbaseactivitylib.basemvp.BasePresenter;
24 | import com.yzs.yzsbaseactivitylib.entity.BaseListType;
25 |
26 | import java.util.ArrayList;
27 | import java.util.List;
28 |
29 | /**
30 | * Author: 姚智胜
31 | * Version: V1.0版本
32 | * Description:
33 | * Date: 2018/1/9
34 | * Email: 541567595@qq.com
35 | */
36 |
37 | public abstract class YzsBaseMvpListFragment extends
38 | YzsBaseFragment {
39 |
40 | /**
41 | * 默认为0单行布局
42 | */
43 | private int mListType = 0;
44 | /**
45 | * 排列方式默认垂直
46 | */
47 | private boolean mIsVertical = true;
48 | /**
49 | * grid布局与瀑布流布局默认行数
50 | */
51 | private int mSpanCount = 1;
52 |
53 | protected RecyclerView mRecyclerView;
54 |
55 | protected YzsListAdapter mAdapter;
56 |
57 | protected RefreshLayout mRefreshLayout;
58 |
59 | private boolean isOpenRefresh = false;
60 |
61 | private boolean isOpenLoadMore = false;
62 |
63 | private int mPage = 1;
64 | private int mPageSize = 10;
65 | private int startPageNum = 1;
66 |
67 | public void setmPageSize(int mPageSize) {
68 | this.mPageSize = mPageSize;
69 | }
70 |
71 |
72 | @Override
73 | protected int getLayoutRes() {
74 | return R.layout.yzs_comment_list;
75 | }
76 |
77 | public int getmPageSize() {
78 | return mPageSize;
79 | }
80 |
81 | /**
82 | * 是否开启刷新和加载更多,默认不开启
83 | *
84 | * @param isOpenRefresh
85 | * @param isOpenLoadMore
86 | */
87 | public void isOpenLoad(boolean isOpenRefresh, boolean isOpenLoadMore) {
88 | this.isOpenRefresh = isOpenRefresh;
89 | this.isOpenLoadMore = isOpenLoadMore;
90 | }
91 |
92 | @Override
93 | protected void initView(View view) {
94 | if (0 == getLayoutRes()) {
95 | throw new RuntimeException("layoutResId is null!");
96 | }
97 | mRecyclerView = (RecyclerView) view.findViewById(R.id.yzs_base_list);
98 | mRefreshLayout = (RefreshLayout) view.findViewById(R.id.yzs_base_refreshLayout);
99 | mAdapter = new YzsListAdapter(initItemLayout(), new ArrayList());
100 | initSetting();
101 | chooseListType(mListType, mIsVertical);
102 |
103 | if (isOpenRefresh && mRefreshLayout != null) {
104 | if (isOpenLoadMore) {
105 | mRefreshLayout.setOnRefreshLoadmoreListener(new OnRefreshLoadmoreListener() {
106 | @Override
107 | public void onLoadmore(RefreshLayout refreshlayout) {
108 | judgeViewIsNull();
109 | if (mRefreshLayout != null)
110 | loadMoreListener();
111 | }
112 |
113 | @Override
114 | public void onRefresh(RefreshLayout refreshlayout) {
115 | judgeViewIsNull();
116 | refreshListener();
117 | }
118 | });
119 | } else {
120 | mRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
121 | @Override
122 | public void onRefresh(RefreshLayout refreshlayout) {
123 | judgeViewIsNull();
124 | refreshListener();
125 | }
126 | });
127 | }
128 |
129 | }
130 |
131 | }
132 |
133 |
134 | /**
135 | * 初始化子布局
136 | */
137 | protected abstract
138 | @LayoutRes
139 | int initItemLayout();
140 |
141 | /**
142 | * 初始化各种状态处理
143 | * 在这个方法里处理的是recyclerview的所有的初始化,
144 | * 包括对他的展示形式,是list或grid或瀑布流
145 | */
146 | protected abstract void initSetting();
147 |
148 | /**
149 | * @param type 布局管理type
150 | * @param isVertical 是否是垂直的布局 ,true垂直布局,false横向布局
151 | */
152 | protected void setListType(@ListType int type, boolean isVertical) {
153 | mListType = type;
154 | mIsVertical = isVertical;
155 | }
156 |
157 | /**
158 | * 为grid样式和瀑布流设置横向或纵向数量
159 | *
160 | * @param spanCount 数量
161 | */
162 | protected void setSpanCount(int spanCount) {
163 | if (spanCount > 0)
164 | mSpanCount = spanCount;
165 | }
166 |
167 | /**
168 | * @param listType 选择布局种类
169 | */
170 | private void chooseListType(int listType, boolean isVertical) {
171 | switch (listType) {
172 | case BaseListType.LINEAR_LAYOUT_MANAGER:
173 | //设置布局管理器
174 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
175 |
176 | linearLayoutManager.setOrientation(isVertical ? LinearLayoutManager.VERTICAL : LinearLayoutManager.HORIZONTAL);
177 |
178 | mRecyclerView.setLayoutManager(linearLayoutManager);
179 | break;
180 | case BaseListType.GRID_LAYOUT_MANAGER:
181 |
182 | GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), mSpanCount);
183 |
184 | gridLayoutManager.setOrientation(isVertical ? GridLayoutManager.VERTICAL : GridLayoutManager.HORIZONTAL);
185 |
186 | mRecyclerView.setLayoutManager(gridLayoutManager);
187 | break;
188 | case BaseListType.STAGGERED_GRID_LAYOUT_MANAGER:
189 | //设置布局管理器
190 | StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager
191 | (mSpanCount, isVertical ? StaggeredGridLayoutManager.VERTICAL : StaggeredGridLayoutManager.HORIZONTAL);
192 |
193 | mRecyclerView.setLayoutManager(staggeredGridLayoutManager);
194 | break;
195 | default:
196 | //设置布局管理器
197 | LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
198 |
199 | layoutManager.setOrientation(isVertical ? LinearLayoutManager.VERTICAL : LinearLayoutManager.HORIZONTAL);
200 |
201 | mRecyclerView.setLayoutManager(layoutManager);
202 | break;
203 | }
204 | mRecyclerView.setAdapter(mAdapter);
205 | }
206 |
207 | /**
208 | * adapter内的处理
209 | *
210 | * @param baseViewHolder BaseViewHolder
211 | * @param t 泛型T
212 | */
213 | protected abstract void MyHolder(BaseViewHolder baseViewHolder, D t);
214 |
215 | /**
216 | * 刷新回调
217 | */
218 | protected void refreshListener() {
219 | }
220 |
221 |
222 | /**
223 | * 加载更多回调
224 | */
225 | protected void loadMoreListener() {
226 | }
227 |
228 |
229 | public class YzsListAdapter extends BaseQuickAdapter {
230 |
231 | public YzsListAdapter(int layoutResId, List data) {
232 | super(layoutResId, data);
233 | }
234 |
235 | @Override
236 | protected void convert(BaseViewHolder baseViewHolder, D t) {
237 | MyHolder(baseViewHolder, t);
238 | }
239 | }
240 |
241 | public void okRefresh() {
242 | judgeViewIsNull();
243 | if (mAdapter != null) {
244 | mPage = startPageNum+1;
245 | mRefreshLayout.finishRefresh();
246 | mRefreshLayout.setLoadmoreFinished(false);//恢复上拉状态
247 | Logger.d("refresh_complete");
248 | }
249 | }
250 |
251 | public void autoListLoad(@Nullable List tList, String empty_str, @DrawableRes int Empty_res) {
252 | tList = tList == null ? new ArrayList() : tList;
253 | if (getPage() == startPageNum) {
254 | okRefresh();
255 | mAdapter.setNewData(tList);
256 | if (tList.size() == 0) {
257 | mAdapter.setEmptyView(getEmptyView(empty_str, Empty_res));
258 | }
259 | } else {
260 | if (tList.size() == mPageSize) {
261 | okLoadMore(true);
262 | } else {
263 | okLoadMore(false);
264 | }
265 | mAdapter.addData(tList);
266 | }
267 | }
268 |
269 | /**
270 | * 包含错误处理自动化,在接口返回错误处使用
271 | *
272 | * @param tList
273 | * @param empty_str
274 | * @param empty_res
275 | * @param isFail
276 | */
277 | public void autoListLoad(@Nullable List tList, String empty_str, @DrawableRes int empty_res, boolean isFail) {
278 | if (isFail && getPage() != startPageNum) {
279 | failLoadMore();
280 | } else {
281 | autoListLoad(tList, empty_str, empty_res);
282 | }
283 | }
284 |
285 |
286 | public void okLoadMore(boolean isHashNext) {
287 | judgeViewIsNull();
288 |
289 | mPage++;
290 | mRefreshLayout.finishLoadmore();
291 |
292 | if (!isHashNext) {
293 | //false为显示加载结束,true为不显示
294 | mRefreshLayout.setLoadmoreFinished(true);//设置之后,将不会再触发加载事件
295 | }
296 | }
297 |
298 |
299 | public void failLoadMore() {
300 | judgeViewIsNull();
301 | mRefreshLayout.finishLoadmore();
302 | }
303 |
304 | @Override
305 | public void onDestroy() {
306 | mAdapter = null;
307 | mRefreshLayout = null;
308 | super.onDestroy();
309 | }
310 |
311 | public int getPage() {
312 | return mPage;
313 | }
314 |
315 | public void setPage(int page) {
316 | mPage = page;
317 | startPageNum = page;
318 | }
319 |
320 |
321 | /**
322 | * 处理mRefreshLayout与mRecyclerView的未知空情况bug
323 | */
324 | private void judgeViewIsNull() {
325 | if (mRefreshLayout == null) {
326 | mRefreshLayout = (RefreshLayout) rootView.findViewById(R.id.yzs_base_refreshLayout);
327 | }
328 | if (mRecyclerView == null) {
329 | mRecyclerView = (RecyclerView) rootView.findViewById(R.id.yzs_base_list);
330 | }
331 | if (mAdapter == null) {
332 | mAdapter = new YzsListAdapter(initItemLayout(), new ArrayList());
333 | initSetting();
334 | chooseListType(mListType, mIsVertical);
335 |
336 | if (isOpenRefresh && mRefreshLayout != null) {
337 | if (isOpenLoadMore) {
338 | mRefreshLayout.setOnRefreshLoadmoreListener(new OnRefreshLoadmoreListener() {
339 | @Override
340 | public void onLoadmore(RefreshLayout refreshlayout) {
341 | judgeViewIsNull();
342 | if (mRefreshLayout != null)
343 | loadMoreListener();
344 | }
345 |
346 | @Override
347 | public void onRefresh(RefreshLayout refreshlayout) {
348 | judgeViewIsNull();
349 | refreshListener();
350 | }
351 | });
352 | } else {
353 | mRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
354 | @Override
355 | public void onRefresh(RefreshLayout refreshlayout) {
356 | judgeViewIsNull();
357 | refreshListener();
358 | }
359 | });
360 | }
361 |
362 | }
363 |
364 | }
365 |
366 | }
367 |
368 | /**
369 | * 进入自动加载
370 | */
371 | protected void autoRefresh() {
372 | mRefreshLayout.autoRefresh();
373 | }
374 |
375 | /**
376 | * 提供改变显示方法(该方法用于布局显示后动态改变显示方式)
377 | */
378 | protected void changeShowType(@ListType int listType, boolean isVertical) {
379 | chooseListType(listType, isVertical);
380 | }
381 | }
382 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/java/com/yzs/yzsbaseactivitylib/yzsbase/YzsBaseSupportFragmentActivity.java:
--------------------------------------------------------------------------------
1 | package com.yzs.yzsbaseactivitylib.yzsbase;
2 |
3 | import android.os.Bundle;
4 |
5 | import com.yzs.yzsbaseactivitylib.R;
6 | import com.yzs.yzsbaseactivitylib.basemvp.BaseModel;
7 | import com.yzs.yzsbaseactivitylib.basemvp.BasePresenter;
8 |
9 | import me.yokeyword.fragmentation.SupportFragment;
10 | import me.yokeyword.fragmentation.anim.DefaultNoAnimator;
11 | import me.yokeyword.fragmentation.anim.FragmentAnimator;
12 |
13 | /**
14 | * Author: 姚智胜
15 | * Version: V1.0版本
16 | * Description:
17 | * Date: 2018/1/10
18 | * Email: 541567595@qq.com
19 | */
20 |
21 | public abstract class YzsBaseSupportFragmentActivity
22 | extends YzsBaseActivity {
23 |
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | // UnCeHandler.getInstance().init(this);
29 | if (null != setFragment()) {
30 | loadRootFragment(R.id.fl_container, setFragment());
31 | }
32 |
33 | }
34 |
35 | @Override
36 | public int getContentViewResId() {
37 | return R.layout.ac_base;
38 | }
39 |
40 | /**
41 | * 设置整个架构的第一个fragment
42 | *
43 | * @return
44 | */
45 | public abstract SupportFragment setFragment();
46 |
47 |
48 | @Override
49 | public FragmentAnimator onCreateFragmentAnimator() {
50 | // 设置默认Fragment动画 默认竖向(和安卓5.0以上的动画相同)
51 | // return super.onCreateFragmentAnimator();
52 | //无动画
53 | return new DefaultNoAnimator();
54 | // 设置横向(和安卓4.x动画相同)
55 | // return new DefaultHorizontalAnimator();
56 | // 设置自定义动画
57 | // return new FragmentAnimator(enter,exit,popEnter,popExit);
58 | }
59 |
60 | @Override
61 | public boolean showToolBar() {
62 | return super.showToolBar();
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/java/com/yzs/yzsbaseactivitylib/yzsbase/YzsBaseWebFragment.java:
--------------------------------------------------------------------------------
1 | package com.yzs.yzsbaseactivitylib.yzsbase;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Activity;
5 | import android.graphics.Bitmap;
6 | import android.net.http.SslError;
7 | import android.os.Build;
8 | import android.util.Log;
9 | import android.view.View;
10 | import android.webkit.SslErrorHandler;
11 | import android.webkit.WebChromeClient;
12 | import android.webkit.WebSettings;
13 | import android.webkit.WebView;
14 | import android.webkit.WebViewClient;
15 |
16 | import com.yzs.yzsbaseactivitylib.R;
17 | import com.yzs.yzsbaseactivitylib.util.LoadingDialogUtils;
18 | import com.yzs.yzsbaseactivitylib.util.StringUtils;
19 |
20 |
21 | /**
22 | * Author: 姚智胜
23 | * Version: V1.0版本
24 | * Description: baseWebFragment
25 | * Date: 2017/7/4
26 | * Email: 541567595@qq.com
27 | */
28 |
29 | public abstract class YzsBaseWebFragment extends YzsBaseFragment {
30 | private static final String TAG = "YzsBaseWebFragment";
31 |
32 | protected WebView wv_web_view;
33 |
34 |
35 | protected WebView initWeb(final String url) {
36 | return initWebView(url, _mActivity, null, null);
37 | }
38 |
39 | protected WebView initWeb(final String url,
40 | final onWebProgressListener listener) {
41 | return initWebView(url, _mActivity, null, listener);
42 | }
43 | protected WebView initWeb(final String url,
44 | Object classObj,
45 | final onWebProgressListener listener) {
46 | return initWebView(url, _mActivity, classObj, listener);
47 | }
48 |
49 |
50 | /**
51 | * 初始化webView
52 | *
53 | * @param activity webView窗体
54 | * @param listener web加载进度监听
55 | * @param classObj 调用javascript类
56 | * @return
57 | */
58 | @SuppressLint({"SetJavaScriptEnabled", "JavascriptInterface"})
59 | private WebView initWebView(final String url,
60 | Activity activity,
61 | Object classObj,
62 | final onWebProgressListener listener
63 | ) {
64 | if (null == activity) {
65 | Log.e(TAG, "activity is null!");
66 | return null;
67 | }
68 |
69 | WebSettings wv_settings = wv_web_view.getSettings();
70 | wv_settings.setJavaScriptEnabled(true);
71 | wv_settings.setDefaultTextEncodingName("UTF-8");
72 | wv_settings.setDisplayZoomControls(false);
73 | wv_settings.setBuiltInZoomControls(false);
74 | wv_settings.setSupportZoom(false);
75 | wv_settings.setDomStorageEnabled(true);
76 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
77 | wv_settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
78 | }
79 |
80 | // 加载的页面自适应手机屏幕
81 | wv_settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
82 |
83 | wv_web_view.setWebViewClient(new WebViewClient() {
84 | @Override
85 | public void onPageStarted(WebView view, String url, Bitmap favicon) {
86 | super.onPageStarted(view, url, favicon);
87 | LoadingDialogUtils.showLoadingDialog(_mActivity);
88 | }
89 |
90 | @Override
91 | public void onPageFinished(WebView view, String url) {
92 | super.onPageFinished(view, url);
93 | LoadingDialogUtils.cancelLoadingDialog();
94 | }
95 |
96 | @Override
97 | public boolean shouldOverrideUrlLoading(WebView view, String url) {
98 | //去WebView打开
99 | view.loadUrl(url);
100 | return true;
101 | }
102 |
103 | //https:验证
104 | @Override
105 | public void onReceivedSslError(WebView view,
106 | SslErrorHandler handler, SslError error) {
107 | handler.proceed();
108 | }
109 | });
110 |
111 | if (null != listener) {
112 | wv_web_view.setWebChromeClient(new WebChromeClient() {
113 | @Override
114 | public void onProgressChanged(WebView view, int newProgress) {
115 | if (100 == newProgress) {
116 | if (null != listener) {
117 | listener.onProgressComplete();
118 | }
119 | // 关闭进度条
120 | } else {
121 | if (null != listener) {
122 | listener.onProgressStart();
123 | }
124 | // 加载中显示进度条
125 | }
126 | }
127 | });
128 | }
129 |
130 | if (null != classObj) {
131 | wv_web_view.addJavascriptInterface(classObj, "JsInteface");
132 | }
133 |
134 | if (!StringUtils.isEmpty(url)) {
135 | loadWebPage(wv_web_view, url);
136 | }
137 |
138 | return wv_web_view;
139 | }
140 |
141 |
142 |
143 | /**
144 | * 加载网页
145 | */
146 | private void loadWebPage(WebView webView, final String params) {
147 | if (this.isUrl(params)) { // url 地址 形式 加载
148 | //WebView加载web资源
149 | // final String urlString = WebPage.IP_PATH
150 | // + this.webPageIdentify
151 | // + this.webPageParams;
152 | Log.e(TAG, "url:" + params);
153 | webView.loadUrl(params);
154 | } else {// 网页 源码 形式 加载
155 | webView.loadDataWithBaseURL(null, params, "text/html", "utf-8", null);
156 | }
157 | }
158 |
159 | private boolean isUrl(final String url) {
160 | boolean urlFlag = false;
161 |
162 | final String strTmp = url.substring(0, 4);
163 | if (!StringUtils.isEmpty(url) && !StringUtils.isEmpty(strTmp)) {
164 | if ("http".equals(strTmp) || "https".equals(strTmp)) {
165 | urlFlag = true;
166 | }
167 | }
168 |
169 | return urlFlag;
170 | }
171 |
172 | /**
173 | * @author zhaojy
174 | * @ClassName IWebProgress
175 | * @date 2015-12-13
176 | * @Description: web页加载状态
177 | */
178 | public interface onWebProgressListener {
179 | public void onProgressComplete();
180 |
181 | public void onProgressStart();
182 | }
183 |
184 | @Override
185 | public void initPresenter() {
186 |
187 | }
188 |
189 | @Override
190 | protected int getLayoutRes() {
191 | return R.layout.layout_web;
192 | }
193 |
194 | @Override
195 | protected void initView(View rootView) {
196 | wv_web_view = (WebView) rootView.findViewById(R.id.wv_webview);
197 | }
198 |
199 |
200 | }
201 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/res/drawable-xxhdpi/base_toolbar_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yaozs/YzsBaseActivity/135ab39748cd2c734020fdfad47d942ac62dec80/yzsbaseactivitylib/src/main/res/drawable-xxhdpi/base_toolbar_back.png
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/res/layout/ac_base.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
18 |
19 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/res/layout/ac_base_toolbar_cover.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
13 |
14 |
19 |
20 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/res/layout/layout_common_toolbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
21 |
22 |
30 |
31 |
40 |
41 |
49 |
50 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/res/layout/layout_empty_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
12 |
13 |
20 |
21 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/res/layout/layout_web.xml:
--------------------------------------------------------------------------------
1 |
5 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/res/layout/res_l_simple_progress_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
15 |
16 |
23 |
24 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/res/layout/res_yzs_loading_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
15 |
16 |
23 |
24 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/res/layout/yzs_comment_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
22 |
23 |
28 |
29 |
33 |
34 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/res/mipmap-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yaozs/YzsBaseActivity/135ab39748cd2c734020fdfad47d942ac62dec80/yzsbaseactivitylib/src/main/res/mipmap-mdpi/icon.png
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/res/mipmap-xhdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yaozs/YzsBaseActivity/135ab39748cd2c734020fdfad47d942ac62dec80/yzsbaseactivitylib/src/main/res/mipmap-xhdpi/icon.png
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/res/mipmap-xxhdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yaozs/YzsBaseActivity/135ab39748cd2c734020fdfad47d942ac62dec80/yzsbaseactivitylib/src/main/res/mipmap-xxhdpi/icon.png
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/res/mipmap-xxxhdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yaozs/YzsBaseActivity/135ab39748cd2c734020fdfad47d942ac62dec80/yzsbaseactivitylib/src/main/res/mipmap-xxxhdpi/icon.png
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/res/values-v19/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 25dp
4 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 0dp
4 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | YzsBaseActivityLib
3 |
4 |
--------------------------------------------------------------------------------
/yzsbaseactivitylib/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
10 |
20 |
21 |
22 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------