Просмотр исходного кода

足迹中显示每日足迹数量

zengjiebin лет назад: 7
Родитель
Сommit
9a7c8200a9

+ 8 - 0
app/src/main/java/com/sheep/gamegroup/model/api/ApiService.java

@@ -1455,5 +1455,13 @@ public interface ApiService {
      */
     @GET(ApiKey.getUserFootPrintList)
     Observable<BaseMessage> getUserFootPrintList(@Query("page") int page, @Query("per_page") int per_page, @Query("date") String date);
+    /**
+     * 小绵羊3.4.5
+     * 查询足迹/我的足迹日期数量列表
+     * start_date * string (query)	 查询开始日期年月,如: 2018-11-01
+     * end_date * string (query) 查询结束日期年月,如: 2018-11-30
+     */
+    @GET(ApiKey.getUserFootPrintDateCount)
+    Observable<BaseMessage> getUserFootPrintDateCount(@Query("start_date") String start_date, @Query("end_date") String end_date);
 //---------------------------end 小绵羊3.4.5 足迹-------------------------------------
 }

+ 46 - 0
app/src/main/java/com/sheep/gamegroup/model/entity/FootprintCountRespons.java

@@ -0,0 +1,46 @@
+package com.sheep.gamegroup.model.entity;
+
+import android.text.TextUtils;
+
+import com.kfzs.duanduan.utils.NumberFormatUtils;
+import com.sheep.gamegroup.util.ListUtil;
+import com.sheep.gamegroup.util.StringUtils;
+
+import java.util.ArrayList;
+
+/**
+ * Created by realicing on 2018/11/26.
+ * realicing@sina.com
+ * 小绵羊3.4.5新增--足迹--某一天的足迹数量
+ */
+public class FootprintCountRespons {
+    private String date;
+    private int count;
+
+    public String getDate() {
+        return date;
+    }
+
+    public void setDate(String date) {
+        this.date = date;
+    }
+
+    public int getCount() {
+        return count;
+    }
+
+    public void setCount(int count) {
+        this.count = count;
+    }
+
+
+    //获取对应的天数
+    public int getDay() {
+        if(!TextUtils.isEmpty(date)) {
+            ArrayList<String> arrayList = StringUtils.getAllSatisfyStr(date, "\\d+");
+            String item = ListUtil.getLast(arrayList);
+            return NumberFormatUtils.parseInteger(item);
+        }
+        return 1;
+    }
+}

+ 37 - 56
app/src/main/java/com/sheep/gamegroup/view/fragment/BaseListFragment4.java

@@ -2,18 +2,18 @@ package com.sheep.gamegroup.view.fragment;
 
 import android.app.Activity;
 import android.support.v7.widget.RecyclerView;
-import android.view.View;
 
-import com.sheep.gamegroup.absBase.BaseRefreshLoadMoreFragment;
+import com.chad.library.adapter.base.BaseQuickAdapter;
+import com.chad.library.adapter.base.BaseViewHolder;
 import com.sheep.gamegroup.model.api.ApiService;
 import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.util.SheepSubscriber;
-import com.sheep.gamegroup.util.CommonUtil;
 import com.sheep.gamegroup.util.Conversion;
 import com.sheep.gamegroup.util.DataUtil;
 import com.sheep.gamegroup.util.ListUtil;
 import com.sheep.gamegroup.util.ViewUtil;
 import com.sheep.jiuyan.samllsheep.SheepApp;
+import com.sheep.jiuyan.samllsheep.base.BaseFragment;
 
 import java.util.List;
 
@@ -22,34 +22,22 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
 import io.reactivex.schedulers.Schedulers;
 
 /**
- * Created by realicing on 2018/10/9.
+ * Created by realicing on 2018/11/26.
  * realicing@sina.com
- * 使用普通的RecyclerView来显示列表,可配合SmartRefreshLayout和ViewPager使用(setSmartRefreshLayout和setViewPager)
+ * 使用普通的RecyclerView来显示列表,配合BaseQuickAdapter来刷新数据与加载更多
  */
