|
@@ -2,12 +2,30 @@ package com.sheep.jiuyan.samllsheep.page.fragment;
|
|
|
|
|
|
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
|
import android.support.annotation.Nullable;
|
|
import android.support.annotation.Nullable;
|
|
|
|
|
+import android.support.v7.widget.LinearLayoutManager;
|
|
|
|
|
+import android.support.v7.widget.RecyclerView;
|
|
|
import android.view.LayoutInflater;
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewGroup;
|
|
|
|
|
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.base.BaseFragment;
|
|
import com.sheep.jiuyan.samllsheep.base.BaseFragment;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.net.NetManager;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.net.SheepCallback;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.net.Url;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.page.adapter.AdpTaskList;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.page.entry.TaskPublish;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.page.entry.WXAccount;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.BackDo;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.RecyleViewLoadMoreUtils;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.SpUtils;
|
|
|
|
|
+
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+import okhttp3.Call;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @ Created by Dlg
|
|
* @ Created by Dlg
|
|
@@ -19,6 +37,13 @@ import com.sheep.jiuyan.samllsheep.base.BaseFragment;
|
|
|
|
|
|
|
|
public class FgtMainPageOffline extends BaseFragment {
|
|
public class FgtMainPageOffline extends BaseFragment {
|
|
|
|
|
|
|
|
|
|
+ private ViewGroup mViewEmpty;
|
|
|
|
|
+ private ViewGroup mViewList;
|
|
|
|
|
+ private RecyclerView mRecyclerView;
|
|
|
|
|
+ private int mIntLastPage = 0;//上次的页码
|
|
|
|
|
+ private AdpTaskList mAdpTaskList;
|
|
|
|
|
+ private RecyleViewLoadMoreUtils mRecyleViewLoadMoreUtils;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public int getLayoutId() {
|
|
public int getLayoutId() {
|
|
|
return R.layout.fgt_main_page_offline;
|
|
return R.layout.fgt_main_page_offline;
|
|
@@ -26,12 +51,74 @@ public class FgtMainPageOffline extends BaseFragment {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void onViewCreated() {
|
|
public void onViewCreated() {
|
|
|
|
|
+ mViewEmpty = findViewById(R.id.layout_fgt_main_page_offline_empty);
|
|
|
|
|
+ mViewList = findViewById(R.id.layout_fgt_main_page_offline_task);
|
|
|
|
|
+ mRecyclerView = findViewById(R.id.recy_fgt_main_page_offline_task);
|
|
|
|
|
|
|
|
|
|
+ mRecyleViewLoadMoreUtils = new RecyleViewLoadMoreUtils();
|
|
|
|
|
+ mAdpTaskList = new AdpTaskList(getActivity());
|
|
|
|
|
+ mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
|
|
|
|
+ mRecyclerView.setAdapter(mAdpTaskList);
|
|
|
|
|
+ mRecyleViewLoadMoreUtils.setLoadMore(mRecyclerView, new BackDo() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void Run() {
|
|
|
|
|
+ initData(true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ initData(false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- public void initData(){
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 加载远端数据
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param isLoadMore
|
|
|
|
|
+ */
|
|
|
|
|
+ public void initData(final boolean isLoadMore) {
|
|
|
|
|
+ mIntLastPage = isLoadMore ? mIntLastPage + 1 : 1;
|
|
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
|
|
+ map.put("wx_open_id", SpUtils.getOpenId(getActivity()));
|
|
|
|
|
+ NetManager.get(Url.WXACCOUNT, map, getActivity(), new SheepCallback<List<WXAccount>>(getActivity()) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void success(List<WXAccount> wxAccounts) {
|
|
|
|
|
+ if (!isLoadMore) {
|
|
|
|
|
+// mAdpTaskList.clear();//暂时没有分页功能,就这样吧。
|
|
|
|
|
+ }
|
|
|
|
|
+ mAdpTaskList.add(new WXAccount());
|
|
|
|
|
+ mAdpTaskList.add(new WXAccount());
|
|
|
|
|
+ mAdpTaskList.add(new WXAccount());
|
|
|
|
|
+ mAdpTaskList.add(new WXAccount());
|
|
|
|
|
+ if (wxAccounts != null && wxAccounts.size() > 0) {
|
|
|
|
|
+ mAdpTaskList.addAll(wxAccounts);
|
|
|
|
|
+ mAdpTaskList.notifyDataSetChanged();
|
|
|
|
|
+ }
|
|
|
|
|
+ //TODO 请求的个数最好弄成统一管理的常量
|
|
|
|
|
+ mRecyleViewLoadMoreUtils.setmIsLoading(wxAccounts.size() != 10);
|
|
|
|
|
+ reFreshView();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //TODO 你的框架不知道哪个是失败必须执行的,要添加拒绝加载更多等
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onFailure(Call call, IOException e) {
|
|
|
|
|
+ super.onFailure(call, e);
|
|
|
|
|
+ mRecyleViewLoadMoreUtils.setmIsLoading(true);
|
|
|
|
|
+ reFreshView();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void otherCode(int code, String string) {
|
|
|
|
|
+ mRecyleViewLoadMoreUtils.setmIsLoading(true);
|
|
|
|
|
+ reFreshView();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 刷新UI显示
|
|
|
|
|
+ */
|
|
|
|
|
+ private void reFreshView() {
|
|
|
|
|
+ mViewEmpty.setVisibility(mAdpTaskList.getItemCount() > 0 ? View.GONE : View.VISIBLE);
|
|
|
|
|
+ mViewList.setVisibility(mAdpTaskList.getItemCount() > 0 ? View.VISIBLE : View.GONE);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|