|
|
@@ -1,10 +1,10 @@
|
|
|
-package com.kfzs.duanduan.fragment;
|
|
|
+package com.sheep.gamegroup.view.fragment;
|
|
|
|
|
|
import android.app.Activity;
|
|
|
import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.annotation.Nullable;
|
|
|
-import android.support.v7.widget.LinearLayoutManager;
|
|
|
+import android.support.v7.widget.RecyclerView;
|
|
|
import android.text.TextUtils;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
@@ -14,12 +14,11 @@ import android.widget.TextView;
|
|
|
import com.arialyy.annotations.Download;
|
|
|
import com.arialyy.aria.core.Aria;
|
|
|
import com.arialyy.aria.core.download.DownloadTask;
|
|
|
-import com.jcodecraeer.xrecyclerview.XRecyclerView;
|
|
|
import com.kfzs.android.view.tag.FlowLayout;
|
|
|
import com.kfzs.android.view.tag.TagAdapter;
|
|
|
import com.kfzs.android.view.tag.TagFlowLayout;
|
|
|
-import com.kfzs.duanduan.BaseCompatFragment;
|
|
|
import com.kfzs.duanduan.services.DownloadTaskService;
|
|
|
+import com.sheep.gamegroup.model.api.ApiService;
|
|
|
import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
import com.sheep.gamegroup.model.entity.FindApp;
|
|
|
import com.sheep.gamegroup.model.entity.FindItem;
|
|
|
@@ -27,10 +26,8 @@ import com.sheep.gamegroup.model.entity.FindTag;
|
|
|
import com.sheep.gamegroup.model.entity.HomeListEntity;
|
|
|
import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
import com.sheep.gamegroup.util.CommonUtil;
|
|
|
-import com.sheep.gamegroup.util.DataUtil;
|
|
|
import com.sheep.gamegroup.util.Jump2View;
|
|
|
import com.sheep.gamegroup.util.ListUtil;
|
|
|
-import com.sheep.gamegroup.util.SysAppUtil;
|
|
|
import com.sheep.gamegroup.util.ViewHolder;
|
|
|
import com.sheep.gamegroup.util.ViewUtil;
|
|
|
import com.sheep.gamegroup.view.adapter.AdbCommonRecycler;
|
|
|
@@ -40,18 +37,14 @@ import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
|
|
|
|
|
|
import org.afinal.simplecache.ApiKey;
|
|
|
-import org.greenrobot.eventbus.EventBus;
|
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
import java.util.Locale;
|
|
|
import java.util.Map;
|
|
|
|
|
|
-import butterknife.BindView;
|
|
|
-import butterknife.ButterKnife;
|
|
|
+import rx.Observable;
|
|
|
import rx.android.schedulers.AndroidSchedulers;
|
|
|
-import rx.functions.Action1;
|
|
|
import rx.schedulers.Schedulers;
|
|
|
|
|
|
import static android.content.Intent.ACTION_PACKAGE_ADDED;
|
|
|
@@ -59,74 +52,13 @@ import static android.content.Intent.ACTION_PACKAGE_REMOVED;
|
|
|
import static com.sheep.gamegroup.util.UMConfigUtils.Event.FIND_ITEM;
|
|
|
|
|
|
/**
|
|
|
- * Created by realicing on 2018/6/27.
|
|
|
+ * Created by realicing on 2018/9/7.
|
|
|
* realicing@sina.com
|
|
|
*/
|
|
|
-public class FgtFindChild extends BaseCompatFragment {
|
|
|
-
|
|
|
- private int page = 1;//页数
|
|
|
- private int per_page = DataUtil.PER_PAGE;
|
|
|
- private int type;
|
|
|
- public static FgtFindChild newInstance(int type){
|
|
|
- FgtFindChild fgt = new FgtFindChild();
|
|
|
- Bundle bundle = new Bundle();
|
|
|
- bundle.putInt("type", type);
|
|
|
- fgt.setArguments(bundle);
|
|
|
- return fgt;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
- Bundle bundle = getArguments();
|
|
|
- if(bundle != null){
|
|
|
- type = bundle.getInt("type", 0);
|
|
|
- }
|
|
|
- EventBus.getDefault().register(this);
|
|
|
- Aria.download(this).register();
|
|
|
- }
|
|
|
-
|
|
|
- private Activity activity;
|
|
|
+public class FgtFindChild extends BaseListFragment<FindItem> {
|
|
|
@Override
|
|
|
- protected void initView(Bundle savedInstanceState) {
|
|
|
- setContentView(R.layout.net_empty_xrecycler);
|
|
|
- activity = getActivity();
|
|
|
- ButterKnife.bind(this, mContentView);
|
|
|
- initView();
|
|
|
- initData();
|
|
|
- }
|
|
|
-
|
|
|
- @BindView(R.id.title)
|
|
|
- View title;
|
|
|
-// @BindView(R.id.refresh)
|
|
|
-// SwipeRefreshLayout refresh;
|
|
|
- @BindView(R.id.empty_view)
|
|
|
- View empty_view;
|
|
|
- @BindView(R.id.check_net_ll)
|
|
|
- View check_net_ll;
|
|
|
- @BindView(R.id.view_list)
|
|
|
- XRecyclerView view_list;
|
|
|
- private void initView(){
|
|
|
- title.setVisibility(View.GONE);
|
|
|
- view_list.setLoadingListener(new XRecyclerView.LoadingListener() {
|
|
|
- @Override
|
|
|
- public void onRefresh() {
|
|
|
- refreshData();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onLoadMore() {
|
|
|
- if(ListUtil.size(list) >= per_page*page){
|
|
|
- page += 1;
|
|
|
- initData();
|
|
|
- }else {
|
|
|
- view_list.setNoMore(true);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- ViewUtil.setBottomLine(view_list);
|
|
|
- view_list.setLayoutManager(new LinearLayoutManager(SheepApp.getInstance()));
|
|
|
- view_list.setAdapter(new AdbCommonRecycler<FindItem>(SheepApp.getInstance(), list){
|
|
|
+ protected RecyclerView.Adapter getAdapter() {
|
|
|
+ return new AdbCommonRecycler<FindItem>(SheepApp.getInstance(), list){
|
|
|
|
|
|
@Override
|
|
|
public int getItemViewType(int position) {
|
|
|
@@ -201,9 +133,47 @@ public class FgtFindChild extends BaseCompatFragment {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- });
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ protected String getKey(int page, int per_page) {
|
|
|
+ return ApiKey.articles(page, per_page, type);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected Observable<BaseMessage> getApi(ApiService apiService) {
|
|
|
+ return apiService.getFindList(page, per_page, type);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected Class<FindItem> getTClass() {
|
|
|
+ return FindItem.class;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void notifyData() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private int type;
|
|
|
+ public static FgtFindChild newInstance(int type){
|
|
|
+ FgtFindChild fgt = new FgtFindChild();
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
+ bundle.putInt("type", type);
|
|
|
+ fgt.setArguments(bundle);
|
|
|
+ return fgt;
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ Bundle bundle = getArguments();
|
|
|
+ if(bundle != null){
|
|
|
+ type = bundle.getInt("type", 0);
|
|
|
+ }
|
|
|
+ Aria.download(this).register();
|
|
|
+ }
|
|
|
/**
|
|
|
* 点击一个发现元素
|
|
|
* @param item
|
|
|
@@ -229,17 +199,17 @@ public class FgtFindChild extends BaseCompatFragment {
|
|
|
}
|
|
|
FIND_ITEM.onEvent("find_id", item.getId());
|
|
|
SheepApp.getInstance().getNetComponent().getApiService().getFindItemAddClicks(item.getId())
|
|
|
- .subscribeOn(Schedulers.io())
|
|
|
- .observeOn(AndroidSchedulers.mainThread())
|
|
|
- .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
- @Override
|
|
|
- public void onNext(BaseMessage baseMessage) {
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onError(BaseMessage baseMessage) {
|
|
|
- }
|
|
|
- });
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -249,24 +219,24 @@ public class FgtFindChild extends BaseCompatFragment {
|
|
|
*/
|
|
|
private void openHomeListItem(FindItem item) {
|
|
|
SheepApp.getInstance().getNetComponent().getApiService().getHomeListItem(item.getHome_list_id())
|
|
|
- .subscribeOn(Schedulers.io())
|
|
|
- .observeOn(AndroidSchedulers.mainThread())
|
|
|
- .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
- @Override
|
|
|
- public void onNext(BaseMessage baseMessage) {
|
|
|
- HomeListEntity homeListEntity = baseMessage.getData(HomeListEntity.class);
|
|
|
- if(homeListEntity == null){
|
|
|
- G.showToast(R.string.error_data);
|
|
|
- return;
|
|
|
- }
|
|
|
- CommonUtil.getInstance().goWhere(activity, homeListEntity, "发现");
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onError(BaseMessage baseMessage) {
|
|
|
- G.showToast(baseMessage);
|
|
|
- }
|
|
|
- });
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ HomeListEntity homeListEntity = baseMessage.getData(HomeListEntity.class);
|
|
|
+ if(homeListEntity == null){
|
|
|
+ G.showToast(R.string.error_data);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ CommonUtil.getInstance().goWhere(activity, homeListEntity, "发现");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ G.showToast(baseMessage);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -288,66 +258,6 @@ public class FgtFindChild extends BaseCompatFragment {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void initData(){
|
|
|
- //先尝试获取缓存数据
|
|
|
- List<FindItem> newList = DataUtil.getInstance().getCacheList(ApiKey.articles(page, per_page, type), FindItem.class);
|
|
|
- loadList(newList);
|
|
|
- empty_view.setVisibility(View.INVISIBLE);
|
|
|
- SysAppUtil.checkNet(new Action1<Integer>() {
|
|
|
- @Override
|
|
|
- public void call(Integer result) {
|
|
|
- if(result != 0){//无网络
|
|
|
- if(check_net_ll != null)
|
|
|
- check_net_ll.setVisibility(View.VISIBLE);
|
|
|
- } else {
|
|
|
- if(check_net_ll != null)
|
|
|
- check_net_ll.setVisibility(View.GONE);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- SheepApp.getInstance().getNetComponent().getApiService().getFindList(page, per_page, type)
|
|
|
- .subscribeOn(Schedulers.io())
|
|
|
- .observeOn(AndroidSchedulers.mainThread())
|
|
|
- .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
- @Override
|
|
|
- public void onNext(BaseMessage baseMessage) {
|
|
|
- boolean isNewData = DataUtil.getInstance().isNewData(ApiKey.articles(page, per_page, type));
|
|
|
- if(isNewData) {
|
|
|
- List<FindItem> newList = baseMessage.getDatas(FindItem.class);
|
|
|
- loadList(newList);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onError(BaseMessage baseMessage){
|
|
|
- notifyDataSetChanged();
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- public void refreshData(){
|
|
|
- list.clear();
|
|
|
- view_list.getAdapter().notifyDataSetChanged();
|
|
|
- page = 1;
|
|
|
- initData();
|
|
|
- }
|
|
|
- private void loadList(List<FindItem> newList){
|
|
|
- ListUtil.addAll(list, newList);
|
|
|
- notifyDataSetChanged();
|
|
|
- }
|
|
|
-
|
|
|
- private void notifyDataSetChanged(){
|
|
|
- CommonUtil.getInstance().updateEmptyView(empty_view, list.isEmpty());
|
|
|
- if(page == 1){
|
|
|
- view_list.refreshComplete();
|
|
|
- } else {
|
|
|
- view_list.loadMoreComplete();
|
|
|
- }
|
|
|
- view_list.getAdapter().notifyDataSetChanged();
|
|
|
- }
|
|
|
- private List<FindItem> list = ListUtil.emptyList();
|
|
|
-
|
|
|
-
|
|
|
|
|
|
private Map<String, FindApp> findAppMap = new HashMap<>();
|
|
|
//获取任务对应的findApp
|
|
|
@@ -483,9 +393,4 @@ public class FgtFindChild extends BaseCompatFragment {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- @Override
|
|
|
- public void onDestroy() {
|
|
|
- super.onDestroy();
|
|
|
- EventBus.getDefault().unregister(this);
|
|
|
- }
|
|
|
}
|