-public abstract class BaseListFragment4<T> extends BaseRefreshLoadMoreFragment {
+public abstract class BaseListFragment4<T> extends BaseFragment {
 
     protected Activity activity;
-    protected View empty_view;
     protected RecyclerView view_list;
+    protected BaseQuickAdapter<T, BaseViewHolder> adapter;
 
     @Override
     public void onViewCreated() {
         activity = getActivity();
         initView();
         initListener();
-        switch (refreshDataType()) {
-            case REFRESH_ON_CREATE:
-                refreshData();
-                break;
-            case REFRESH_ON_RESUME:
-                break;
-            case REFRESH_ON_YOURSELF:
-            default:
-                notifyDataSetChanged();
-                break;
-        }
-        if (!useSelfEmpty() && empty_view != null)
-            empty_view.setVisibility(View.GONE);
+        initLoadMoreListener();
     }
 
 
@@ -72,10 +60,16 @@ public abstract class BaseListFragment4<T> extends BaseRefreshLoadMoreFragment {
             initData();
         } else {
             setNoMore(true);
-            refreshOrLoadMoreComplete();
         }
     }
 
+    protected void setNoMore(boolean noMore) {
+        if (noMore)
+            if (adapter != null)
+                adapter.loadMoreEnd(true);
+
+    }
+
     protected List<T> list = ListUtil.emptyList();
     protected List<T> lastCacheList = ListUtil.emptyList();
 
@@ -131,40 +125,32 @@ public abstract class BaseListFragment4<T> extends BaseRefreshLoadMoreFragment {
         return baseMessage.getDatas(getTClass());
     }
 
-    @Override
-    public void onResume() {
-        super.onResume();
-        if (refreshDataType() == REFRESH_ON_RESUME) {
-            refreshData();
-        }
-    }
-
-    //使用布局中自带的无数据空view
-    public boolean useSelfEmpty() {
-        return true;
-    }
-
-    public static final int REFRESH_ON_CREATE = 0;
-    public static final int REFRESH_ON_RESUME = 1;
-    public static final int REFRESH_ON_YOURSELF = -1;
-
-    /**
-     * 在哪里初始化数据:0 onViewCreated后, 1 onResume后, -1 不初始化
-     *
-     * @return
-     */
-    public int refreshDataType() {
-        return REFRESH_ON_CREATE;
-    }
 
     public void clear() {
         lastMessage = null;
         setNoMore(false);
 
-        if (useSelfEmpty() && empty_view != null)
-            empty_view.setVisibility(View.INVISIBLE);
         list.clear();
         page = 1;
+        initLoadMoreListener();
+    }
+
+    protected void initLoadMoreListener() {
+        if (adapter != null && view_list != null) {
+//            adapter.setUpFetchListener(new BaseQuickAdapter.UpFetchListener() {
+//                @Override
+//                public void onUpFetch() {
+//                    LogUtil.println("BaseListFragment4", "onUpFetch");
+//                    refreshData();
+//                }
+//            });
+            adapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
+                @Override
+                public void onLoadMoreRequested() {
+                    loadMoreData();
+                }
+            }, view_list);
+        }
     }
 
     //通过刷新来重新加载数据
@@ -184,21 +170,16 @@ public abstract class BaseListFragment4<T> extends BaseRefreshLoadMoreFragment {
 
     //刷新数据
     public void notifyDataSetChanged() {
-        if (view_list == null || empty_view == null) {
-            return;
-        }
         updateEmptyView();
         ViewUtil.notifyDataSetChanged(view_list);
-        refreshOrLoadMoreComplete();
+        if (adapter != null)
+            adapter.loadMoreComplete();
     }
 
     //是否显示无数据占位图
     protected void updateEmptyView() {
-        if (useSelfEmpty())
-            CommonUtil.getInstance().updateEmptyView(empty_view, list.isEmpty());
-    }
 
-    protected abstract RecyclerView.Adapter getAdapter();
+    }
 
     protected abstract String getKey(int page, int per_page);
 

+ 69 - 58
app/src/main/java/com/sheep/gamegroup/view/fragment/FgtFootprint.java

@@ -1,5 +1,6 @@
 package com.sheep.gamegroup.view.fragment;
 
+import android.graphics.Color;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
 import android.view.LayoutInflater;
