From 9f2967f4de3c8eea3583fde89f084da38397119a Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sat, 18 Mar 2017 00:51:12 +0800
Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5eclipse=E7=89=88=E8=87=B3stud?=
=?UTF-8?q?io=E7=89=88?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../zuo/biao/library/base/BaseAdapter.java | 26 +-
.../library/base/BaseHttpListActivity.java | 15 +-
.../biao/library/base/BaseListActivity.java | 20 +-
.../biao/library/base/BaseListFragment.java | 20 +-
.../zuo/biao/library/base/BaseAdapter.java | 26 +-
.../library/base/BaseHttpListActivity.java | 70 ++++--
.../library/base/BaseHttpListFragment.java | 63 +++--
.../biao/library/base/BaseListActivity.java | 233 +++++++++---------
.../biao/library/base/BaseListFragment.java | 233 ++++++++----------
.../library/interfaces/CacheCallBack.java | 2 +-
.../java/zuo/biao/library/manager/Cache.java | 10 +-
.../biao/library/manager/CacheManager.java | 160 ++++++------
.../library/ui/ServerSettingActivity.java | 9 +-
.../biao/library/ui/xlistview/XListView.java | 24 +-
.../library/ui/xlistview/XListViewFooter.java | 44 ++--
.../main/java/zuo/biao/library/util/Json.java | 130 ++++++++--
.../zuo/biao/library/util/SettingUtil.java | 97 +++++---
.../zblibrary/demo/DEMO/DemoListActivity.java | 6 +-
.../zblibrary/demo/DEMO/DemoListFragment.java | 4 +-
.../zblibrary/demo/DEMO/DemoMainActivity.java | 2 +-
.../demo/activity_fragment/AboutActivity.java | 2 +-
.../activity_fragment/QRCodeActivity.java | 4 +-
.../activity_fragment/SettingActivity.java | 24 +-
.../demo/activity_fragment/UserActivity.java | 16 +-
.../activity_fragment/UserListFragment.java | 15 +-
.../zblibrary/demo/manager/DataManager.java | 6 +-
.../src/main/res/layout/setting_activity.xml | 36 +++
27 files changed, 741 insertions(+), 556 deletions(-)
diff --git a/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseAdapter.java b/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseAdapter.java
index 83bb4ce..c199908 100755
--- a/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseAdapter.java
+++ b/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseAdapter.java
@@ -14,11 +14,6 @@
package zuo.biao.library.base;
-import java.util.ArrayList;
-import java.util.List;
-
-import zuo.biao.library.interfaces.OnReachViewBorderListener;
-import zuo.biao.library.util.CommonUtil;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
@@ -26,6 +21,13 @@
import android.view.View;
import android.view.ViewGroup;
+import java.util.ArrayList;
+import java.util.List;
+
+import zuo.biao.library.interfaces.OnReachViewBorderListener;
+import zuo.biao.library.util.CommonUtil;
+import zuo.biao.library.util.SettingUtil;
+
/**基础Adapter
*
适用于ListView,GridView等AbsListView的子类
* @author Lemon
@@ -39,7 +41,7 @@
public abstract class BaseAdapter extends android.widget.BaseAdapter {
// private static final String TAG = "BaseAdapter";
-
+
/**
* 管理整个界面的Activity实例
*/
@@ -69,7 +71,7 @@ public synchronized void refresh(List list) {
this.list = list == null ? null : new ArrayList(list);
notifyDataSetChanged();
}
-
+
@Override
public int getCount() {
return list == null ? 0 : list.size();
@@ -89,9 +91,9 @@ public long getItemId(int position) {
return position;
}
-
+
//预加载,可不使用 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
+
protected OnReachViewBorderListener onReachViewBorderListener;
/**设置到达parent的边界的监听
* @param onReachViewBorderListener
@@ -99,7 +101,7 @@ public long getItemId(int position) {
public void setOnReachViewBorderListener(OnReachViewBorderListener onReachViewBorderListener) {
this.onReachViewBorderListener = onReachViewBorderListener;
}
-
+
/**
* 预加载提前数
* @use 可在子类getView前赋值;
@@ -115,14 +117,14 @@ public void setOnReachViewBorderListener(OnReachViewBorderListener onReachViewBo
*/
@Override
public View getView(int position, View convertView, ViewGroup parent) {
- if (onReachViewBorderListener != null && position >= getCount() - 1 - preloadCount) {
+ if (SettingUtil.preload && onReachViewBorderListener != null && position >= getCount() - 1 - preloadCount) {
onReachViewBorderListener.onReach(OnReachViewBorderListener.TYPE_BOTTOM, parent);
}
return convertView;
}
//预加载,可不使用 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-
+
diff --git a/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseHttpListActivity.java b/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseHttpListActivity.java
index 30e705b..38e79ed 100755
--- a/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseHttpListActivity.java
+++ b/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseHttpListActivity.java
@@ -14,6 +14,9 @@
package zuo.biao.library.base;
+import android.view.View;
+import android.widget.BaseAdapter;
+
import java.util.List;
import zuo.biao.library.interfaces.AdapterCallBack;
@@ -23,8 +26,6 @@
import zuo.biao.library.ui.xlistview.XListView;
import zuo.biao.library.ui.xlistview.XListView.IXListViewListener;
import zuo.biao.library.util.Log;
-import android.view.View;
-import android.widget.BaseAdapter;
/**基础http获取列表的Activity
* @author Lemon
@@ -51,7 +52,7 @@ public void initView() {
}
/**设置列表适配器
- * @param adapter if (adapter != null && adapter instanceof BaseHttpAdapter) >> 预加载
+ * @param callBack
*/
@SuppressWarnings("unchecked")
@Override
@@ -123,7 +124,7 @@ public void initEvent() {// 必须调用
lvBaseList.setXListViewListener(this);
}
- /*
+ /*
* @param page 用-page作为requestCode
*/
@Override
@@ -152,8 +153,8 @@ public void run() {
/**
* @param requestCode = -page {@link #getListAsync(int)}
- * @param resultJson
- * @param e
+ * @param resultJson
+ * @param e
*/
@Override
public void onHttpResponse(final int requestCode, final String resultJson, final Exception e) {
@@ -175,7 +176,7 @@ public void run() {
onLoadSucceed(page, array);
}
}
- });
+ });
}
diff --git a/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseListActivity.java b/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseListActivity.java
index 6959c3d..2fb8e65 100644
--- a/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseListActivity.java
+++ b/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseListActivity.java
@@ -35,8 +35,6 @@
* @param 数据模型(model/JavaBean)类
* @param AbsListView的子类(ListView,GridView等)
* @param 管理LV的Adapter
- * @see #onCreateView
- * @see #setContentView
* @see #lvBaseList
* @see #initCache
* @see #initView
@@ -62,8 +60,8 @@ protected void setOnStopLoadListener(OnStopLoadListener onStopLoadListener) {
* @warn 在initData前使用才有效
* @param cacheCallBack
*/
- protected void initCache(CacheCallBack onCacheCallBack) {
- this.cacheCallBack = onCacheCallBack;
+ protected void initCache(CacheCallBack cacheCallBack) {
+ this.cacheCallBack = cacheCallBack;
}
@@ -202,7 +200,7 @@ public void run() {
getListAsync(page);
} else {//从缓存获取数据
onLoadSucceed(page, CacheManager.getInstance().getList(cacheCallBack.getCacheClass()
- , cacheCallBack.getCacheGroup(), loadCacheStart, cacheCallBack.getCacheCount()),
+ , cacheCallBack.getCacheGroup(), loadCacheStart, cacheCallBack.getCacheCount()),
true);
if (page <= HttpManager.PAGE_NUM_0) {
isLoading = false;//stopLoadeData在其它线程isLoading = false;后这个线程里还是true
@@ -215,13 +213,13 @@ public void run() {
/**停止加载数据
* isCache = false;
- * @param page
+ * @param page
*/
public synchronized void stopLoadData(int page) {
stopLoadData(page, false);
}
/**停止加载数据
- * @param page
+ * @param page
* @param isCache
*/
private synchronized void stopLoadData(int page, boolean isCache) {
@@ -248,10 +246,10 @@ private synchronized void stopLoadData(int page, boolean isCache) {
private boolean isSucceed = false;
/**处理列表
- * @param page
+ * @param page
* @param newList 新数据列表
- * @param isCache
- * @return
+ * @param isCache
+ * @return
* @return
*/
public synchronized void handleList(int page, List newList, boolean isCache) {
@@ -350,7 +348,7 @@ public synchronized void onLoadFailed(int page, Exception e) {
private int saveCacheStart;
/**保存缓存
- * @param newList
+ * @param newList
*/
public synchronized void saveCache(List newList) {
if (cacheCallBack == null || newList == null || newList.isEmpty()) {
diff --git a/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseListFragment.java b/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseListFragment.java
index b542efa..6216901 100644
--- a/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseListFragment.java
+++ b/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseListFragment.java
@@ -67,8 +67,8 @@ protected void setOnStopLoadListener(OnStopLoadListener onStopLoadListener) {
* @warn 在initData前使用才有效
* @param cacheCallBack
*/
- protected void initCache(CacheCallBack onCacheCallBack) {
- this.cacheCallBack = onCacheCallBack;
+ protected void initCache(CacheCallBack cacheCallBack) {
+ this.cacheCallBack = cacheCallBack;
}
@@ -170,7 +170,7 @@ public void setAdapter(BA adapter) {
public abstract void setList(List list);
/**显示列表(已在UI线程中)
- * @param list
+ * @param callBack
*/
public void setList(AdapterCallBack callBack) {
if (adapter == null) {
@@ -267,7 +267,7 @@ public void run() {
getListAsync(page);
} else {//从缓存获取数据
onLoadSucceed(page, CacheManager.getInstance().getList(cacheCallBack.getCacheClass()
- , cacheCallBack.getCacheGroup(), loadCacheStart, cacheCallBack.getCacheCount()),
+ , cacheCallBack.getCacheGroup(), loadCacheStart, cacheCallBack.getCacheCount()),
true);
if (page <= HttpManager.PAGE_NUM_0) {
isLoading = false;//stopLoadeData在其它线程isLoading = false;后这个线程里还是true
@@ -280,13 +280,13 @@ public void run() {
/**停止加载数据
* isCache = false;
- * @param page
+ * @param page
*/
public synchronized void stopLoadData(int page) {
stopLoadData(page, false);
}
/**停止加载数据
- * @param page
+ * @param page
* @param isCache
*/
private synchronized void stopLoadData(int page, boolean isCache) {
@@ -313,10 +313,10 @@ private synchronized void stopLoadData(int page, boolean isCache) {
private boolean isSucceed = false;
/**处理列表
- * @param page
+ * @param page
* @param newList 新数据列表
- * @param isCache
- * @return
+ * @param isCache
+ * @return
* @return
*/
public synchronized void handleList(int page, List newList, boolean isCache) {
@@ -415,7 +415,7 @@ public synchronized void onLoadFailed(int page, Exception e) {
private int saveCacheStart;
/**保存缓存
- * @param newList
+ * @param newList
*/
public synchronized void saveCache(List newList) {
if (cacheCallBack == null || newList == null || newList.isEmpty()) {
diff --git a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/base/BaseAdapter.java b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/base/BaseAdapter.java
index 83bb4ce..c199908 100755
--- a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/base/BaseAdapter.java
+++ b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/base/BaseAdapter.java
@@ -14,11 +14,6 @@
package zuo.biao.library.base;
-import java.util.ArrayList;
-import java.util.List;
-
-import zuo.biao.library.interfaces.OnReachViewBorderListener;
-import zuo.biao.library.util.CommonUtil;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
@@ -26,6 +21,13 @@
import android.view.View;
import android.view.ViewGroup;
+import java.util.ArrayList;
+import java.util.List;
+
+import zuo.biao.library.interfaces.OnReachViewBorderListener;
+import zuo.biao.library.util.CommonUtil;
+import zuo.biao.library.util.SettingUtil;
+
/**基础Adapter
*
适用于ListView,GridView等AbsListView的子类
* @author Lemon
@@ -39,7 +41,7 @@
public abstract class BaseAdapter extends android.widget.BaseAdapter {
// private static final String TAG = "BaseAdapter";
-
+
/**
* 管理整个界面的Activity实例
*/
@@ -69,7 +71,7 @@ public synchronized void refresh(List list) {
this.list = list == null ? null : new ArrayList(list);
notifyDataSetChanged();
}
-
+
@Override
public int getCount() {
return list == null ? 0 : list.size();
@@ -89,9 +91,9 @@ public long getItemId(int position) {
return position;
}
-
+
//预加载,可不使用 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
+
protected OnReachViewBorderListener onReachViewBorderListener;
/**设置到达parent的边界的监听
* @param onReachViewBorderListener
@@ -99,7 +101,7 @@ public long getItemId(int position) {
public void setOnReachViewBorderListener(OnReachViewBorderListener onReachViewBorderListener) {
this.onReachViewBorderListener = onReachViewBorderListener;
}
-
+
/**
* 预加载提前数
* @use 可在子类getView前赋值;
@@ -115,14 +117,14 @@ public void setOnReachViewBorderListener(OnReachViewBorderListener onReachViewBo
*/
@Override
public View getView(int position, View convertView, ViewGroup parent) {
- if (onReachViewBorderListener != null && position >= getCount() - 1 - preloadCount) {
+ if (SettingUtil.preload && onReachViewBorderListener != null && position >= getCount() - 1 - preloadCount) {
onReachViewBorderListener.onReach(OnReachViewBorderListener.TYPE_BOTTOM, parent);
}
return convertView;
}
//预加载,可不使用 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-
+
diff --git a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/base/BaseHttpListActivity.java b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/base/BaseHttpListActivity.java
index 4b05e81..38e79ed 100755
--- a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/base/BaseHttpListActivity.java
+++ b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/base/BaseHttpListActivity.java
@@ -14,20 +14,25 @@
package zuo.biao.library.base;
+import android.view.View;
+import android.widget.BaseAdapter;
+
import java.util.List;
+import zuo.biao.library.interfaces.AdapterCallBack;
import zuo.biao.library.interfaces.OnReachViewBorderListener;
import zuo.biao.library.interfaces.OnStopLoadListener;
import zuo.biao.library.manager.HttpManager;
import zuo.biao.library.ui.xlistview.XListView;
import zuo.biao.library.ui.xlistview.XListView.IXListViewListener;
-import android.view.View;
-import android.widget.BaseAdapter;
+import zuo.biao.library.util.Log;
/**基础http获取列表的Activity
* @author Lemon
* @param 数据模型(model/JavaBean)类
* @param 管理XListView的Adapter
+ * @see #getListAsync(int)
+ * @see #onHttpResponse(int, String, Exception)
* @use extends BaseHttpListActivity 并在子类onCreate中lvBaseList.onRefresh();, 具体参考 .UserListFragment
*/
public abstract class BaseHttpListActivity extends BaseListActivity
@@ -43,26 +48,31 @@ public abstract class BaseHttpListActivity extends Ba
public void initView() {
super.initView();
- setAdapter(null);//ListView需要设置adapter才能显示header和footer
+ setList((List) null);//ListView需要设置adapter才能显示header和footer; setAdapter调不到子类方法
}
/**设置列表适配器
- * @param adapter if (adapter != null && adapter instanceof BaseHttpAdapter) >> 预加载
+ * @param callBack
*/
@SuppressWarnings("unchecked")
- public void setAdapter(BA adapter) {
- super.setAdapter(adapter);
- lvBaseList.showFooter(adapter != null);
+ @Override
+ public void setList(AdapterCallBack callBack) {
+ super.setList(callBack);
+ boolean empty = adapter == null || adapter.isEmpty();
+ Log.d(TAG, "setList adapter empty = " + empty);
+ lvBaseList.showFooter(! empty);//放setAdapter中不行,adapter!=null时没有调用setAdapter
if (adapter != null && adapter instanceof zuo.biao.library.base.BaseAdapter) {
- ((zuo.biao.library.base.BaseAdapter) adapter).setOnReachViewBorderListener(new OnReachViewBorderListener(){
- @Override
- public void onReach(int type, View v) {
- if (type == TYPE_BOTTOM) {
- lvBaseList.onLoadMore();
- }
- }
- });
+ ((zuo.biao.library.base.BaseAdapter) adapter).setOnReachViewBorderListener(
+ empty || lvBaseList.isFooterShowing() == false ? null : new OnReachViewBorderListener(){
+
+ @Override
+ public void onReach(int type, View v) {
+ if (type == TYPE_BOTTOM) {
+ lvBaseList.onLoadMore();
+ }
+ }
+ });
}
}
@@ -86,8 +96,8 @@ public void initData() {
}
/**
- * 将Json串转为List(已在非UI线程中)
- * *直接Json.parseArray(json, getCacheClass());可以省去这个方法,但由于可能json不完全符合parseArray条件,所以还是要保留。
+ * 将JSON串转为List(已在非UI线程中)
+ * *直接JSON.parseArray(json, getCacheClass());可以省去这个方法,但由于可能json不完全符合parseArray条件,所以还是要保留。
* *比如json只有其中一部分能作为parseArray的字符串时,必须先提取出这段字符串再parseArray
*/
public abstract List parseArray(String json);
@@ -114,6 +124,12 @@ public void initEvent() {// 必须调用
lvBaseList.setXListViewListener(this);
}
+ /*
+ * @param page 用-page作为requestCode
+ */
+ @Override
+ public abstract void getListAsync(int page);
+
@Override
public void onStopRefresh() {
runUiThread(new Runnable() {
@@ -135,20 +151,32 @@ public void run() {
});
}
+ /**
+ * @param requestCode = -page {@link #getListAsync(int)}
+ * @param resultJson
+ * @param e
+ */
@Override
- public void onHttpResponse(int requestCode, final String resultJson, final Exception e) {
+ public void onHttpResponse(final int requestCode, final String resultJson, final Exception e) {
runThread(TAG + "onHttpResponse", new Runnable() {
@Override
public void run() {
+ int page = 0;
+ if (requestCode > 0) {
+ Log.w(TAG, "requestCode > 0, 应该用BaseListFragment#getListAsync(int page)中的page的负数作为requestCode!");
+ } else {
+ page = - requestCode;
+ }
List array = parseArray(resultJson);
+
if ((array == null || array.isEmpty()) && e != null) {
- onLoadFailed(e);
+ onLoadFailed(page, e);
} else {
- onLoadSucceed(array);
+ onLoadSucceed(page, array);
}
}
- });
+ });
}
diff --git a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/base/BaseHttpListFragment.java b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/base/BaseHttpListFragment.java
index 236d716..661ea45 100755
--- a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/base/BaseHttpListFragment.java
+++ b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/base/BaseHttpListFragment.java
@@ -16,11 +16,13 @@
import java.util.List;
+import zuo.biao.library.interfaces.AdapterCallBack;
import zuo.biao.library.interfaces.OnReachViewBorderListener;
import zuo.biao.library.interfaces.OnStopLoadListener;
import zuo.biao.library.manager.HttpManager;
import zuo.biao.library.ui.xlistview.XListView;
import zuo.biao.library.ui.xlistview.XListView.IXListViewListener;
+import zuo.biao.library.util.Log;
import android.view.View;
import android.widget.BaseAdapter;
@@ -28,6 +30,8 @@
* @author Lemon
* @param 数据模型(model/JavaBean)类
* @param 管理XListView的Adapter
+ * @see #getListAsync(int)
+ * @see #onHttpResponse(int, String, Exception)
* @use extends BaseHttpListFragment 并在子类onCreateView中lvBaseList.onRefresh();, 具体参考 .UserListFragment
*/
public abstract class BaseHttpListFragment extends BaseListFragment
@@ -43,26 +47,31 @@ public abstract class BaseHttpListFragment extends Ba
public void initView() {
super.initView();
- setAdapter(null);//ListView需要设置adapter才能显示header和footer
+ setList((List) null);//ListView需要设置adapter才能显示header和footer; setAdapter调不到子类方法
}
/**设置列表适配器
* @param adapter if (adapter != null && adapter instanceof BaseHttpAdapter) >> 预加载
*/
@SuppressWarnings("unchecked")
- public void setAdapter(BA adapter) {
- super.setAdapter(adapter);
- lvBaseList.showFooter(adapter != null);
+ @Override
+ public void setList(AdapterCallBack callBack) {
+ super.setList(callBack);
+ boolean empty = adapter == null || adapter.isEmpty();
+ Log.d(TAG, "setList adapter empty = " + empty);
+ lvBaseList.showFooter(! empty);//放setAdapter中不行,adapter!=null时没有调用setAdapter
if (adapter != null && adapter instanceof zuo.biao.library.base.BaseAdapter) {
- ((zuo.biao.library.base.BaseAdapter) adapter).setOnReachViewBorderListener(new OnReachViewBorderListener(){
- @Override
- public void onReach(int type, View v) {
- if (type == TYPE_BOTTOM) {
- lvBaseList.onLoadMore();
- }
- }
- });
+ ((zuo.biao.library.base.BaseAdapter) adapter).setOnReachViewBorderListener(
+ empty || lvBaseList.isFooterShowing() == false ? null : new OnReachViewBorderListener(){
+
+ @Override
+ public void onReach(int type, View v) {
+ if (type == TYPE_BOTTOM) {
+ lvBaseList.onLoadMore();
+ }
+ }
+ });
}
}
@@ -86,8 +95,8 @@ public void initData() {
}
/**
- * 将Json串转为List(已在非UI线程中)
- * *直接Json.parseArray(json, getCacheClass());可以省去这个方法,但由于可能json不完全符合parseArray条件,所以还是要保留。
+ * 将JSON串转为List(已在非UI线程中)
+ * *直接JSON.parseArray(json, getCacheClass());可以省去这个方法,但由于可能json不完全符合parseArray条件,所以还是要保留。
* *比如json只有其中一部分能作为parseArray的字符串时,必须先提取出这段字符串再parseArray
*/
public abstract List parseArray(String json);
@@ -114,6 +123,12 @@ public void initEvent() {// 必须调用
lvBaseList.setXListViewListener(this);
}
+ /*
+ * @param page 用-page作为requestCode
+ */
+ @Override
+ public abstract void getListAsync(int page);
+
@Override
public void onStopRefresh() {
runUiThread(new Runnable() {
@@ -135,22 +150,34 @@ public void run() {
});
}
+ /**
+ * @param requestCode = -page {@link #getListAsync(int)}
+ * @param resultJson
+ * @param e
+ */
@Override
- public void onHttpResponse(int requestCode, final String resultJson, final Exception e) {
+ public void onHttpResponse(final int requestCode, final String resultJson, final Exception e) {
runThread(TAG + "onHttpResponse", new Runnable() {
@Override
public void run() {
+ int page = 0;
+ if (requestCode > 0) {
+ Log.w(TAG, "requestCode > 0, 应该用BaseListFragment#getListAsync(int page)中的page的负数作为requestCode!");
+ } else {
+ page = - requestCode;
+ }
List array = parseArray(resultJson);
+
if ((array == null || array.isEmpty()) && e != null) {
- onLoadFailed(e);
+ onLoadFailed(page, e);
} else {
- onLoadSucceed(array);
+ onLoadSucceed(page, array);
}
}
});
}
-
+
// 系统自带监听方法<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
diff --git a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/base/BaseListActivity.java b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/base/BaseListActivity.java
index 2565c06..2fb8e65 100644
--- a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/base/BaseListActivity.java
+++ b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/base/BaseListActivity.java
@@ -21,11 +21,11 @@
import zuo.biao.library.R;
import zuo.biao.library.interfaces.AdapterCallBack;
import zuo.biao.library.interfaces.CacheCallBack;
-import zuo.biao.library.interfaces.OnResultListener;
import zuo.biao.library.interfaces.OnStopLoadListener;
import zuo.biao.library.manager.CacheManager;
import zuo.biao.library.manager.HttpManager;
import zuo.biao.library.util.Log;
+import zuo.biao.library.util.SettingUtil;
import zuo.biao.library.util.StringUtil;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
@@ -60,8 +60,8 @@ protected void setOnStopLoadListener(OnStopLoadListener onStopLoadListener) {
* @warn 在initData前使用才有效
* @param cacheCallBack
*/
- protected void initCache(CacheCallBack onCacheCallBack) {
- this.cacheCallBack = onCacheCallBack;
+ protected void initCache(CacheCallBack cacheCallBack) {
+ this.cacheCallBack = cacheCallBack;
}
@@ -101,7 +101,7 @@ public void setAdapter(BA adapter) {
* @param list
*/
public abstract void setList(List list);
-
+
/**显示列表(已在UI线程中)
* @param list
*/
@@ -111,31 +111,6 @@ public void setList(AdapterCallBack callBack) {
}
callBack.refreshAdapter();
}
-
- /**显示列表(已在UI线程中),异步加载列表内容,提高列表流畅性
- * @param list
- * @param listener
- * @must cacheCallBack != null 且 cacheCallBack.getCacheId(data) 有正确返回值。可以通过initCache设置cacheCallBack
- * @use 调用后使用 .CacheAdapter 加载idList
- */
- public void setListAsync(final List list, final OnResultListener> listener) {
- runThread(TAG + "setListAsync", new Runnable() {
-
- @Override
- public void run() {
- final List idList = new ArrayList();
- for (T data : list) {
- idList.add(cacheCallBack.getCacheId(data));
- }
- runUiThread(new Runnable() {
- @Override
- public void run() {
- listener.onResult(idList);
- }
- });
- }
- });
- }
// UI显示区(操作UI,但不存在数据获取或处理代码,也不存在事件监听代码)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -151,34 +126,36 @@ public void run() {
// Data数据区(存在数据获取或处理代码,但不存在事件监听代码)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- protected boolean isToLoadCache;
- protected boolean isToSaveCache;
+ private boolean isToSaveCache;
+ private boolean isToLoadCache;
@Override
public void initData() {// 必须调用
-
- isToSaveCache = cacheCallBack != null && cacheCallBack.getCacheClass() != null;
+
+ isToSaveCache = SettingUtil.cache && cacheCallBack != null && cacheCallBack.getCacheClass() != null;
isToLoadCache = isToSaveCache && StringUtil.isNotEmpty(cacheCallBack.getCacheGroup(), true);
}
/**
* 获取列表,在非UI线程中
* @must 获取成功后调用onLoadSucceed
- * @param pageNum
+ * @param page 在onLoadSucceed中传回来保证一致性
*/
- public abstract void getListAsync(int pageNum);
+ public abstract void getListAsync(int page);
- public void loadData(int pageNum) {
- loadData(pageNum, isToLoadCache);
+
+ public void loadData(int page) {
+ loadData(page, isToLoadCache);
}
+
+ /**
+ * 数据列表
+ */
+ private List list;
/**
* 正在加载
*/
protected boolean isLoading = false;
- // /**线程不同步导致获取的值不可靠
- // * 正在加载缓存
- // */
- // protected boolean isLoadingCache = false;
/**
* 还有更多可加载数据
*/
@@ -186,49 +163,49 @@ public void loadData(int pageNum) {
/**
* 加载页码,每页对应一定数量的数据
*/
- protected int pageNum;
- protected int loadCacheStart;
+ private int page;
+ private int loadCacheStart;
/**加载数据,用getListAsync方法发请求获取数据
- * @param pageNum_
- * @param isToLoadCache
+ * @param page_
+ * @param isCache
*/
- public void loadData(int pageNum_, final boolean isToLoadCache) {
- Log.i(TAG, "loadData pageNum_ = " + pageNum_ + "; isToLoadCache = " + isToLoadCache);
+ private void loadData(int page_, final boolean isCache) {
if (isLoading) {
Log.w(TAG, "loadData isLoading >> return;");
return;
}
isLoading = true;
+ isSucceed = false;
- if (pageNum_ <= HttpManager.PAGE_NUM_0) {
- pageNum_ = HttpManager.PAGE_NUM_0;
+ if (page_ <= HttpManager.PAGE_NUM_0) {
+ page_ = HttpManager.PAGE_NUM_0;
isHaveMore = true;
loadCacheStart = 0;//使用则可像网络正常情况下的重载,不使用则在网络异常情况下不重载(导致重载后加载数据下移)
} else {
if (isHaveMore == false) {
- stopLoadData();
+ stopLoadData(page_);
return;
}
loadCacheStart = list == null ? 0 : list.size();
}
- this.pageNum = pageNum_;
+ this.page = page_;
+ Log.i(TAG, "loadData page_ = " + page_ + "; isCache = " + isCache
+ + "; isHaveMore = " + isHaveMore + "; loadCacheStart = " + loadCacheStart);
runThread(TAG + "loadData", new Runnable() {
@Override
public void run() {
- //从缓存获取数据
- List newList = isToLoadCache == false ? null : CacheManager.getInstance().getList(
- cacheCallBack.getCacheClass(), cacheCallBack.getCacheGroup(), loadCacheStart);
- if (newList == null || newList.isEmpty()) {
- getListAsync(pageNum);
- return;
- }
-
- onLoadSucceed(newList, true);
- if (pageNum <= HttpManager.PAGE_NUM_0) {
- isLoading = false;//stopLoadData在其它线程isLoading = false;后这个线程里还是true
- loadData(pageNum, false);
+ if (isCache == false) {//从网络获取数据
+ getListAsync(page);
+ } else {//从缓存获取数据
+ onLoadSucceed(page, CacheManager.getInstance().getList(cacheCallBack.getCacheClass()
+ , cacheCallBack.getCacheGroup(), loadCacheStart, cacheCallBack.getCacheCount()),
+ true);
+ if (page <= HttpManager.PAGE_NUM_0) {
+ isLoading = false;//stopLoadeData在其它线程isLoading = false;后这个线程里还是true
+ loadData(page, false);
+ }
}
}
});
@@ -236,14 +213,16 @@ public void run() {
/**停止加载数据
* isCache = false;
+ * @param page
*/
- public synchronized void stopLoadData() {
- stopLoadData(false);
+ public synchronized void stopLoadData(int page) {
+ stopLoadData(page, false);
}
/**停止加载数据
+ * @param page
* @param isCache
*/
- public synchronized void stopLoadData(boolean isCache) {
+ private synchronized void stopLoadData(int page, boolean isCache) {
Log.i(TAG, "stopLoadData isCache = " + isCache);
isLoading = false;
dismissProgressDialog();
@@ -257,96 +236,100 @@ public synchronized void stopLoadData(boolean isCache) {
Log.w(TAG, "stopLoadData onStopLoadListener == null >> return;");
return;
}
- if (pageNum <= HttpManager.PAGE_NUM_0) {
- onStopLoadListener.onStopRefresh();
- } else {
+ onStopLoadListener.onStopRefresh();
+ if (page > HttpManager.PAGE_NUM_0) {
onStopLoadListener.onStopLoadMore(isHaveMore);
}
}
- /**
- * 数据列表
- */
- protected List list;
- /**
- * 新数据列表
- */
- protected List newList = null;
+ private boolean isSucceed = false;
/**处理列表
- * @param newList_ 新数据列表
- * @param isCache
+ * @param page
+ * @param newList 新数据列表
+ * @param isCache
+ * @return
* @return
*/
- public synchronized void handleList(List newList_, boolean isCache) {
- this.newList = newList_;
+ public synchronized void handleList(int page, List newList, boolean isCache) {
if (newList == null) {
newList = new ArrayList();
}
- Log.i(TAG, "handleList newList.size = " + newList.size() + "; isCache = " + isCache);
+ isSucceed = ! newList.isEmpty();
+ Log.i(TAG, "\n\n<<<<<<<<<<<<<<<<<\n handleList newList.size = " + newList.size() + "; isCache = " + isCache
+ + "; page = " + page + "; isSucceed = " + isSucceed);
- if (pageNum <= HttpManager.PAGE_NUM_0) {
+ if (page <= HttpManager.PAGE_NUM_0) {
+ Log.i(TAG, "handleList page <= HttpManager.PAGE_NUM_0 >>>> ");
saveCacheStart = 0;
- list = newList;
- if (isCache == false && list != null && list.size() > 0) {
+ list = new ArrayList(newList);
+ if (isCache == false && list.isEmpty() == false) {
+ Log.i(TAG, "handleList isCache == false && list.isEmpty() == false >> isToLoadCache = false;");
isToLoadCache = false;
}
} else {
- saveCacheStart = list == null ? 0 : list.size();
- if (newList.size() <= 0) {
- isHaveMore = false;
- } else {
- if (list == null) {
- list = new ArrayList();
- }
+ Log.i(TAG, "handleList page > HttpManager.PAGE_NUM_0 >>>> ");
+ if (list == null) {
+ list = new ArrayList();
+ }
+ saveCacheStart = list.size();
+ isHaveMore = ! newList.isEmpty();
+ if (isHaveMore) {
list.addAll(newList);
}
}
+
+ Log.i(TAG, "handleList list.size = " + list.size() + "; isHaveMore = " + isHaveMore
+ + "; isToLoadCache = " + isToLoadCache + "; saveCacheStart = " + saveCacheStart
+ + "\n>>>>>>>>>>>>>>>>>>\n\n");
}
/**加载成功
* isCache = false;
+ * @param page
* @param newList
*/
- public synchronized void onLoadSucceed(final List newList) {
- onLoadSucceed(newList, false);
+ public synchronized void onLoadSucceed(final int page, final List newList) {
+ onLoadSucceed(page, newList, false);
}
/**加载成功
+ * @param page
* @param newList
* @param isCache newList是否为缓存
*/
- public synchronized void onLoadSucceed(final List newList, final boolean isCache) {
+ private synchronized void onLoadSucceed(final int page, final List newList, final boolean isCache) {
runThread(TAG + "onLoadSucceed", new Runnable() {
@Override
public void run() {
- Log.i(TAG, "onLoadSucceed isCache = " + isCache + " >> handleList...");
- handleList(newList, isCache);
-
- if (isToSaveCache && isCache == false) {
- saveCache();
- }
+ Log.i(TAG, "onLoadSucceed page = " + page + "; isCache = " + isCache + " >> handleList...");
+ handleList(page, newList, isCache);
runUiThread(new Runnable() {
@Override
public void run() {
+ stopLoadData(page, isCache);
setList(list);
- stopLoadData(isCache);
}
});
+
+ if (isToSaveCache && isCache == false) {
+ saveCache(newList);
+ }
}
});
}
/**加载失败
+ * @param page
* @param e
*/
- public synchronized void onLoadFailed(Exception e) {
- Log.e(TAG, "onLoadFailed e = " + e);
- stopLoadData();
+ public synchronized void onLoadFailed(int page, Exception e) {
+ Log.e(TAG, "onLoadFailed page = " + page + "; e = " + (e == null ? null : e.getMessage()));
+ stopLoadData(page);
showShortToast(R.string.get_failed);
}
@@ -354,21 +337,22 @@ public synchronized void onLoadFailed(Exception e) {
//缓存<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- /**
- * 获取缓存每页数量
- * @return > 0 ?缓存 : 不缓存
- */
- public int getCachePageSize() {
- //让给服务器返回每页数量为pageSize的数据,不行的话在子类重写 Math.max(10, newList == null ? 0 : newList.size());
- return CacheManager.MAX_PAGE_SIZE;
- }
+ // /**
+ // * 获取缓存每页数量
+ // * @return > 0 ?缓存 : 不缓存
+ // */
+ // public int getCacheCount() {
+ // //让给服务器返回每页数量为count的数据,不行的话在子类重写 Math.max(10, newList == null ? 0 : newList.size());
+ // return CacheManager.MAX_PAGE_SIZE;
+ // }
private int saveCacheStart;
/**保存缓存
+ * @param newList
*/
- public synchronized void saveCache() {
- if (cacheCallBack == null || newList == null) {
- Log.e(TAG, "saveCache cacheCallBack == null || newList == null >> return;");
+ public synchronized void saveCache(List newList) {
+ if (cacheCallBack == null || newList == null || newList.isEmpty()) {
+ Log.e(TAG, "saveCache cacheCallBack == null || newList == null || newList.isEmpty() >> return;");
return;
}
@@ -380,7 +364,7 @@ public synchronized void saveCache() {
}
CacheManager.getInstance().saveList(cacheCallBack.getCacheClass(), cacheCallBack.getCacheGroup()
- , map, saveCacheStart, cacheCallBack.getCachePageSize());
+ , map, saveCacheStart, cacheCallBack.getCacheCount());
}
//缓存>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -414,7 +398,11 @@ public void onRefresh() {
/**加载更多
*/
public void onLoadMore() {
- loadData(pageNum + 1);
+ if (isSucceed == false && page <= HttpManager.PAGE_NUM_0) {
+ Log.w(TAG, "onLoadMore isSucceed == false && page <= HttpManager.PAGE_NUM_0 >> return;");
+ return;
+ }
+ loadData(page + (isSucceed ? 1 : 0));
}
@@ -425,16 +413,15 @@ public void onLoadMore() {
@Override
protected void onDestroy() {
- stopLoadData();
+ isLoading = false;
+ isHaveMore = false;
+ isToSaveCache = false;
+ isToLoadCache = false;
super.onDestroy();
- isLoading = false;
- isHaveMore = true;
lvBaseList = null;
-
list = null;
- newList = null;
onStopLoadListener = null;
cacheCallBack = null;
diff --git a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/base/BaseListFragment.java b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/base/BaseListFragment.java
index 1fbf81f..6216901 100644
--- a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/base/BaseListFragment.java
+++ b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/base/BaseListFragment.java
@@ -21,11 +21,11 @@
import zuo.biao.library.R;
import zuo.biao.library.interfaces.AdapterCallBack;
import zuo.biao.library.interfaces.CacheCallBack;
-import zuo.biao.library.interfaces.OnResultListener;
import zuo.biao.library.interfaces.OnStopLoadListener;
import zuo.biao.library.manager.CacheManager;
import zuo.biao.library.manager.HttpManager;
import zuo.biao.library.util.Log;
+import zuo.biao.library.util.SettingUtil;
import zuo.biao.library.util.StringUtil;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -67,8 +67,8 @@ protected void setOnStopLoadListener(OnStopLoadListener onStopLoadListener) {
* @warn 在initData前使用才有效
* @param cacheCallBack
*/
- protected void initCache(CacheCallBack onCacheCallBack) {
- this.cacheCallBack = onCacheCallBack;
+ protected void initCache(CacheCallBack cacheCallBack) {
+ this.cacheCallBack = cacheCallBack;
}
@@ -170,7 +170,7 @@ public void setAdapter(BA adapter) {
public abstract void setList(List list);
/**显示列表(已在UI线程中)
- * @param list
+ * @param callBack
*/
public void setList(AdapterCallBack callBack) {
if (adapter == null) {
@@ -178,33 +178,6 @@ public void setList(AdapterCallBack callBack) {
}
callBack.refreshAdapter();
}
-
- /**显示列表(已在UI线程中),异步加载列表内容,提高列表流畅性
- * @param list
- * @param listener
- * @must cacheCallBack != null 且 cacheCallBack.getCacheId(data) 有正确返回值。可以通过initCache设置cacheCallBack
- * @use 调用后使用 .CacheAdapter 加载idList
- */
- public void setListAsync(final List list, final OnResultListener> listener) {
- runThread(TAG + "setListAsync", new Runnable() {
-
- @Override
- public void run() {
- final List idList = new ArrayList();
- if (list != null) {
- for (T data : list) {
- idList.add(cacheCallBack.getCacheId(data));
- }
- }
- runUiThread(new Runnable() {
- @Override
- public void run() {
- listener.onResult(idList);
- }
- });
- }
- });
- }
// UI显示区(操作UI,但不存在数据获取或处理代码,也不存在事件监听代码)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -220,34 +193,36 @@ public void run() {
// Data数据区(存在数据获取或处理代码,但不存在事件监听代码)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- protected boolean isToLoadCache;
- protected boolean isToSaveCache;
+ private boolean isToSaveCache;
+ private boolean isToLoadCache;
@Override
public void initData() {// 必须调用
- isToSaveCache = cacheCallBack != null && cacheCallBack.getCacheClass() != null;
+ isToSaveCache = SettingUtil.cache && cacheCallBack != null && cacheCallBack.getCacheClass() != null;
isToLoadCache = isToSaveCache && StringUtil.isNotEmpty(cacheCallBack.getCacheGroup(), true);
}
/**
* 获取列表,在非UI线程中
* @must 获取成功后调用onLoadSucceed
- * @param pageNum
+ * @param page 在onLoadSucceed中传回来保证一致性
*/
- public abstract void getListAsync(int pageNum);
+ public abstract void getListAsync(int page);
- public void loadData(int pageNum) {
- loadData(pageNum, isToLoadCache);
+
+ public void loadData(int page) {
+ loadData(page, isToLoadCache);
}
+
+ /**
+ * 数据列表
+ */
+ private List list;
/**
* 正在加载
*/
protected boolean isLoading = false;
- // /**线程不同步导致获取的值不可靠
- // * 正在加载缓存
- // */
- // protected boolean isLoadingCache = false;
/**
* 还有更多可加载数据
*/
@@ -255,49 +230,49 @@ public void loadData(int pageNum) {
/**
* 加载页码,每页对应一定数量的数据
*/
- protected int pageNum;
- protected int loadCacheStart;
+ private int page;
+ private int loadCacheStart;
/**加载数据,用getListAsync方法发请求获取数据
- * @param pageNum_
- * @param isToLoadCache
+ * @param page_
+ * @param isCache
*/
- public void loadData(int pageNum_, final boolean isToLoadCache) {
- Log.i(TAG, "loadData pageNum_ = " + pageNum_ + "; isToLoadCache = " + isToLoadCache);
+ private void loadData(int page_, final boolean isCache) {
if (isLoading) {
Log.w(TAG, "loadData isLoading >> return;");
return;
}
isLoading = true;
+ isSucceed = false;
- if (pageNum_ <= HttpManager.PAGE_NUM_0) {
- pageNum_ = HttpManager.PAGE_NUM_0;
+ if (page_ <= HttpManager.PAGE_NUM_0) {
+ page_ = HttpManager.PAGE_NUM_0;
isHaveMore = true;
loadCacheStart = 0;//使用则可像网络正常情况下的重载,不使用则在网络异常情况下不重载(导致重载后加载数据下移)
} else {
if (isHaveMore == false) {
- stopLoadData();
+ stopLoadData(page_);
return;
}
loadCacheStart = list == null ? 0 : list.size();
}
- this.pageNum = pageNum_;
+ this.page = page_;
+ Log.i(TAG, "loadData page_ = " + page_ + "; isCache = " + isCache
+ + "; isHaveMore = " + isHaveMore + "; loadCacheStart = " + loadCacheStart);
runThread(TAG + "loadData", new Runnable() {
@Override
public void run() {
- //从缓存获取数据
- List newList = isToLoadCache == false ? null : CacheManager.getInstance().getList(
- cacheCallBack.getCacheClass(), cacheCallBack.getCacheGroup(), loadCacheStart);
- if (newList == null || newList.isEmpty()) {
- getListAsync(pageNum);
- return;
- }
-
- onLoadSucceed(newList, true);
- if (pageNum <= HttpManager.PAGE_NUM_0) {
- isLoading = false;//stopLoadData在其它线程isLoading = false;后这个线程里还是true
- loadData(pageNum, false);
+ if (isCache == false) {//从网络获取数据
+ getListAsync(page);
+ } else {//从缓存获取数据
+ onLoadSucceed(page, CacheManager.getInstance().getList(cacheCallBack.getCacheClass()
+ , cacheCallBack.getCacheGroup(), loadCacheStart, cacheCallBack.getCacheCount()),
+ true);
+ if (page <= HttpManager.PAGE_NUM_0) {
+ isLoading = false;//stopLoadeData在其它线程isLoading = false;后这个线程里还是true
+ loadData(page, false);
+ }
}
}
});
@@ -305,14 +280,16 @@ public void run() {
/**停止加载数据
* isCache = false;
+ * @param page
*/
- public synchronized void stopLoadData() {
- stopLoadData(false);
+ public synchronized void stopLoadData(int page) {
+ stopLoadData(page, false);
}
/**停止加载数据
+ * @param page
* @param isCache
*/
- public synchronized void stopLoadData(boolean isCache) {
+ private synchronized void stopLoadData(int page, boolean isCache) {
Log.i(TAG, "stopLoadData isCache = " + isCache);
isLoading = false;
dismissProgressDialog();
@@ -326,96 +303,100 @@ public synchronized void stopLoadData(boolean isCache) {
Log.w(TAG, "stopLoadData onStopLoadListener == null >> return;");
return;
}
- if (pageNum <= HttpManager.PAGE_NUM_0) {
- onStopLoadListener.onStopRefresh();
- } else {
+ onStopLoadListener.onStopRefresh();
+ if (page > HttpManager.PAGE_NUM_0) {
onStopLoadListener.onStopLoadMore(isHaveMore);
}
}
- /**
- * 数据列表
- */
- protected List list;
- /**
- * 新数据列表
- */
- protected List newList = null;
+ private boolean isSucceed = false;
/**处理列表
- * @param newList_ 新数据列表
- * @param isCache
+ * @param page
+ * @param newList 新数据列表
+ * @param isCache
+ * @return
* @return
*/
- public synchronized void handleList(List newList_, boolean isCache) {
- this.newList = newList_;
+ public synchronized void handleList(int page, List newList, boolean isCache) {
if (newList == null) {
newList = new ArrayList();
}
- Log.i(TAG, "handleList newList.size = " + newList.size() + "; isCache = " + isCache);
+ isSucceed = ! newList.isEmpty();
+ Log.i(TAG, "\n\n<<<<<<<<<<<<<<<<<\n handleList newList.size = " + newList.size() + "; isCache = " + isCache
+ + "; page = " + page + "; isSucceed = " + isSucceed);
- if (pageNum <= HttpManager.PAGE_NUM_0) {
+ if (page <= HttpManager.PAGE_NUM_0) {
+ Log.i(TAG, "handleList page <= HttpManager.PAGE_NUM_0 >>>> ");
saveCacheStart = 0;
- list = newList;
- if (isCache == false && list != null && list.size() > 0) {
+ list = new ArrayList(newList);
+ if (isCache == false && list.isEmpty() == false) {
+ Log.i(TAG, "handleList isCache == false && list.isEmpty() == false >> isToLoadCache = false;");
isToLoadCache = false;
}
} else {
- saveCacheStart = list == null ? 0 : list.size();
- if (newList.size() <= 0) {
- isHaveMore = false;
- } else {
- if (list == null) {
- list = new ArrayList();
- }
+ Log.i(TAG, "handleList page > HttpManager.PAGE_NUM_0 >>>> ");
+ if (list == null) {
+ list = new ArrayList();
+ }
+ saveCacheStart = list.size();
+ isHaveMore = ! newList.isEmpty();
+ if (isHaveMore) {
list.addAll(newList);
}
}
+
+ Log.i(TAG, "handleList list.size = " + list.size() + "; isHaveMore = " + isHaveMore
+ + "; isToLoadCache = " + isToLoadCache + "; saveCacheStart = " + saveCacheStart
+ + "\n>>>>>>>>>>>>>>>>>>\n\n");
}
/**加载成功
* isCache = false;
+ * @param page
* @param newList
*/
- public synchronized void onLoadSucceed(final List newList) {
- onLoadSucceed(newList, false);
+ public synchronized void onLoadSucceed(final int page, final List newList) {
+ onLoadSucceed(page, newList, false);
}
/**加载成功
+ * @param page
* @param newList
* @param isCache newList是否为缓存
*/
- public synchronized void onLoadSucceed(final List newList, final boolean isCache) {
+ private synchronized void onLoadSucceed(final int page, final List newList, final boolean isCache) {
runThread(TAG + "onLoadSucceed", new Runnable() {
@Override
public void run() {
- Log.i(TAG, "onLoadSucceed isCache = " + isCache + " >> handleList...");
- handleList(newList, isCache);
-
- if (isToSaveCache && isCache == false) {
- saveCache();
- }
+ Log.i(TAG, "onLoadSucceed page = " + page + "; isCache = " + isCache + " >> handleList...");
+ handleList(page, newList, isCache);
runUiThread(new Runnable() {
@Override
public void run() {
+ stopLoadData(page, isCache);
setList(list);
- stopLoadData(isCache);
}
});
+
+ if (isToSaveCache && isCache == false) {
+ saveCache(newList);
+ }
}
});
}
/**加载失败
+ * @param page
* @param e
*/
- public synchronized void onLoadFailed(Exception e) {
- Log.e(TAG, "onLoadFailed e = " + e);
- stopLoadData();
+ public synchronized void onLoadFailed(int page, Exception e) {
+ Log.e(TAG, "onLoadFailed page = " + page + "; e = " + (e == null ? null : e.getMessage()));
+ stopLoadData(page);
showShortToast(R.string.get_failed);
}
@@ -423,21 +404,22 @@ public synchronized void onLoadFailed(Exception e) {
//缓存<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- /**
- * 获取缓存每页数量
- * @return > 0 ?缓存 : 不缓存
- */
- public int getCachePageSize() {
- //让给服务器返回每页数量为pageSize的数据,不行的话在子类重写 Math.max(10, newList == null ? 0 : newList.size());
- return CacheManager.MAX_PAGE_SIZE;
- }
+ // /**
+ // * 获取缓存每页数量
+ // * @return > 0 ?缓存 : 不缓存
+ // */
+ // public int getCacheCount() {
+ // //让给服务器返回每页数量为count的数据,不行的话在子类重写 Math.max(10, newList == null ? 0 : newList.size());
+ // return CacheManager.MAX_PAGE_SIZE;
+ // }
private int saveCacheStart;
/**保存缓存
+ * @param newList
*/
- public synchronized void saveCache() {
- if (cacheCallBack == null || newList == null) {
- Log.e(TAG, "saveCache cacheCallBack == null || newList == null >> return;");
+ public synchronized void saveCache(List newList) {
+ if (cacheCallBack == null || newList == null || newList.isEmpty()) {
+ Log.e(TAG, "saveCache cacheCallBack == null || newList == null || newList.isEmpty() >> return;");
return;
}
@@ -449,7 +431,7 @@ public synchronized void saveCache() {
}
CacheManager.getInstance().saveList(cacheCallBack.getCacheClass(), cacheCallBack.getCacheGroup()
- , map, saveCacheStart, cacheCallBack.getCachePageSize());
+ , map, saveCacheStart, cacheCallBack.getCacheCount());
}
//缓存>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -483,7 +465,11 @@ public void onRefresh() {
/**加载更多
*/
public void onLoadMore() {
- loadData(pageNum + 1);
+ if (isSucceed == false && page <= HttpManager.PAGE_NUM_0) {
+ Log.w(TAG, "onLoadMore isSucceed == false && page <= HttpManager.PAGE_NUM_0 >> return;");
+ return;
+ }
+ loadData(page + (isSucceed ? 1 : 0));
}
@@ -494,16 +480,15 @@ public void onLoadMore() {
@Override
public void onDestroy() {
- stopLoadData();
+ isLoading = false;
+ isHaveMore = false;
+ isToSaveCache = false;
+ isToLoadCache = false;
super.onDestroy();
- isLoading = false;
- isHaveMore = true;
lvBaseList = null;
-
list = null;
- newList = null;
onStopLoadListener = null;
cacheCallBack = null;
diff --git a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/interfaces/CacheCallBack.java b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/interfaces/CacheCallBack.java
index f5b5e59..d227577 100644
--- a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/interfaces/CacheCallBack.java
+++ b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/interfaces/CacheCallBack.java
@@ -44,6 +44,6 @@ public interface CacheCallBack {
* 获取缓存每页数量
* @return > 0 ?缓存 : 不缓存
*/
- int getCachePageSize();
+ int getCacheCount();
}
\ No newline at end of file
diff --git a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/manager/Cache.java b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/manager/Cache.java
index 3982fb8..7fa020b 100755
--- a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/manager/Cache.java
+++ b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/manager/Cache.java
@@ -19,7 +19,7 @@
import java.util.Map;
import java.util.Set;
-import zuo.biao.library.util.Json;
+import zuo.biao.library.util.JSON;
import zuo.biao.library.util.Log;
import zuo.biao.library.util.StringUtil;
import android.content.Context;
@@ -84,7 +84,7 @@ public void save(String key, T value) {
}
key = StringUtil.getTrimedString(key);
- sp.edit().remove(key).putString(key, Json.toJSONString(value)).commit();
+ sp.edit().remove(key).putString(key, JSON.toJSONString(value)).commit();
}
/**判断是否已存
@@ -111,7 +111,7 @@ public T get(String key) {
return null;
}
- return Json.parseObject(sp.getString(StringUtil.getTrimedString(key), null), clazz);
+ return JSON.parseObject(sp.getString(StringUtil.getTrimedString(key), null), clazz);
}
@@ -178,7 +178,7 @@ public List getAllValueList() {
List list = new ArrayList();
T data;
for (String value : map.values()) {
- data = Json.parseObject(value, clazz);
+ data = JSON.parseObject(value, clazz);
if (data != null) {
list.add(data);
}
@@ -202,4 +202,4 @@ public void remove(String key) {
}
-}
\ No newline at end of file
+}
diff --git a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/manager/CacheManager.java b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/manager/CacheManager.java
index 589df08..7819b3e 100755
--- a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/manager/CacheManager.java
+++ b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/manager/CacheManager.java
@@ -20,7 +20,7 @@
import zuo.biao.library.base.BaseApplication;
import zuo.biao.library.util.DataKeeper;
-import zuo.biao.library.util.Json;
+import zuo.biao.library.util.JSON;
import zuo.biao.library.util.Log;
import zuo.biao.library.util.StringUtil;
import android.content.Context;
@@ -46,7 +46,12 @@ public static synchronized CacheManager getInstance() {
if (manager == null) {
manager = new CacheManager(BaseApplication.getInstance());
}
- return manager;
+ synchronized (CacheManager.class) {
+ if (manager == null) {
+ manager = new CacheManager(BaseApplication.getInstance());
+ }
+ return manager;
+ }
}
@@ -70,10 +75,9 @@ public String getListPath(Class clazz) {
* @param group
* @return
*/
- public String getGroupPath(Class clazz, String group) {
+ public String getGroupPath(Class clazz) {
String classPath = getClassPath(clazz);
- return StringUtil.isNotEmpty(classPath, true) == false || StringUtil.isNotEmpty(group, true) == false
- ? null : classPath + KEY_GROUP_ + StringUtil.getTrimedString(group);
+ return StringUtil.isNotEmpty(classPath, true) == false ? null : classPath + KEY_GROUP;
}
private SharedPreferences getSharedPreferences(String path) {
@@ -90,15 +94,7 @@ private SharedPreferences getSharedPreferences(String path) {
/**
* 数据分组,自定义
*/
- public static final String KEY_GROUP_ = "GROUP_";
- /**
- * 分组中id列表每页数量
- */
- public static final String KEY_PAGE_SIZE = "KEY_PAGE_SIZE";
- /**
- * 分组中id列表,用json string的形式储存(避免排序问题)
- */
- public static final String KEY_ID_LIST = "KEY_ID_LIST";
+ public static final String KEY_GROUP = "GROUP";
/**
* 分组中列表每页最大数量
*/
@@ -109,15 +105,15 @@ private SharedPreferences getSharedPreferences(String path) {
* @return
*/
public List getAllList(Class clazz) {
- return getList(clazz, -1);
+ return getList(clazz, -1, 0);
}
/**获取列表
* @param clazz
* @param start
* @return
*/
- public List getList(Class clazz, int start) {
- return getList(clazz, null, start);
+ public List getList(Class clazz, int start, int pageSize) {
+ return getList(clazz, null, start, pageSize);
}
/**获取列表
* @param clazz
@@ -125,37 +121,41 @@ public List getList(Class clazz, int start) {
* @return
*/
public List getAllList(Class clazz, String group) {
- return StringUtil.isNotEmpty(group, true) ? getList(clazz, group, -1) : null;
+ return StringUtil.isNotEmpty(group, true) ? getList(clazz, group, -1, 0) : null;
}
/**获取列表
* @param clazz
* @param group == null ? all : in group
* @param start < 0 ? all in group : subList(start, end)
+ * @param count > 0 ? all in group : subList(start, end)
* @return
*/
- public List getList(Class clazz, String group, int start) {
- Log.i(TAG, "getList group = " + group +"; start = " + start);
-
- Cache cacheList = clazz == null ? null : new Cache(context, clazz, getClassPath(clazz)
- + KEY_LIST);
+ public List getList(Class clazz, String group, int start, int count) {
+ Log.i(TAG, "\n\n<<<<<<<<<<<<<<<<\ngetList group = " + group +"; start = " + start + "; count = " + count);
+ if (count <= 0 || clazz == null) {
+ Log.e(TAG, "getList count <= 0 || clazz == null >> return null;");
+ return null;
+ }
+ Cache cacheList = new Cache(context, clazz, getClassPath(clazz) + KEY_LIST);
if (StringUtil.isNotEmpty(group, true) == false) {
- return cacheList == null ? null : cacheList.getValueList(start, start + 10);
+ return cacheList == null ? null : cacheList.getValueList(start, start + count);
}
List idList = getIdList(clazz, group);
- if (idList == null) {
- Log.e(TAG, "getList idList == null >> return null;");
+ final int totalCount = idList == null ? 0 : idList.size();
+ Log.i(TAG, "getList idList.size() = " + totalCount);
+ if (totalCount <= 0) {
+ Log.e(TAG, "getList totalCount <= 0 >> return null;");
return null;
}
if (start >= 0) {
Log.i(TAG, "getList start >= 0 >> ");
- int end = start + getPageSize(clazz, group);
- if (end > idList.size()) {
- Log.i(TAG, "getList end > idList.size() >> end = idList.size();");
- end = idList.size();
+ int end = start + count;
+ if (end > totalCount) {
+ end = totalCount;
}
Log.i(TAG, "getList end = " + end);
if (end <= start) {
@@ -163,8 +163,10 @@ public List getList(Class clazz, String group, int start) {
return null;
}
- Log.i(TAG, "getList >> idList = idList.subList(start, end); >>");
- idList = idList.subList(start, end);
+ if (start > 0 || end < totalCount) {
+ Log.i(TAG, "getList start > 0 || end < totalCount >> idList = idList.subList(" + start + "," + end + "); >>");
+ idList = idList.subList(start, end);
+ }
}
List list = new ArrayList();
@@ -176,7 +178,7 @@ public List getList(Class clazz, String group, int start) {
}
}
- Log.i(TAG, "getList return list; list.size() = " + list.size());
+ Log.i(TAG, "getList return list; list.size() = " + list.size() + "\n>>>>>>>>>>>>>>>>>>>>>>\n\n");
return list;
}
@@ -194,17 +196,6 @@ public T get(Class clazz, String id) {
- /**获取每页数量
- * @param clazz
- * @param group
- * @return
- */
- private int getPageSize(Class clazz, String group) {
- SharedPreferences sp = getSharedPreferences(
- getClassPath(clazz) + KEY_GROUP_ + StringUtil.getTrimedString(group));
- return sp == null ? 0 : sp.getInt(KEY_PAGE_SIZE, 0);
- }
-
/**获取id列表
* @param clazz
* @param group
@@ -212,8 +203,8 @@ private int getPageSize(Class clazz, String group) {
*/
public List getIdList(Class clazz, String group) {
SharedPreferences sp = getSharedPreferences(
- getClassPath(clazz) + KEY_GROUP_ + StringUtil.getTrimedString(group));
- return sp == null ? null : Json.parseArray(sp.getString(KEY_ID_LIST, null), String.class);
+ getClassPath(clazz) + KEY_GROUP);
+ return sp == null ? null : JSON.parseArray(sp.getString(StringUtil.getTrimedString(group), null), String.class);
}
/**保存列表
@@ -252,6 +243,7 @@ public void addList(Class clazz, String group, LinkedHashMap m
* @param pageSize 每页大小
*/
public void saveList(Class clazz, String group, LinkedHashMap map, int start, int pageSize) {
+ Log.i(TAG, "\n\n <<<<<<<<<<<<<<<<<\nsaveList group = " + group + "; start = " + start + "; pageSize = " + pageSize);
if (clazz == null || map == null || map.size() <= 0) {
Log.e(TAG, "saveList clazz == null || map == null || map.size() <= 0 >> return;");
return;
@@ -259,49 +251,56 @@ public void saveList(Class clazz, String group, LinkedHashMap
final String CLASS_PATH = getClassPath(clazz);
if (StringUtil.isNotEmpty(group, true)) {
+ group = StringUtil.getTrimedString(group);
Log.i(TAG, "saveList group = " + group + "; map.size() = " + map.size()
+ "; start = " + start +"; pageSize = " + pageSize);
List newIdList = new ArrayList(map.keySet());//用String而不是Long,因为订单Order的id超出Long的最大值
- // if (newIdList != null) {
- Log.i(TAG, "saveList newIdList.size() = " + newIdList.size()
- + "; start save <<<<<<<<<<<<<<<<<\n ");
+
+ Log.i(TAG, "saveList newIdList.size() = " + newIdList.size() + "; start save <<<<<<<<<<<<<<<<<\n ");
//保存至分组<<<<<<<<<<<<<<<<<<<<<<<<<
- SharedPreferences sp = getSharedPreferences(CLASS_PATH + KEY_GROUP_ + StringUtil.getTrimedString(group));
+ SharedPreferences sp = getSharedPreferences(CLASS_PATH + KEY_GROUP);
// sp.edit().putString(KEY_GROUP, group);
Editor editor = sp.edit();
- // Log.i(TAG, "\n saveList pageSize = " + getPageSize(clazz, group) + " <<<<<<<<");
+ Log.i(TAG, "\n saveList pageSize = " + pageSize + " <<<<<<<<");
//列表每页大小
- if (pageSize > 0) {//sp.getInt(KEY_PAGE_SIZE, 0)) {
+ if (pageSize > 0) {
if (pageSize > MAX_PAGE_SIZE) {
pageSize = MAX_PAGE_SIZE;
}
- editor.remove(KEY_PAGE_SIZE).putInt(KEY_PAGE_SIZE, pageSize);
}
- // Log.i(TAG, "\n saveList pageSize = " + getPageSize(clazz, group) + ">>>>>>>>>");
+ Log.i(TAG, "\n saveList pageSize = " + pageSize + ">>>>>>>>>");
//id列表
- List idList = Json.parseArray(sp.getString(KEY_ID_LIST, null), String.class);
+ List idList = JSON.parseArray(sp.getString(group, null), String.class);
if (idList == null) {
idList = new ArrayList();
}
if (start < 0) {
start = idList.size();
}
- // Log.i(TAG, "\n saveList idList.size() = " + idList.size() + " <<<<<<<<");
+ Log.i(TAG, "\n saveList idList.size() = " + idList.size() + " <<<<<<<<");
+ String id;
for (int i = start; i < start + newIdList.size(); i++) {
+ id = newIdList.get(i - start);
+ if (id == null || id.isEmpty()) {
+ continue;
+ }
+ if (idList.contains(id)) {
+ idList.remove(id);//位置发生变化
+ }
if (i < idList.size()) {
- idList.set(i, newIdList.get(i - start));
- } else {
- idList.add(newIdList.get(i - start));
+ idList.set(i, id);
+ } else {
+ idList.add(id);
}
}
- editor.remove(KEY_ID_LIST).putString(KEY_ID_LIST, Json.toJSONString(idList)).commit();
+ editor.remove(group).putString(group, JSON.toJSONString(idList)).commit();
- // Log.i(TAG, "\n saveList idList.size() = " + getIdList(clazz, group).size() + ">>>>>>>>>");
+ Log.i(TAG, "\n saveList idList.size() = " + idList.size() + " >>>>>>>>");
}
//保存至分组>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -313,8 +312,7 @@ public void saveList(Class clazz, String group, LinkedHashMap
cache.saveList(map);
//保存所有数据>>>>>>>>>>>>>>>>>>>>>>>>>
- Log.i(TAG, "\n saveList cache.getSize() = " + cache.getSize()
- + "; end save >>>>>>>>>>>> ");
+ Log.i(TAG, "saveList cache.getSize() = " + cache.getSize() + "; end save \n>>>>>>>>>>>>>>>>>> \n\n");
// }
}
@@ -340,28 +338,24 @@ public void save(Class clazz, T data, String id, String group) {
Log.e(id, "save data == null || StringUtil.isNotEmpty(id, true) == false >> return;");
return;
}
-
- Log.i(TAG, "save " + id + " >> ");
+
new Cache(context, clazz, getListPath(clazz)).save(id, data);
-
- Log.i(TAG, "save " + id + " to " + group + " >> ");
- SharedPreferences sp = getSharedPreferences(getGroupPath(clazz, group));
- if (sp == null) {
- Log.e(TAG, "save sp == null >> return;");
- return;
- }
- List idList = getIdList(clazz, group);
- if (idList == null) {
- idList = new ArrayList();
- }
- if (idList.contains(id)) {
- Log.e(TAG, "save idList.contains(id) >> return;");
- return;
- }
+ SharedPreferences sp = getSharedPreferences(getGroupPath(clazz));
+ if (sp != null) {
+ group = StringUtil.getTrimedString(group);
- idList.add(0, id);
- sp.edit().remove(KEY_ID_LIST).putString(KEY_ID_LIST, Json.toJSONString(idList)).commit();
+ Log.i(TAG, "save sp != null >> save to group");
+ List idList = getIdList(clazz, group);
+ if (idList == null) {
+ idList = new ArrayList();
+ }
+ if (idList.contains(id) == false) {
+ Log.i(TAG, "save idList.contains(id) == false >> add");
+ idList.add(0, id);
+ sp.edit().remove(group).putString(group, JSON.toJSONString(idList)).commit();
+ }
+ }
}
/**清空类
@@ -394,7 +388,7 @@ public void clear(Class clazz, String group, boolean removeAllInGroup) {
cache.remove(id);
}
}
- clear(getSharedPreferences(getGroupPath(clazz, group)));
+ clear(getSharedPreferences(getGroupPath(clazz)));
}
/**清空
* @param sp
diff --git a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/ui/ServerSettingActivity.java b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/ui/ServerSettingActivity.java
index 008532d..c8ca3a5 100755
--- a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/ui/ServerSettingActivity.java
+++ b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/ui/ServerSettingActivity.java
@@ -183,15 +183,14 @@ public void initData() {//必须调用
private void saveAndExit(boolean isTest) {
if (StringUtil.isNotEmpty(sharedPreferencesPath, true)
&& StringUtil.isNotEmpty(isTest ? testKey : normalKey, true)) {
- SettingUtil.putBoolean(context, SettingUtil.KEY_IS_ON_TEST_MODE, isTest);
+ SettingUtil.putBoolean(SettingUtil.KEY_IS_ON_TEST_MODE, isTest);
DataKeeper.save(sharedPreferencesPath, pathMode, isTest ? testKey : normalKey
, StringUtil.getNoBlankString(isTest ? etServerSettingTest : etServerSettingNormal));
showShortToast("已保存并切换至" + SERVER_NAMES[SettingUtil.isOnTestMode ? 1 : 0]
+ ",请不要退出登录。重启后生效");
- } else {
- setResult(RESULT_OK, new Intent().putExtra(isTest ? RESULT_TEST_ADDRESS : RESULT_NORMAL_ADDRESS
- , StringUtil.getNoBlankString(isTest ? etServerSettingTest : etServerSettingNormal)));
}
+ setResult(RESULT_OK, new Intent().putExtra(isTest ? RESULT_TEST_ADDRESS : RESULT_NORMAL_ADDRESS
+ , StringUtil.getNoBlankString(isTest ? etServerSettingTest : etServerSettingNormal)));
finish();
}
@@ -302,4 +301,4 @@ public void onClick(View v) {
//内部类,尽量少用>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-}
\ No newline at end of file
+}
diff --git a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/ui/xlistview/XListView.java b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/ui/xlistview/XListView.java
index 8d5dc62..c20ad03 100755
--- a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/ui/xlistview/XListView.java
+++ b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/ui/xlistview/XListView.java
@@ -77,6 +77,9 @@ public XListView(Context context, AttributeSet attrs, int defStyle) {
initWithContext(context);
}
+ public boolean isFooterShowing() {
+ return isFooterAdded && mFooterView != null && mFooterView.isShowing();
+ }
/**
* mFooterView是否已被添加
*/
@@ -193,6 +196,10 @@ public void onClick(View v) {
* @author Lemon
*/
public void onRefresh() {
+// if (getCount() <= 0) {//解决onRefresh失败后不显示footer
+ showFooter(false);
+// }
+
mPullRefreshing = true;
smoothScrollToPosition(0);
mHeaderView.setVisiableHeight((int) getContext().getResources()
@@ -315,10 +322,12 @@ private void resetFooterHeight() {
}
private void startLoadMore() {
- mPullLoading = true;
- mFooterView.setState(XListViewFooter.STATE_LOADING);
- if (mListViewListener != null) {
- mListViewListener.onLoadMore();
+ if (isFooterShowing()) {
+ mPullLoading = true;
+ mFooterView.setState(XListViewFooter.STATE_LOADING);
+ if (mListViewListener != null) {
+ mListViewListener.onLoadMore();
+ }
}
}
@@ -353,8 +362,11 @@ public boolean onTouchEvent(MotionEvent ev) {
mLastY = -1; // reset
if (getFirstVisiblePosition() == 0) {
// invoke refresh
- if (mEnablePullRefresh
- && mHeaderView.getVisiableHeight() > mHeaderViewHeight) {
+ if (mEnablePullRefresh && mHeaderView.getVisiableHeight() > mHeaderViewHeight) {
+// if (getCount() <= 0) {
+ showFooter(false);
+// }
+
mPullRefreshing = true;
mHeaderView.setState(XListViewHeader.STATE_REFRESHING);
if (mListViewListener != null) {
diff --git a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/ui/xlistview/XListViewFooter.java b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/ui/xlistview/XListViewFooter.java
index 03facd0..b79b025 100755
--- a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/ui/xlistview/XListViewFooter.java
+++ b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/ui/xlistview/XListViewFooter.java
@@ -7,6 +7,7 @@
package zuo.biao.library.ui.xlistview;
import zuo.biao.library.R;
+import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
@@ -42,7 +43,7 @@ public XListViewFooter(Context context, AttributeSet attrs) {
public void setState(int state) {
mProgressBar.setVisibility(View.GONE);
mHintView.setVisibility(View.VISIBLE);
-
+
switch (state) {
case STATE_READY:
mHintView.setText(R.string.xlistview_footer_hint_ready);
@@ -91,34 +92,42 @@ public void loading() {
mProgressBar.setVisibility(View.VISIBLE);
}
+ private boolean isShowing = false;
+ public boolean isShowing() {
+ return isShowing;
+ }
/**
* hide footer when disable pull load more
*/
public void hide() {
- LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mContentView
- .getLayoutParams();
- lp.height = 0;
- mContentView.setLayoutParams(lp);
+ if (needFooter) {
+ isShowing = false;
+ LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mContentView.getLayoutParams();
+ lp.height = 1;
+ mContentView.setLayoutParams(lp);
+ }
}
/**
* show footer
*/
public void show() {
- LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mContentView
- .getLayoutParams();
- lp.height = android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
- mContentView.setLayoutParams(lp);
+ if (needFooter) {
+ isShowing = true;
+ LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mContentView.getLayoutParams();
+ lp.height = android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
+ mContentView.setLayoutParams(lp);
+ }
}
- @SuppressWarnings("deprecation")
+ @SuppressLint("InflateParams")
private void initView(Context context) {
mContext = context;
LinearLayout moreView = (LinearLayout) LayoutInflater.from(mContext)
.inflate(R.layout.xlistview_footer, null);
addView(moreView);
moreView.setLayoutParams(new LinearLayout.LayoutParams(
- android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
+ android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
mContentView = moreView.findViewById(R.id.xlistview_footer_content);
mProgressBar = moreView.findViewById(R.id.xlistview_footer_progressbar);
@@ -126,12 +135,11 @@ private void initView(Context context) {
.findViewById(R.id.xlistview_footer_hint_textview);
}
- public void setGone() // 取消上拉模式初始化时调用
- {
- LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mContentView
- .getLayoutParams();
- lp.height = 1;
- mContentView.setLayoutParams(lp);
- mContentView.setVisibility(View.INVISIBLE);
+ private boolean needFooter = true;
+ public void setGone() { // 取消上拉模式初始化时调用
+ if (needFooter) {
+ hide();
+ needFooter = false;
+ }
}
}
diff --git a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/util/Json.java b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/util/Json.java
index d8c89a9..9de0eb6 100755
--- a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/util/Json.java
+++ b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/util/Json.java
@@ -16,21 +16,21 @@
import java.util.List;
-import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
-/**阿里fastjson封装类 防止解析时异常
- * @modifier Lemon
+/**阿里FastJSON封装类 防止解析时异常
+ * @author Lemon
*/
-public class Json {
- private static final String TAG = "Json";
+public class JSON {
+ private static final String TAG = "JSON";
/**判断json格式是否正确
* @param s
* @return
*/
public static boolean isJsonCorrect(String s) {
- Log.i(TAG, "isJsonCorrect <<<< " + s + " >>>>>>>");
+// Log.i(TAG, "isJsonCorrect <<<< " + s + " >>>>>>>");
if (s == null || s.equals("[]")
|| s.equals("{}") || s.equals("") || s.equals("[null]") || s.equals("{null}") || s.equals("null")) {
return false;
@@ -39,34 +39,53 @@ public static boolean isJsonCorrect(String s) {
}
/**获取有效的json
- * @param s
+ * @param json
* @return
*/
- public static String getCorrectJson(String s) {
- return isJsonCorrect(s) ? s : "";
+ public static String getCorrectJson(String json) {
+ return isJsonCorrect(json) ? json : "";
}
/**
- * @param s
+ * @param obj
+ * @return
+ */
+ /**obj转JSONObject
+ * @param json
+ * @return
+ */
+ public static JSONObject parseObject(Object obj) {
+ return parseObject(toJSONString(obj));
+ }
+ /**json转JSONObject
+ * @param json
* @return
*/
- public static JSONObject parseObject(String s) {
+ public static JSONObject parseObject(String json) {
try {
- return JSON.parseObject(getCorrectJson(s));
+ return com.alibaba.fastjson.JSON.parseObject(getCorrectJson(json));
} catch (Exception e) {
Log.e(TAG, "parseObject catch \n" + e.getMessage());
}
return null;
}
-
- /**
- * @param s
+
+ /**JSONObject转实体类
+ * @param object
* @param clazz
* @return
*/
- public static T parseObject(String s, Class clazz) {
+ public static T parseObject(JSONObject object, Class clazz) {
+ return parseObject(toJSONString(object), clazz);
+ }
+ /**json转实体类
+ * @param json
+ * @param clazz
+ * @return
+ */
+ public static T parseObject(String json, Class clazz) {
try {
- return JSON.parseObject(getCorrectJson(s), clazz);
+ return com.alibaba.fastjson.JSON.parseObject(getCorrectJson(json), clazz);
} catch (Exception e) {
Log.e(TAG, "parseObject catch \n" + e.getMessage());
}
@@ -78,8 +97,11 @@ public static T parseObject(String s, Class clazz) {
* @return
*/
public static String toJSONString(Object obj) {
+ if (obj instanceof String) {
+ return (String) obj;
+ }
try {
- return JSON.toJSONString(obj);
+ return com.alibaba.fastjson.JSON.toJSONString(obj);
} catch (Exception e) {
Log.e(TAG, "toJSONString catch \n" + e.getMessage());
}
@@ -87,17 +109,81 @@ public static String toJSONString(Object obj) {
}
/**
- * @param s
+ * @param json
+ * @return
+ */
+ public static JSONArray parseArray(String json) {
+ try {
+ return com.alibaba.fastjson.JSON.parseArray(getCorrectJson(json));
+ } catch (Exception e) {
+ Log.e(TAG, "parseArray catch \n" + e.getMessage());
+ }
+ return null;
+ }
+ /**
+ * @param json
* @param clazz
* @return
*/
- public static List parseArray(String s, Class clazz) {
+ public static List parseArray(String json, Class clazz) {
try {
- return JSON.parseArray(getCorrectJson(s), clazz);
+ return com.alibaba.fastjson.JSON.parseArray(getCorrectJson(json), clazz);
} catch (Exception e) {
Log.e(TAG, "parseArray catch \n" + e.getMessage());
}
return null;
}
-}
+ /**格式化,显示更好看
+ * @param object
+ * @return
+ */
+ public static String format(Object object) {
+ try {
+ return com.alibaba.fastjson.JSON.toJSONString(object, true);
+ } catch (Exception e) {
+ Log.e(TAG, "format catch \n" + e.getMessage());
+ }
+ return null;
+ }
+
+ /**判断是否为JSONObject
+ * @param obj instanceof String ? parseObject
+ * @return
+ */
+ public static boolean isJSONObject(Object obj) {
+ if (obj instanceof JSONObject) {
+ return true;
+ }
+ if (obj instanceof String) {
+ try {
+ JSONObject json = parseObject((String) obj);
+ return json != null && json.isEmpty() == false;
+ } catch (Exception e) {
+ Log.e(TAG, "isJSONObject catch \n" + e.getMessage());
+ }
+ }
+
+ return false;
+ }
+ /**判断是否为JSONArray
+ * @param obj instanceof String ? parseArray
+ * @return
+ */
+ public static boolean isJSONArray(Object obj) {
+ if (obj instanceof JSONArray) {
+ return true;
+ }
+ if (obj instanceof String) {
+ try {
+ JSONArray json = parseArray((String) obj);
+ return json != null && json.isEmpty() == false;
+ } catch (Exception e) {
+ Log.e(TAG, "isJSONArray catch \n" + e.getMessage());
+ }
+ }
+
+ return false;
+ }
+
+}
\ No newline at end of file
diff --git a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/util/SettingUtil.java b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/util/SettingUtil.java
index a320bf6..c8c6a3e 100755
--- a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/util/SettingUtil.java
+++ b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/java/zuo/biao/library/util/SettingUtil.java
@@ -35,6 +35,9 @@ public final class SettingUtil {
private SettingUtil() {/*不能实例化**/}
+ public static final String KEY_CACHE = "KEY_CACHE";//开启缓存
+ public static final String KEY_PRELOAD = "KEY_PRELOAD";//开启预加载
+
public static final String KEY_VOICE = "KEY_VOICE";//开启通知声
public static final String KEY_VIBRATE = "KEY_VIBRATE";//开启震动
public static final String KEY_NO_DISTURB = "KEY_NO_DISTURB";//夜间防打扰
@@ -43,6 +46,9 @@ private SettingUtil() {/*不能实例化**/}
public static final String KEY_IS_FIRST_START = "KEY_IS_FIRST_START";//第一次打开应用
public static final String[] KEYS = {
+ KEY_CACHE,
+ KEY_PRELOAD,
+
KEY_VOICE,
KEY_VIBRATE,
KEY_NO_DISTURB,
@@ -51,6 +57,9 @@ private SettingUtil() {/*不能实例化**/}
KEY_IS_FIRST_START,
};
+ public static boolean cache = true;//开启缓存
+ public static boolean preload = true;//开启预加载
+
public static boolean voice = true;//开启通知声
public static boolean vibrate = true;//开启震动
public static boolean noDisturb = false;//夜间防打扰
@@ -58,7 +67,10 @@ private SettingUtil() {/*不能实例化**/}
public static boolean isOnTestMode = false;//测试模式
public static boolean isFirstStart = true;//第一次打开应用
- public static final boolean[] defaultValues = {
+ public static final boolean[] defaultValues = new boolean[]{
+ cache,//开启缓存
+ preload,//开启预加载
+
voice,//开启通知声
vibrate,//开启震动
noDisturb,//夜间防打扰
@@ -67,25 +79,29 @@ private SettingUtil() {/*不能实例化**/}
isFirstStart,//第一次打开应用
};
+ private static Context context;
/**初始化
- * @param context
+ * @param context_
*/
- public static void init(Context context) {
+ public static void init(Context context_) {
+ context = context_;
- voice = getBoolean(context, KEY_VOICE, voice);
- vibrate = getBoolean(context, KEY_VIBRATE, vibrate);
- noDisturb = getBoolean(context, KEY_NO_DISTURB, noDisturb);
+ cache = getBoolean(KEY_CACHE, cache);
+ preload = getBoolean(KEY_PRELOAD, preload);
- isOnTestMode = getBoolean(context, KEY_IS_ON_TEST_MODE, isOnTestMode);
- isFirstStart = getBoolean(context, KEY_IS_FIRST_START, isFirstStart);
+ voice = getBoolean(KEY_VOICE, voice);
+ vibrate = getBoolean(KEY_VIBRATE, vibrate);
+ noDisturb = getBoolean(KEY_NO_DISTURB, noDisturb);
+
+ isOnTestMode = getBoolean(KEY_IS_ON_TEST_MODE, isOnTestMode);
+ isFirstStart = getBoolean(KEY_IS_FIRST_START, isFirstStart);
}
/**恢复默认
- * @param context
*/
- public static void restoreDefault(Context context) {
+ public static void restoreDefault() {
for (int i = 0; i < KEYS.length; i++) {
- putBoolean(context, KEYS[i], defaultValues[i]);
+ putBoolean(KEYS[i], defaultValues[i]);
}
init(context);
@@ -116,14 +132,13 @@ public static int getKeyIndex(String key) {
}
/**
- * @param context
* @param key
* @param defaultValue
* @return
*/
- public static boolean getBoolean(Context context, String key, boolean defaultValue){
- if (context == null || isContainKey(key) == false) {
- Log.e(TAG, "writeBoolean context == null || isContainKey(key) == false >> return defaultValue;");
+ public static boolean getBoolean(String key, boolean defaultValue){
+ if (isContainKey(key) == false) {
+ Log.e(TAG, "writeBoolean isContainKey(key) == false >> return defaultValue;");
return defaultValue;
}
@@ -132,12 +147,11 @@ public static boolean getBoolean(Context context, String key, boolean defaultVal
/**设置所有boolean
- * @param context
* @param values
*/
- public static void putAllBoolean(Context context, boolean[] values){
- if (context == null || values == null || values.length != KEYS.length) {
- Log.e(TAG, "putAllBoolean context == null || values == null || values.length != KEYS.length >> return;");
+ public static void putAllBoolean(boolean[] values){
+ if (values == null || values.length != KEYS.length) {
+ Log.e(TAG, "putAllBoolean values == null || values.length != KEYS.length >> return;");
return;
}
@@ -152,14 +166,13 @@ public static void putAllBoolean(Context context, boolean[] values){
}
/**
- * @param context
* @param key
* @param value
*/
- public static void putBoolean(Context context, String key, boolean value){
+ public static void putBoolean(String key, boolean value){
int keyIndex = getKeyIndex(key);
- if (context == null || keyIndex <= 0) {
- Log.e(TAG, "writeBoolean context == null || keyIndex <= 0 >> return;");
+ if (keyIndex <= 0) {
+ Log.e(TAG, "writeBoolean keyIndex <= 0 >> return;");
return;
}
@@ -179,6 +192,9 @@ public static void putBoolean(Context context, String key, boolean value){
public static boolean[] getAllBooleans(Context context) {
init(context);
return new boolean[]{
+ cache,
+ preload,
+
voice,
vibrate,
noDisturb,
@@ -192,11 +208,10 @@ public static boolean[] getAllBooleans(Context context) {
public static final int[] NO_DISTURB_END_TIME = {6, 0};
/**免打扰
- * @param context
* @return
*/
- public static boolean noDisturb(Context context) {
- return getBoolean(context, KEY_NO_DISTURB, noDisturb)
+ public static boolean noDisturb() {
+ return getBoolean(KEY_NO_DISTURB, noDisturb)
&& TimeUtil.isNowInTimeArea(NO_DISTURB_START_TIME, NO_DISTURB_END_TIME);
}
@@ -223,40 +238,40 @@ public static boolean noDisturb(Context context) {
/**获取当前服务器地址
* isHttps = false
- * @param context
* @return
*/
public static String getCurrentServerAddress(Context context) {
- return getCurrentServerAddress(context, false);
+ return getCurrentServerAddress(false);
}
/**获取当前服务器地址
- * @param context
* @param isHttps
* @return
*/
- public static String getCurrentServerAddress(Context context, boolean isHttps) {
- return isHttps ? URL_SERVER_ADDRESS_NORMAL_HTTPS : getServerAddress(context, isOnTestMode);
+ public static String getCurrentServerAddress(boolean isHttps) {
+ return isHttps ? URL_SERVER_ADDRESS_NORMAL_HTTPS : getServerAddress(isOnTestMode);
}
/**获取服务器地址
* isHttps = false
- * @param context
* @param isTest
* @return
*/
- public static String getServerAddress(Context context, boolean isTest) {
- return getServerAddress(context, isTest, false);
+ public static String getServerAddress(boolean isTest) {
+ return getServerAddress(isTest, false);
}
/**获取服务器地址
- * @param context
* @param isTest
* @return
*/
- public static String getServerAddress(Context context, boolean isTest, boolean isHttps) {
- SharedPreferences sdf = context == null ? null : context.getSharedPreferences(APP_SETTING, Context.MODE_PRIVATE);
- return sdf == null ? null : sdf.getString(
- isTest ? KEY_SERVER_ADDRESS_TEST : KEY_SERVER_ADDRESS_NORMAL
- , isTest ? URL_SERVER_ADDRESS_TEST : (
- isHttps ? URL_SERVER_ADDRESS_NORMAL_HTTPS : URL_SERVER_ADDRESS_NORMAL_HTTP));
+ public static String getServerAddress(boolean isTest, boolean isHttps) {
+ SharedPreferences sdf = context.getSharedPreferences(APP_SETTING, Context.MODE_PRIVATE);
+ if (sdf == null) {
+ return null;
+ }
+ if (isTest) {
+ return sdf.getString(KEY_SERVER_ADDRESS_TEST, URL_SERVER_ADDRESS_TEST);
+ }
+ return sdf.getString(KEY_SERVER_ADDRESS_NORMAL
+ , isHttps ? URL_SERVER_ADDRESS_NORMAL_HTTPS : URL_SERVER_ADDRESS_NORMAL_HTTP);
}
diff --git a/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/DEMO/DemoListActivity.java b/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/DEMO/DemoListActivity.java
index 62cddc9..a540390 100755
--- a/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/DEMO/DemoListActivity.java
+++ b/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/DEMO/DemoListActivity.java
@@ -140,15 +140,15 @@ public void initData() {//必须在onCreate方法内调用
}
@Override
- public void getListAsync(int pageNum) {
+ public void getListAsync(int page) {
showProgressDialog(R.string.loading);
List> list = new ArrayList>();
for (int i = 0; i < 6; i++) {
- list.add(new Entry(getPictureUrl(i + 6*pageNum), "联系人" + i + 6*pageNum));
+ list.add(new Entry(getPictureUrl(i + 6*page), "联系人" + i + 6*page));
}
- onLoadSucceed(list);
+ onLoadSucceed(page, list);
}
/**获取图片地址,仅供测试用
diff --git a/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/DEMO/DemoListFragment.java b/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/DEMO/DemoListFragment.java
index 5312bdd..ced8256 100644
--- a/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/DEMO/DemoListFragment.java
+++ b/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/DEMO/DemoListFragment.java
@@ -114,7 +114,7 @@ public void initData() {//必须在onCreateView方法内调用
@Override
- public void getListAsync(int pageNum) {
+ public void getListAsync(int page) {
//示例代码<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
showProgressDialog(R.string.loading);
@@ -123,7 +123,7 @@ public void getListAsync(int pageNum) {
list.add(new Entry("联系人" + i , String.valueOf(1311736568 + i*i)));
}
- onLoadSucceed(list);
+ onLoadSucceed(page, list);
//示例代码>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
}
diff --git a/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/DEMO/DemoMainActivity.java b/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/DEMO/DemoMainActivity.java
index 9aa04e4..adb8f53 100755
--- a/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/DEMO/DemoMainActivity.java
+++ b/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/DEMO/DemoMainActivity.java
@@ -306,7 +306,7 @@ public boolean onTouch(View v, MotionEvent event) {
showShortToast("请长按5-8秒");
} else {
toActivity(ServerSettingActivity.createIntent(context
- , SettingUtil.getServerAddress(context, false), SettingUtil.getServerAddress(context, true)
+ , SettingUtil.getServerAddress(false), SettingUtil.getServerAddress(true)
, SettingUtil.APP_SETTING, Context.MODE_PRIVATE
, SettingUtil.KEY_SERVER_ADDRESS_NORMAL, SettingUtil.KEY_SERVER_ADDRESS_TEST));
return true;
diff --git a/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/activity_fragment/AboutActivity.java b/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/activity_fragment/AboutActivity.java
index 94240e1..f091a04 100644
--- a/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/activity_fragment/AboutActivity.java
+++ b/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/activity_fragment/AboutActivity.java
@@ -213,7 +213,7 @@ public void onDragBottom(boolean rightToLeft) {
@Override
public void run() {
Log.i(TAG, "onDragBottom >> SettingUtil.putBoolean(context, SettingUtil.KEY_IS_FIRST_IN, false);");
- SettingUtil.putBoolean(context, SettingUtil.KEY_IS_FIRST_START, false);
+ SettingUtil.putBoolean(SettingUtil.KEY_IS_FIRST_START, false);
}
});
}
diff --git a/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/activity_fragment/QRCodeActivity.java b/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/activity_fragment/QRCodeActivity.java
index 41706cc..cdeef2e 100644
--- a/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/activity_fragment/QRCodeActivity.java
+++ b/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/activity_fragment/QRCodeActivity.java
@@ -20,7 +20,7 @@
import zuo.biao.library.interfaces.OnBottomDragListener;
import zuo.biao.library.manager.CacheManager;
import zuo.biao.library.util.ImageLoaderUtil;
-import zuo.biao.library.util.Json;
+import zuo.biao.library.util.JSON;
import zuo.biao.library.util.Log;
import zuo.biao.library.util.StringUtil;
import android.app.Activity;
@@ -152,7 +152,7 @@ protected void setQRCode(User user) {
}
try {
- qRCodeBitmap = EncodingHandler.createQRCode(Json.toJSONString(user)
+ qRCodeBitmap = EncodingHandler.createQRCode(JSON.toJSONString(user)
, (int) (2 * getResources().getDimension(R.dimen.qrcode_size)));
} catch (WriterException e) {
e.printStackTrace();
diff --git a/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/activity_fragment/SettingActivity.java b/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/activity_fragment/SettingActivity.java
index d7b7fe5..5da4555 100644
--- a/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/activity_fragment/SettingActivity.java
+++ b/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/activity_fragment/SettingActivity.java
@@ -58,14 +58,16 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void initView() {//必须调用
- ivSettings = new ImageView[5];
- ivSettings[0] = (ImageView) findViewById(R.id.ivSettingVoice);
- ivSettings[1] = (ImageView) findViewById(R.id.ivSettingVibrate);
-
- ivSettings[2] = (ImageView) findViewById(R.id.ivSettingNoDisturb);
+ ivSettings = new ImageView[7];
+ ivSettings[0] = (ImageView) findViewById(R.id.ivSettingCache);
+ ivSettings[1] = (ImageView) findViewById(R.id.ivSettingPreload);
+
+ ivSettings[2] = (ImageView) findViewById(R.id.ivSettingVoice);
+ ivSettings[3] = (ImageView) findViewById(R.id.ivSettingVibrate);
+ ivSettings[4] = (ImageView) findViewById(R.id.ivSettingNoDisturb);
- ivSettings[3] = (ImageView) findViewById(R.id.ivSettingTestMode);
- ivSettings[4] = (ImageView) findViewById(R.id.ivSettingFirstStart);
+ ivSettings[5] = (ImageView) findViewById(R.id.ivSettingTestMode);
+ ivSettings[6] = (ImageView) findViewById(R.id.ivSettingFirstStart);
}
@@ -81,7 +83,7 @@ private void setSwitch(int which, boolean isToOn) {
return;
}
- ivSettings[which].setImageResource(isToOn == false ? switchResIds[0] : switchResIds[1]);
+ ivSettings[which].setImageResource(switchResIds[isToOn ? 1 : 0]);
settings[which] = isToOn;
}
@@ -166,7 +168,7 @@ public void onClick(View v) {
@Override
public void onDragBottom(boolean rightToLeft) {
if (rightToLeft) {
- SettingUtil.restoreDefault(context);
+ SettingUtil.restoreDefault();
initData();
return;
}
@@ -191,7 +193,7 @@ public void finish() {
@Override
public void run() {
- SettingUtil.putAllBoolean(context, settings);
+ SettingUtil.putAllBoolean(settings);
isSettingChanged = false;
runUiThread(new Runnable() {
@@ -238,4 +240,4 @@ protected void onDestroy() {
//内部类,尽量少用>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-}
\ No newline at end of file
+}
diff --git a/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/activity_fragment/UserActivity.java b/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/activity_fragment/UserActivity.java
index 71a08ef..fa67ba9 100644
--- a/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/activity_fragment/UserActivity.java
+++ b/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/activity_fragment/UserActivity.java
@@ -14,8 +14,6 @@
package zblibrary.demo.activity_fragment;
-import org.json.JSONObject;
-
import zblibrary.demo.R;
import zblibrary.demo.model.User;
import zblibrary.demo.util.MenuUtil;
@@ -32,7 +30,7 @@
import zuo.biao.library.ui.EditTextInfoActivity;
import zuo.biao.library.ui.TextClearSuit;
import zuo.biao.library.util.CommonUtil;
-import zuo.biao.library.util.Json;
+import zuo.biao.library.util.JSON;
import zuo.biao.library.util.Log;
import zuo.biao.library.util.StringUtil;
import android.app.Activity;
@@ -45,6 +43,8 @@
import android.widget.EditText;
import android.widget.TextView;
+import com.alibaba.fastjson.JSONObject;
+
/**联系人资料界面
* @author Lemon
*/
@@ -229,7 +229,7 @@ public void onBottomMenuItemClick(int intentCode) {
}
switch (intentCode) {
case MenuUtil.INTENT_CODE_SEND:
- CommonUtil.shareInfo(context, Json.toJSONString(user));
+ CommonUtil.shareInfo(context, JSON.toJSONString(user));
break;
case MenuUtil.INTENT_CODE_QRCODE:
toActivity(QRCodeActivity.createIntent(context, userId));
@@ -261,9 +261,9 @@ public void onBottomMenuItemClick(int intentCode) {
public void onHttpResponse(int requestCode, String resultJson, Exception e) {
User user = null;
try {//如果服务器返回的json一定在最外层有个data,可以用OnHttpResponseListenerImpl解析
- JSONObject jsonObject = new JSONObject(resultJson);
- JSONObject data = jsonObject.getJSONObject("data");
- user = Json.parseObject("" + data, User.class);
+ JSONObject jsonObject = JSON.parseObject(resultJson);
+ JSONObject data = jsonObject == null ? null : jsonObject.getJSONObject("data");
+ user = JSON.parseObject(data, User.class);
} catch (Exception e1) {
Log.e(TAG, "onHttpResponse try { user = Json.parseObject(... >>" +
" } catch (JSONException e1) {\n" + e1.getMessage());
@@ -280,7 +280,7 @@ public void onHttpResponse(int requestCode, String resultJson, Exception e) {
// //对应HttpRequest.getUser(userId, 0, new OnHttpResponseListenerImpl(UserActivity.this)); <<<<<
// @Override
// public void onHttpSuccess(int requestCode, int resultCode, String resultData) {
- // setUser(Json.parseObject(resultData, User.class));
+ // setUser(JSON.parseObject(resultData, User.class));
// }
//
// @Override
diff --git a/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/activity_fragment/UserListFragment.java b/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/activity_fragment/UserListFragment.java
index dc81234..fd2f4b8 100755
--- a/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/activity_fragment/UserListFragment.java
+++ b/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/activity_fragment/UserListFragment.java
@@ -23,7 +23,7 @@
import zuo.biao.library.base.BaseHttpListFragment;
import zuo.biao.library.interfaces.AdapterCallBack;
import zuo.biao.library.interfaces.CacheCallBack;
-import zuo.biao.library.util.Json;
+import zuo.biao.library.util.JSON;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
@@ -135,15 +135,15 @@ public void initData() {//必须调用
}
@Override
- public void getListAsync(final int pageNum) {
- //实际使用时用这个,需要配置服务器地址 HttpRequest.getUserList(range, pageNum, 0, this);
+ public void getListAsync(final int page) {
+ //实际使用时用这个,需要配置服务器地址 HttpRequest.getUserList(range, page, -page, this);
//仅测试用<<<<<<<<<<<
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
- onHttpResponse(0, Json.toJSONString(TestUtil.getUserList(pageNum, getCachePageSize())), null);
+ onHttpResponse(-page, JSON.toJSONString(TestUtil.getUserList(page, getCacheCount())), null);
}
}, 1000);
//仅测试用>>>>>>>>>>>>
@@ -151,7 +151,7 @@ public void run() {
@Override
public List parseArray(String json) {
- return Json.parseArray(json, User.class);
+ return JSON.parseArray(json, User.class);
}
@Override
@@ -166,7 +166,10 @@ public String getCacheGroup() {
public String getCacheId(User data) {
return data == null ? null : "" + data.getId();
}
-
+ @Override
+ public int getCacheCount() {
+ return 10;
+ }
//Data数据区(存在数据获取或处理代码,但不存在事件监听代码)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
diff --git a/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/manager/DataManager.java b/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/manager/DataManager.java
index 50ed34e..621ec81 100755
--- a/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/manager/DataManager.java
+++ b/ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/manager/DataManager.java
@@ -16,7 +16,7 @@
import zblibrary.demo.application.DemoApplication;
import zblibrary.demo.model.User;
-import zuo.biao.library.util.Json;
+import zuo.biao.library.util.JSON;
import zuo.biao.library.util.Log;
import zuo.biao.library.util.StringUtil;
import android.content.Context;
@@ -120,7 +120,7 @@ public User getUser(long userId) {
return null;
}
Log.i(TAG, "getUser userId = " + userId);
- return Json.parseObject(sdf.getString(StringUtil.getTrimedString(userId), null), User.class);
+ return JSON.parseObject(sdf.getString(StringUtil.getTrimedString(userId), null), User.class);
}
@@ -165,7 +165,7 @@ public void saveUser(SharedPreferences sdf, User user) {
}
String key = StringUtil.getTrimedString(user.getId());
Log.i(TAG, "saveUser key = user.getId() = " + user.getId());
- sdf.edit().remove(key).putString(key, Json.toJSONString(user)).commit();
+ sdf.edit().remove(key).putString(key, JSON.toJSONString(user)).commit();
}
/**删除用户
diff --git a/ZBLibrary(AndroidStudio)/app/src/main/res/layout/setting_activity.xml b/ZBLibrary(AndroidStudio)/app/src/main/res/layout/setting_activity.xml
index 513677d..5b8c910 100644
--- a/ZBLibrary(AndroidStudio)/app/src/main/res/layout/setting_activity.xml
+++ b/ZBLibrary(AndroidStudio)/app/src/main/res/layout/setting_activity.xml
@@ -36,6 +36,42 @@
android:id="@+id/llSettingAppSettingContainer"
style="@style/ll_vertical_match_wrap" >
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+