|
@@ -51,6 +51,14 @@ public abstract class BaseListActivity2<T> extends BaseActivity implements IRefr
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //使用布局中自带的无数据空view
|
|
|
|
|
+ public boolean useSelfEmpty() {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ //只有一页数据
|
|
|
|
|
+ public boolean onlyOnePage() {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
public static final int REFRESH_ON_CREATE = 0;
|
|
public static final int REFRESH_ON_CREATE = 0;
|
|
|
public static final int REFRESH_ON_RESUME = 1;
|
|
public static final int REFRESH_ON_RESUME = 1;
|
|
|
public static final int REFRESH_ON_YOURSELF = -1;
|
|
public static final int REFRESH_ON_YOURSELF = -1;
|
|
@@ -64,7 +72,6 @@ public abstract class BaseListActivity2<T> extends BaseActivity implements IRefr
|
|
|
protected BaseMessage lastMessage;//最后一个网络获取的结果
|
|
protected BaseMessage lastMessage;//最后一个网络获取的结果
|
|
|
protected int page = 1;//页数
|
|
protected int page = 1;//页数
|
|
|
protected int per_page = DataUtil.PER_PAGE;
|
|
protected int per_page = DataUtil.PER_PAGE;
|
|
|
- private boolean loadMore;
|
|
|
|
|
|
|
|
|
|
protected View bottomLine;
|
|
protected View bottomLine;
|
|
|
|
|
|
|
@@ -78,6 +85,11 @@ public abstract class BaseListActivity2<T> extends BaseActivity implements IRefr
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void onLoadMore() {
|
|
public void onLoadMore() {
|
|
|
|
|
+ if(onlyOnePage()){
|
|
|
|
|
+ if(view_list != null)
|
|
|
|
|
+ view_list.loadMoreComplete();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
loadMoreData();
|
|
loadMoreData();
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -88,17 +100,13 @@ public abstract class BaseListActivity2<T> extends BaseActivity implements IRefr
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void loadMoreData() {
|
|
public void loadMoreData() {
|
|
|
- if (!loadMore) {
|
|
|
|
|
- loadMore = true;
|
|
|
|
|
- if (ListUtil.size(list) >= per_page * page) {
|
|
|
|
|
- page += 1;
|
|
|
|
|
- mInitData();
|
|
|
|
|
- } else {
|
|
|
|
|
- view_list.setNoMore(true);
|
|
|
|
|
- setNoMore(true);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ initDataStatus = STATUS_ING;
|
|
|
|
|
+ if (ListUtil.size(list) >= per_page * page) {
|
|
|
|
|
+ page += 1;
|
|
|
|
|
+ mInitData();
|
|
|
} else {
|
|
} else {
|
|
|
- view_list.loadMoreComplete();
|
|
|
|
|
|
|
+ view_list.setNoMore(true);
|
|
|
|
|
+ setNoMore(true);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -124,6 +132,7 @@ public abstract class BaseListActivity2<T> extends BaseActivity implements IRefr
|
|
|
public void mInitData() {
|
|
public void mInitData() {
|
|
|
final String urlKey = getKey(page, per_page);
|
|
final String urlKey = getKey(page, per_page);
|
|
|
if (isFirstGetACache()) {
|
|
if (isFirstGetACache()) {
|
|
|
|
|
+ initDataStatus = STATUS_CACHE;
|
|
|
//先尝试获取缓存数据
|
|
//先尝试获取缓存数据
|
|
|
lastCacheList = DataUtil.getInstance().getCacheList(urlKey, getTClass(), conversion, page);
|
|
lastCacheList = DataUtil.getInstance().getCacheList(urlKey, getTClass(), conversion, page);
|
|
|
loadList(lastCacheList);
|
|
loadList(lastCacheList);
|
|
@@ -140,6 +149,7 @@ public abstract class BaseListActivity2<T> extends BaseActivity implements IRefr
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
+ initDataStatus = STATUS_NET;
|
|
|
getApi(SheepApp.getInstance().getNetComponent().getApiService())
|
|
getApi(SheepApp.getInstance().getNetComponent().getApiService())
|
|
|
.subscribeOn(Schedulers.io())
|
|
.subscribeOn(Schedulers.io())
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
@@ -154,14 +164,17 @@ public abstract class BaseListActivity2<T> extends BaseActivity implements IRefr
|
|
|
|
|
|
|
|
List<T> newList = conversion.convert(baseMessage, page);
|
|
List<T> newList = conversion.convert(baseMessage, page);
|
|
|
loadList(newList);
|
|
loadList(newList);
|
|
|
|
|
+ initDataStatus = STATUS_FINISH;
|
|
|
} else {
|
|
} else {
|
|
|
notifyDataSetChanged();
|
|
notifyDataSetChanged();
|
|
|
|
|
+ initDataStatus = STATUS_NONE;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void onError(BaseMessage baseMessage) {
|
|
public void onError(BaseMessage baseMessage) {
|
|
|
notifyDataSetChanged();
|
|
notifyDataSetChanged();
|
|
|
|
|
+ initDataStatus = STATUS_NONE;
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -196,14 +209,18 @@ public abstract class BaseListActivity2<T> extends BaseActivity implements IRefr
|
|
|
public void clear() {
|
|
public void clear() {
|
|
|
lastMessage = null;
|
|
lastMessage = null;
|
|
|
setNoMore(false);
|
|
setNoMore(false);
|
|
|
- empty_view.setVisibility(View.INVISIBLE);
|
|
|
|
|
|
|
+ if (useSelfEmpty()) {
|
|
|
|
|
+ ViewUtil.setVisibility2(empty_view, true);
|
|
|
|
|
+ CommonUtil.getInstance().resetEmptyView(empty_view);
|
|
|
|
|
+ }
|
|
|
list.clear();
|
|
list.clear();
|
|
|
page = 1;
|
|
page = 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void refreshData() {
|
|
public void refreshData() {
|
|
|
|
|
+ initDataStatus = STATUS_ING;
|
|
|
clear();
|
|
clear();
|
|
|
- view_list.getAdapter().notifyDataSetChanged();
|
|
|
|
|
|
|
+ ViewUtil.notifyDataSetChanged(view_list);
|
|
|
mInitData();
|
|
mInitData();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -216,24 +233,34 @@ public abstract class BaseListActivity2<T> extends BaseActivity implements IRefr
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void notifyDataSetChanged() {
|
|
public void notifyDataSetChanged() {
|
|
|
- if (view_list == null)
|
|
|
|
|
- view_list = findViewById(R.id.view_list);
|
|
|
|
|
- if (empty_view == null)
|
|
|
|
|
- empty_view = findViewById(R.id.empty_view);
|
|
|
|
|
- loadMore = false;
|
|
|
|
|
|
|
+ if (view_list == null || empty_view == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
updateEmptyView();
|
|
updateEmptyView();
|
|
|
if (page == 1) {
|
|
if (page == 1) {
|
|
|
view_list.refreshComplete();
|
|
view_list.refreshComplete();
|
|
|
} else {
|
|
} else {
|
|
|
view_list.loadMoreComplete();
|
|
view_list.loadMoreComplete();
|
|
|
}
|
|
}
|
|
|
- view_list.getAdapter().notifyDataSetChanged();
|
|
|
|
|
|
|
+ ViewUtil.notifyDataSetChanged(view_list);
|
|
|
notifyData();
|
|
notifyData();
|
|
|
- view_list.getFootView().setVisibility(view_list.getAdapter().getItemCount() == 0 ? View.GONE : View.VISIBLE);
|
|
|
|
|
|
|
+ if(view_list.getAdapter() != null)
|
|
|
|
|
+ view_list.getFootView().setVisibility(view_list.getAdapter().getItemCount() == 0 ? View.GONE : View.VISIBLE);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
protected void updateEmptyView() {
|
|
protected void updateEmptyView() {
|
|
|
- CommonUtil.getInstance().updateEmptyView(empty_view, list.isEmpty());
|
|
|
|
|
|
|
+ if (useSelfEmpty()) {
|
|
|
|
|
+ switch (initDataStatus){
|
|
|
|
|
+ case STATUS_CACHE:
|
|
|
|
|
+ if(!list.isEmpty())
|
|
|
|
|
+ CommonUtil.getInstance().updateEmptyView(empty_view, false);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case STATUS_NET:
|
|
|
|
|
+ default:
|
|
|
|
|
+ CommonUtil.getInstance().updateEmptyView(empty_view, list.isEmpty());
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -265,4 +292,14 @@ public abstract class BaseListActivity2<T> extends BaseActivity implements IRefr
|
|
|
public void notifyData() {
|
|
public void notifyData() {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ protected int initDataStatus = STATUS_NONE;//加载数据的状态
|
|
|
|
|
+ public static final int STATUS_NONE = 0;
|
|
|
|
|
+ public static final int STATUS_ING = 1;
|
|
|
|
|
+ public static final int STATUS_CACHE = 2;//获取缓存数据中
|
|
|
|
|
+ public static final int STATUS_NET = 3;
|
|
|
|
|
+ public static final int STATUS_FINISH = 4;
|
|
|
|
|
+ //是否正在刷新或者加载更多数据
|
|
|
|
|
+ public boolean isLoadingData(){
|
|
|
|
|
+ return initDataStatus == STATUS_ING;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|