diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index be4b980..79bede6 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 97626ba..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 6560a98..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index dc34569..44a4802 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,27 +5,31 @@ - + diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..35eb1dd 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 7bcf775..110bde1 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,35 +1,39 @@ + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - + + - - + + - - - + + + + + + + + + + + - - + + - - - + + - - + + - - - + + - - + + - - - + + - - + + - - - + + - - + + - - - + + - - + + + + + - - - + + - - + + - - - - - - - - + + - - + + - - - + + + + + + @@ -165,12 +170,12 @@ @@ -217,11 +222,11 @@ - - + + - - + + + + + - + + + + + + - + - - + + + + + + + + + + - + + - - - @@ -754,13 +790,17 @@ + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + - - - + - - - - - - + - - - + - + - + + + + + - - - - + - - + - + + + - - - - + + + - + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Xadapter/Xadapter.iml b/Xadapter/Xadapter.iml index 91c5a4b..3b48f92 100644 --- a/Xadapter/Xadapter.iml +++ b/Xadapter/Xadapter.iml @@ -17,26 +17,26 @@ - - + + - + - + @@ -71,13 +71,6 @@ - - - - - - - @@ -85,12 +78,18 @@ - + + + + + + + + - - - + + diff --git a/Xadapter/build.gradle b/Xadapter/build.gradle index 9a3fe49..079df90 100644 --- a/Xadapter/build.gradle +++ b/Xadapter/build.gradle @@ -23,12 +23,12 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + implementation fileTree(dir: 'libs', include: ['*.jar']) + androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - testCompile 'junit:junit:4.12' - compile "com.android.support:recyclerview-v7:${supportVersion}" + testImplementation 'junit:junit:4.12' + implementation "com.android.support:recyclerview-v7:${supportVersion}" } // 指定编码 diff --git a/Xadapter/src/main/java/com/xz/xadapter/XRvPureDataAdapter.java b/Xadapter/src/main/java/com/xz/xadapter/XRvPureDataAdapter.java index a3e2bf8..84df8ab 100644 --- a/Xadapter/src/main/java/com/xz/xadapter/XRvPureDataAdapter.java +++ b/Xadapter/src/main/java/com/xz/xadapter/XRvPureDataAdapter.java @@ -26,6 +26,14 @@ public List getDatas() { return mDatas; } + /** + * 一般使用 不带刷新 + */ + public void setData(@NonNull T data) { + List lists = new ArrayList<>(); + lists.add(data); + setDatas(lists, true); + } /** * 一般使用 不带刷新 @@ -42,9 +50,6 @@ public void setDatas(@NonNull List datas) { * @param isRefresh 是否刷新 */ public void setDatas(@NonNull List datas, boolean isRefresh) { - if (datas == null) { - return; - } if (mDatas == null) { mDatas = new ArrayList<>(); } else { @@ -62,7 +67,7 @@ public void setDatas(@NonNull List datas, boolean isRefresh) { * @param data 数据 * @param isRefresh 是否刷新 */ - public void addData(T data, boolean isRefresh) { + public void addData(@NonNull T data, boolean isRefresh) { if (this.mDatas == null) { this.mDatas = new ArrayList<>(); this.mDatas.add(data); @@ -83,7 +88,7 @@ public void addData(T data, boolean isRefresh) { * @param data 数据 * @param isRefresh 是否刷新 */ - public void addDatas(List data, boolean isRefresh) { + public void addDatas(@NonNull List data, boolean isRefresh) { if (this.mDatas == null) { this.mDatas = new ArrayList<>(); this.mDatas.addAll(data); @@ -99,14 +104,13 @@ public void addDatas(List data, boolean isRefresh) { } - /** * 移除data * * @param data 对象 * @return 是否移除成功 */ - public boolean removeData(T data) { + public boolean removeData(@NonNull T data) { return this.mDatas != null && this.mDatas.remove(data); } @@ -131,7 +135,7 @@ public boolean removeData(int index) { if (mDatas != null && index >= 0) { if (index < mDatas.size()) { mDatas.remove(index); - notifyItemRangeRemoved(index,1); + notifyItemRangeRemoved(index, 1); return true; } else { return false; diff --git a/Xadapter/src/main/java/com/xz/xadapter/XRvStatusAdapter.java b/Xadapter/src/main/java/com/xz/xadapter/XRvStatusAdapter.java new file mode 100644 index 0000000..e758a26 --- /dev/null +++ b/Xadapter/src/main/java/com/xz/xadapter/XRvStatusAdapter.java @@ -0,0 +1,217 @@ +package com.xz.xadapter; + +import android.annotation.SuppressLint; +import android.graphics.Color; +import android.support.annotation.ColorRes; +import android.support.annotation.DimenRes; +import android.support.annotation.LayoutRes; +import android.support.annotation.NonNull; +import android.support.v7.widget.GridLayoutManager; +import android.support.v7.widget.RecyclerView; + +import com.xz.xadapter.xutil.XRvViewHolder; +import com.xz.xadapter.xutil.XRvWrapperUtils; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author xz + * 状态Adapter + */ +public abstract class XRvStatusAdapter extends XRvPureDataAdapter { + + private boolean isLoading = false; + + private boolean isEmpty = false; + + private boolean isError = false; + + private String mStatusTip = ""; + + private static final int ITEM_STATUS = 9999; + + + /** + * 设置状态文字 颜色 + * resouce + */ + @ColorRes + protected int getStatusTextColor() { + return 0; + } + + /** + * 设置状态文字大小 + * dp + */ + protected int getStatusTextSize() { + return 0; + } + + /** + * 初始化一个实例给状态adapter,避免mData为null,或者空 + * + * @return 获取实例 + */ + protected abstract T initStatusLayout(); + + /** + * 显示正在加载中 + */ + public void showLoading(boolean loading) { + isLoading = loading; + if (loading) { + if (mDatas == null) { + mDatas = new ArrayList<>(); + mDatas.add(initStatusLayout()); + } + mStatusTip = "加载中..."; + notifyDataSetChanged(); + } + } + + /** + * 显示数据为空 + */ + public void showEmpty(boolean empty) { + isEmpty = empty; + if (empty) { + if (mDatas == null) { + mDatas = new ArrayList<>(); + mDatas.add(initStatusLayout()); + } + mStatusTip = "暂无数据..."; + notifyDataSetChanged(); + } + } + + /** + * 显示加载错误 + */ + public void showError(boolean error) { + isError = error; + if (error) { + if (mDatas == null) { + mDatas = new ArrayList<>(); + mDatas.add(initStatusLayout()); + } + mStatusTip = "加载失败,请检查网络!"; + notifyDataSetChanged(); + } + } + + @Override + public void setDatas(List datas) { + if (datas != null && datas.size() > 0) { + resetStatus(); + } + super.setDatas(datas); + if (mDatas.size() == 0) { + showEmpty(true); + } + } + + @Override + public void setDatas(List datas, boolean isRefresh) { + if (datas != null && datas.size() > 0) { + resetStatus(); + } + super.setDatas(datas, isRefresh); + if (mDatas.size() == 0) { + showEmpty(true); + } + } + + @Override + public void addData(T data, boolean isRefresh) { + resetStatus(); + super.addData(data, isRefresh); + } + + @Override + public void addDatas(List data, boolean isRefresh) { + resetStatus(); + super.addDatas(data, isRefresh); + } + + private void resetStatus() { + isEmpty = false; + isLoading = false; + isError = false; + } + + @Override + public final int getItemViewType(int position) { + if (isLoading || isEmpty || isError) { + return ITEM_STATUS; + } + return getItemViewTypeToStaus(position); + } + + public int getItemViewTypeToStaus(int position) { + return 0; + } + + @Override + public final int getItemLayout(int viewType) { + if (viewType == ITEM_STATUS) { + return R.layout.item_adapter_other; + } + return getItemLayoutToStatus(viewType); + } + + /** + * 设置layout + */ + @LayoutRes + public abstract int getItemLayoutToStatus(int viewType); + + + @Override + public final void onBindViewHolder(@NonNull XRvViewHolder holder, int position) { + if (getItemViewType(position) == ITEM_STATUS) { + holder.setText(R.id.ie_tv, mStatusTip); + if (getStatusTextColor() != 0) { + holder.setTextColor(R.id.ie_tv, getStatusTextColor()); + } + if (getStatusTextSize() > 0) { + holder.setTextSize(R.id.ie_tv, getStatusTextSize()); + } + } else { + onBindViewHolderToStatus(holder, position); + } + } + + + /** + * 显示数据,绑定控件 + */ + protected abstract void onBindViewHolderToStatus(@NonNull XRvViewHolder holder, int position); + + + @Override + public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) { + XRvWrapperUtils.onAttachedToRecyclerView(recyclerView, new XRvWrapperUtils.SpanSizeCallback() { + @Override + public int getSpanSize(GridLayoutManager gridLayoutManager, GridLayoutManager.SpanSizeLookup oldLookup, int position) { + if (isEmpty || isError || isLoading) { + return gridLayoutManager.getSpanCount(); + } + if (oldLookup != null) { + return oldLookup.getSpanSize(position); + } + return 1; + } + }); + } + + @Override + public void onViewAttachedToWindow(@NonNull XRvViewHolder holder) { + super.onViewAttachedToWindow(holder); + if (isEmpty || isError || isLoading) { + XRvWrapperUtils.setFullSpan(holder); + } + } + +} diff --git a/Xadapter/src/main/java/com/xz/xadapter/xutil/XRvViewHolder.java b/Xadapter/src/main/java/com/xz/xadapter/xutil/XRvViewHolder.java index 7161768..3234419 100644 --- a/Xadapter/src/main/java/com/xz/xadapter/xutil/XRvViewHolder.java +++ b/Xadapter/src/main/java/com/xz/xadapter/xutil/XRvViewHolder.java @@ -111,6 +111,12 @@ public XRvViewHolder setBackgroundRes(int viewId, int backgroundRes) { return this; } + public XRvViewHolder setTextSize(int viewId, int textSize) { + TextView view = getView(viewId); + view.setTextSize(textSize); + return this; + } + public XRvViewHolder setTextColor(int viewId, int textColor) { TextView view = getView(viewId); view.setTextColor(textColor); diff --git a/Xadapter/src/main/res/layout/item_adapter_other.xml b/Xadapter/src/main/res/layout/item_adapter_other.xml new file mode 100644 index 0000000..2fd6837 --- /dev/null +++ b/Xadapter/src/main/res/layout/item_adapter_other.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/Xadapter/src/main/res/values/colors.xml b/Xadapter/src/main/res/values/colors.xml new file mode 100644 index 0000000..6c0b8a3 --- /dev/null +++ b/Xadapter/src/main/res/values/colors.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/Xadapter/src/main/res/values/styles.xml b/Xadapter/src/main/res/values/styles.xml new file mode 100644 index 0000000..0ac0de1 --- /dev/null +++ b/Xadapter/src/main/res/values/styles.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/app.iml b/app/app.iml index 051209b..7e1c871 100644 --- a/app/app.iml +++ b/app/app.iml @@ -23,19 +23,19 @@ - - + + - + - + @@ -49,13 +49,6 @@ - - - - - - - @@ -63,6 +56,13 @@ + + + + + + + @@ -84,15 +84,20 @@ + + + - - + + + + - + diff --git a/app/build.gradle b/app/build.gradle index 8fe5da2..f3fb333 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -19,22 +19,22 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + implementation fileTree(dir: 'libs', include: ['*.jar']) + androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - compile 'com.android.support.constraint:constraint-layout:1.0.2' - testCompile 'junit:junit:4.12' + implementation 'com.android.support.constraint:constraint-layout:1.0.2' + testImplementation 'junit:junit:4.12' //鸿婶的BaseAdapter git(https://github.com/hongyangAndroid/baseAdapter) - compile "com.android.support:appcompat-v7:${supportVersion}" - compile "com.android.support:support-v4:${supportVersion}" - compile "com.android.support:recyclerview-v7:${supportVersion}" + implementation "com.android.support:appcompat-v7:${supportVersion}" + implementation "com.android.support:support-v4:${supportVersion}" + implementation "com.android.support:recyclerview-v7:${supportVersion}" //刷新加载(https://github.com/scwang90/SmartRefreshLayout) - compile ('com.scwang.smartrefresh:SmartRefreshLayout:1.0.3-alpha-2') { + implementation ('com.scwang.smartrefresh:SmartRefreshLayout:1.0.3-alpha-2') { exclude group: 'com.android.support' } } diff --git a/build.gradle b/build.gradle index ee48413..991e928 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.3' + classpath 'com.android.tools.build:gradle:3.2.1' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index aa57e5a..33089d1 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Sep 11 21:16:56 CST 2018 +#Thu Oct 18 11:48:03 CST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip diff --git a/local.properties b/local.properties index bd34ee9..564cc72 100644 --- a/local.properties +++ b/local.properties @@ -4,6 +4,6 @@ # Location of the SDK. This is only used by Gradle. # For customization when using a Version Control System, please read the # header note. -#Tue Sep 11 21:13:47 CST 2018 -ndk.dir=I\:\\Android\\AndroidStudio\\Sdk\\ndk-bundle -sdk.dir=I\:\\Android\\AndroidStudio\\Sdk +#Thu Oct 18 11:46:55 CST 2018 +ndk.dir=D\:\\AndroidStudioFile\\AndroidSdk\\ndk-bundle +sdk.dir=D\:\\AndroidStudioFile\\AndroidSdk