Search in sources :

Example 1 with TodayViewRecyclerViewAdapter

use of com.nightonke.saver.adapter.TodayViewRecyclerViewAdapter in project CoCoin by Nightonke.

the class TodayViewFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
    layoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.setHasFixedSize(true);
    Calendar now = Calendar.getInstance();
    Calendar leftRange;
    Calendar rightRange;
    RecordManager recordManager = RecordManager.getInstance(mContext.getApplicationContext());
    int start = -1;
    int end = 0;
    switch(position) {
        case TODAY:
            leftRange = CoCoinUtil.GetTodayLeftRange(now);
            for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
                if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
                    end = i + 1;
                    break;
                }
                if (start == -1) {
                    start = i;
                }
            }
            break;
        case YESTERDAY:
            leftRange = CoCoinUtil.GetYesterdayLeftRange(now);
            rightRange = CoCoinUtil.GetYesterdayRightRange(now);
            for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
                if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
                    end = i + 1;
                    break;
                } else if (!recordManager.RECORDS.get(i).getCalendar().after(rightRange)) {
                    if (start == -1) {
                        start = i;
                    }
                }
            }
            break;
        case THIS_WEEK:
            leftRange = CoCoinUtil.GetThisWeekLeftRange(now);
            for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
                if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
                    end = i + 1;
                    break;
                }
                if (start == -1) {
                    start = i;
                }
            }
            break;
        case LAST_WEEK:
            leftRange = CoCoinUtil.GetLastWeekLeftRange(now);
            rightRange = CoCoinUtil.GetLastWeekRightRange(now);
            for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
                if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
                    end = i + 1;
                    break;
                } else if (recordManager.RECORDS.get(i).getCalendar().before(rightRange)) {
                    if (start == -1) {
                        start = i;
                    }
                }
            }
            break;
        case THIS_MONTH:
            leftRange = CoCoinUtil.GetThisMonthLeftRange(now);
            for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
                if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
                    end = i + 1;
                    break;
                }
                if (start == -1) {
                    start = i;
                }
            }
            break;
        case LAST_MONTH:
            leftRange = CoCoinUtil.GetLastMonthLeftRange(now);
            rightRange = CoCoinUtil.GetLastMonthRightRange(now);
            for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
                if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
                    end = i + 1;
                    break;
                } else if (recordManager.RECORDS.get(i).getCalendar().before(rightRange)) {
                    if (start == -1) {
                        start = i;
                    }
                }
            }
            break;
        case THIS_YEAR:
            leftRange = CoCoinUtil.GetThisYearLeftRange(now);
            for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
                if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
                    end = i + 1;
                    break;
                }
                if (start == -1) {
                    start = i;
                }
            }
            break;
        case LAST_YEAR:
            leftRange = CoCoinUtil.GetLastYearLeftRange(now);
            rightRange = CoCoinUtil.GetLastYearRightRange(now);
            for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
                if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
                    end = i + 1;
                    break;
                } else if (recordManager.RECORDS.get(i).getCalendar().before(rightRange)) {
                    if (start == -1) {
                        start = i;
                    }
                }
            }
            break;
    }
    adapter = new TodayViewRecyclerViewAdapter(start, end, mContext, position);
    mAdapter = new RecyclerViewMaterialAdapter(adapter);
    mRecyclerView.setAdapter(mAdapter);
    MaterialViewPagerHelper.registerRecyclerView(getActivity(), mRecyclerView, null);
}
Also used : RecordManager(com.nightonke.saver.model.RecordManager) Calendar(java.util.Calendar) TodayViewRecyclerViewAdapter(com.nightonke.saver.adapter.TodayViewRecyclerViewAdapter) RecyclerViewMaterialAdapter(com.github.florent37.materialviewpager.adapter.RecyclerViewMaterialAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerViewMaterialAdapter (com.github.florent37.materialviewpager.adapter.RecyclerViewMaterialAdapter)1 TodayViewRecyclerViewAdapter (com.nightonke.saver.adapter.TodayViewRecyclerViewAdapter)1 RecordManager (com.nightonke.saver.model.RecordManager)1 Calendar (java.util.Calendar)1