@@ -14,16 +15,18 @@ import com.haibin.calendarview.CalendarLayout;
 import com.haibin.calendarview.CalendarView;
 import com.haibin.calendarviewproject.custom.CustomMonthView;
 import com.haibin.calendarviewproject.custom.CustomWeekView;
-import com.kfzs.appstore.utils.adapter.recyclerview.RecyclerViewAdapter;
-import com.kfzs.appstore.utils.adapter.recyclerview.ViewHolder;
 import com.sheep.gamegroup.model.api.ApiService;
 import com.sheep.gamegroup.model.entity.BaseMessage;
+import com.sheep.gamegroup.model.entity.FootprintCountRespons;
 import com.sheep.gamegroup.model.entity.UserFootprint;
+import com.sheep.gamegroup.model.util.SheepSubscriber;
 import com.sheep.gamegroup.util.ListUtil;
+import com.sheep.gamegroup.util.TestUtil;
 import com.sheep.gamegroup.util.TimeUtil;
 import com.sheep.gamegroup.util.ViewUtil;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
+import com.sheep.jiuyan.samllsheep.utils.G;
 import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
 
 import org.afinal.simplecache.ApiKey;
@@ -35,6 +38,9 @@ import java.util.Map;
 
 import butterknife.BindView;
 import io.reactivex.Observable;
+import io.reactivex.android.schedulers.AndroidSchedulers;
+import io.reactivex.schedulers.Schedulers;
+import rx.functions.Action1;
 
 /**
  * Created by realicing on 2018/9/17.
@@ -67,6 +73,7 @@ public class FgtFootprint extends BaseListFragment4<UserFootprint> {
 
     @Override
     public void initView() {
+        per_page = 1;
         CustomMonthView.class.getSimpleName();
         CustomWeekView.class.getSimpleName();
         TitleBarUtils
@@ -75,9 +82,9 @@ public class FgtFootprint extends BaseListFragment4<UserFootprint> {
                 .setTitle(getView(), "足迹");
 
         view_list = mRecyclerView;
-
+        initAdapter();
         mRecyclerView.setLayoutManager(new LinearLayoutManager(SheepApp.getInstance()));
-        mRecyclerView.setAdapter(getAdapter());
+        mRecyclerView.setAdapter(adapter);
 
         int maxYear = mCalendarView.getCurYear();
         int maxYearMonth = mCalendarView.getCurMonth();
@@ -100,6 +107,23 @@ public class FgtFootprint extends BaseListFragment4<UserFootprint> {
         });
     }
 
+    protected void initAdapter() {
+        adapter = new BaseQuickAdapter<UserFootprint, BaseViewHolder>(R.layout.item_my_focus, list) {
+            @Override
+            protected void convert(BaseViewHolder holder, UserFootprint item) {
+                ImageView item_my_focus_iv = holder.itemView.findViewById(R.id.item_my_focus_iv);
+                TextView item_my_focus_info_tv = holder.itemView.findViewById(R.id.item_my_focus_info_tv);
+                TextView item_my_focus_tv = holder.itemView.findViewById(R.id.item_my_focus_tv);
+                ViewUtil.setVisibility(item_my_focus_tv, false);
+
+                ViewUtil.setAvatar(item_my_focus_iv, item.getPic());
+                ViewUtil.setText(item_my_focus_info_tv, item.getInfo());
+            }
+        };
+        View headerView = LayoutInflater.from(SheepApp.getInstance()).inflate(R.layout.header_foot_print, null);
+        adapter.addHeaderView(headerView);
+    }
+
     private void checkHeaderView(int year, int month) {
         ViewUtil.setText(header_foot_print_date_tv, String.format(Locale.CHINA, "%d年%d月", year, month));
         Calendar firstCalendar = new Calendar();
@@ -112,7 +136,8 @@ public class FgtFootprint extends BaseListFragment4<UserFootprint> {
         lastCalendar.setDay(TimeUtil.getTotalDay(month));
         checkHeaderView(firstCalendar, lastCalendar);
     }
-    private void checkHeaderView(Calendar firstCalendar, Calendar lastCalendar){
+
+    private void checkHeaderView(Calendar firstCalendar, Calendar lastCalendar) {
         Calendar minCalendar = mCalendarView.getMinRangeCalendar();
         Calendar maxCalendar = mCalendarView.getMaxRangeCalendar();
         boolean canScrollToPre = minCalendar.compareTo(firstCalendar) < 0;
@@ -122,10 +147,11 @@ public class FgtFootprint extends BaseListFragment4<UserFootprint> {
         ViewUtil.setEnabled(header_foot_print_next_iv, canScrollToNext);
         ViewUtil.setEnabled(header_foot_print_next_v, canScrollToNext);
     }
+
     private void checkHeaderView(List<Calendar> weekCalendars) {
         Calendar firstCalendar = ListUtil.getItem(weekCalendars, 0);
         Calendar lastCalendar = ListUtil.getLast(weekCalendars);
-        if(firstCalendar != null && lastCalendar != null) {
+        if (firstCalendar != null && lastCalendar != null) {
             int year = firstCalendar.getYear();
             int month = firstCalendar.getMonth();
             ViewUtil.setText(header_foot_print_date_tv, String.format(Locale.CHINA, "%d年%d月", year, month));
@@ -140,6 +166,7 @@ public class FgtFootprint extends BaseListFragment4<UserFootprint> {
             @Override
             public void onMonthChange(int year, int month) {
                 checkHeaderView(year, month);
+                initFootprintCountRespons(year, month);
             }
         });
         mCalendarView.setOnWeekChangeListener(new CalendarView.OnWeekChangeListener() {
@@ -151,7 +178,7 @@ public class FgtFootprint extends BaseListFragment4<UserFootprint> {
         mCalendarView.setOnViewChangeListener(new CalendarView.OnViewChangeListener() {
             @Override
             public void onViewChange(boolean isMonthView) {
-                if(isMonthView){
+                if (isMonthView) {
                     checkHeaderView(mCalendarView.getCurYear(), mCalendarView.getCurMonth());
                 } else {
                     checkHeaderView(mCalendarView.getCurrentWeekCalendars());
@@ -172,68 +199,56 @@ public class FgtFootprint extends BaseListFragment4<UserFootprint> {
         });
     }
 
-    @Override
-    public void initData() {
-        super.initData();
+    //初始化足迹数量
+    private void initFootprintCountRespons(final int year, final int month) {
+        String start_date = String.format(Locale.CHINA, "%d-%02d-%02d", year, month, 1);
+        String end_date = String.format(Locale.CHINA, "%d-%02d-%02d", year, month, TimeUtil.getTotalDay(month));
+        SheepApp.getInstance().getNetComponent().getApiService().getUserFootPrintDateCount(start_date, end_date)
+                        .subscribeOn(Schedulers.io())
+                        .observeOn(AndroidSchedulers.mainThread())
+                        .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
+                            @Override
+                            public void onNext(BaseMessage baseMessage) {
+                                List<FootprintCountRespons> newList = baseMessage.getDataList(FootprintCountRespons.class);
+                                if(!ListUtil.isEmpty(newList)){
+                                    loadFootprintCountList(year, month, newList);
+                                }
+                            }
 
-        int year = mCalendarView.getCurYear();
-        int month = mCalendarView.getCurMonth();
+                            @Override
+                            public void onError(BaseMessage baseMessage) {
+                                if(TestUtil.isDev())
+                                    G.showToast(baseMessage);
+                            }
+                        });
+    }
 
-        Map<String, Calendar> map = new HashMap<>();
-        map.put(getSchemeCalendar(year, month, 3, 0xFF40db25, "假").toString(),
-                getSchemeCalendar(year, month, 3, 0xFF40db25, "假"));
-        map.put(getSchemeCalendar(year, month, 6, 0xFFe69138, "事").toString(),
-                getSchemeCalendar(year, month, 6, 0xFFe69138, "事"));
-        map.put(getSchemeCalendar(year, month, 9, 0xFFdf1356, "议").toString(),
-                getSchemeCalendar(year, month, 9, 0xFFdf1356, "议"));
-        map.put(getSchemeCalendar(year, month, 13, 0xFFedc56d, "记").toString(),
-                getSchemeCalendar(year, month, 13, 0xFFedc56d, "记"));
-        map.put(getSchemeCalendar(year, month, 14, 0xFFedc56d, "记").toString(),
-                getSchemeCalendar(year, month, 14, 0xFFedc56d, "记"));
-        map.put(getSchemeCalendar(year, month, 15, 0xFFaacc44, "假").toString(),
-                getSchemeCalendar(year, month, 15, 0xFFaacc44, "假"));
-        map.put(getSchemeCalendar(year, month, 18, 0xFFbc13f0, "记").toString(),
-                getSchemeCalendar(year, month, 18, 0xFFbc13f0, "记"));
-        map.put(getSchemeCalendar(year, month, 25, 0xFF13acf0, "假").toString(),
-                getSchemeCalendar(year, month, 25, 0xFF13acf0, "假"));
-        map.put(getSchemeCalendar(year, month, 27, 0xFF13acf0, "多").toString(),
-                getSchemeCalendar(year, month, 27, 0xFF13acf0, "多"));
+    private void loadFootprintCountList(final int year, final int month, List<FootprintCountRespons> newList) {
+        final Map<String, Calendar> map = new HashMap<>();
+        ListUtil.forEach(newList, new Action1<FootprintCountRespons>() {
+                    @Override
+                    public void call(FootprintCountRespons item) {
+                        if(item != null && item.getCount() > 0) {
+                            Calendar calendar = getSchemeCalendar(year, month, item.getDay(), String.valueOf(item.getCount()));
+                            map.put(calendar.toString(), calendar);
+                        }
+                    }
+                });
         //此方法在巨大的数据量上不影响遍历性能,推荐使用
         mCalendarView.setSchemeDate(map);
 
     }
 
-    private Calendar getSchemeCalendar(int year, int month, int day, int color, String text) {
+    private Calendar getSchemeCalendar(int year, int month, int day, String text) {
         Calendar calendar = new Calendar();
         calendar.setYear(year);
         calendar.setMonth(month);
         calendar.setDay(day);
-        calendar.setSchemeColor(color);//如果单独标记颜色、则会使用这个颜色
+        calendar.setSchemeColor(Color.RED);//如果单独标记颜色、则会使用这个颜色
         calendar.setScheme(text);
-        calendar.addScheme(new Calendar.Scheme());
-        calendar.addScheme(0xFF008800, "假");
-        calendar.addScheme(0xFF008800, "节");
         return calendar;
     }
 
-    @Override
-    protected RecyclerView.Adapter getAdapter() {
-        BaseQuickAdapter<UserFootprint, BaseViewHolder> adapter = new BaseQuickAdapter<UserFootprint, BaseViewHolder>(R.layout.item_my_focus, list) {
-            @Override
-            protected void convert(BaseViewHolder holder, UserFootprint item) {
-                ImageView item_my_focus_iv = holder.itemView.findViewById(R.id.item_my_focus_iv);
-                TextView item_my_focus_info_tv = holder.itemView.findViewById(R.id.item_my_focus_info_tv);
-                TextView item_my_focus_tv = holder.itemView.findViewById(R.id.item_my_focus_tv);
-                ViewUtil.setVisibility(item_my_focus_tv, false);
-
-                ViewUtil.setAvatar(item_my_focus_iv, item.getPic());
-                ViewUtil.setText(item_my_focus_info_tv, item.getInfo());
-            }
-        };
-        View headerView = LayoutInflater.from(SheepApp.getInstance()).inflate(R.layout.header_foot_print, null);
-        adapter.addHeaderView(headerView);
-        return adapter;
-    }
 
     private String date;
 
@@ -252,8 +267,4 @@ public class FgtFootprint extends BaseListFragment4<UserFootprint> {
         return UserFootprint.class;
     }
 
-    @Override
-    public int refreshDataType() {
-        return REFRESH_ON_YOURSELF;
-    }
 }

+ 1 - 0
app/src/main/java/org/afinal/simplecache/ApiKey.java

@@ -58,6 +58,7 @@ public class ApiKey {
     public static final String getGameUserGameFocusList = "app/game_user/game_focus/list";
     //足迹
     public static final String getUserFootPrintList = "app/user/footprint/list";
+    public static final String getUserFootPrintDateCount = "app/user/footprint/date_count";
     public static final String pageKeyUrl(String baseUrl, int page, int per_page){
         return String.format(Locale.CHINA, "%s?page=%d&per_page=%d", baseUrl, page, per_page);
     }