Search in sources :

Example 1 with RecyclerViewMaterialAdapter

use of com.github.florent37.materialviewpager.adapter.RecyclerViewMaterialAdapter 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)

Example 2 with RecyclerViewMaterialAdapter

use of com.github.florent37.materialviewpager.adapter.RecyclerViewMaterialAdapter in project CoCoin by Nightonke.

the class TagViewFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.setHasFixedSize(true);
    if (position == 0) {
        for (CoCoinRecord coCoinRecord : RecordManager.RECORDS) {
            list.add(coCoinRecord);
        }
    }
    if (position == 1) {
        for (CoCoinRecord coCoinRecord : RecordManager.RECORDS) {
            list.add(coCoinRecord);
        }
    } else {
        for (CoCoinRecord coCoinRecord : RecordManager.RECORDS) {
            if (coCoinRecord.getTag() == RecordManager.TAGS.get(position).getId()) {
                list.add(coCoinRecord);
            }
        }
    }
    mAdapter = new RecyclerViewMaterialAdapter(new TagViewRecyclerViewAdapter(list, mContext, position));
    mRecyclerView.setAdapter(mAdapter);
    MaterialViewPagerHelper.registerRecyclerView(getActivity(), mRecyclerView, null);
}
Also used : TagViewRecyclerViewAdapter(com.nightonke.saver.adapter.TagViewRecyclerViewAdapter) RecyclerView(android.support.v7.widget.RecyclerView) RecyclerViewMaterialAdapter(com.github.florent37.materialviewpager.adapter.RecyclerViewMaterialAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) CoCoinRecord(com.nightonke.saver.model.CoCoinRecord)

Example 3 with RecyclerViewMaterialAdapter

use of com.github.florent37.materialviewpager.adapter.RecyclerViewMaterialAdapter in project CoCoin by Nightonke.

the class MonthViewFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.setHasFixedSize(true);
    if (!IS_EMPTY) {
        RecordManager recordManager = RecordManager.getInstance(mContext.getApplicationContext());
        int startYear = recordManager.RECORDS.get(0).getCalendar().get(Calendar.YEAR);
        int startMonth = recordManager.RECORDS.get(0).getCalendar().get(Calendar.MONTH);
        int nowYear = startYear + (startMonth + (monthNumber - position - 1)) / 12;
        int nowMonth = (startMonth + (monthNumber - position - 1)) % 12;
        Calendar monthStart = Calendar.getInstance();
        Calendar monthEnd = Calendar.getInstance();
        monthStart.set(nowYear, nowMonth, 1, 0, 0, 0);
        monthStart.add(Calendar.MILLISECOND, 0);
        monthEnd.set(nowYear, nowMonth, monthStart.getActualMaximum(Calendar.DAY_OF_MONTH), 23, 59, 59);
        monthEnd.add(Calendar.MILLISECOND, 0);
        Calendar leftRange = CoCoinUtil.GetThisWeekLeftRange(monthStart);
        Calendar rightRange = CoCoinUtil.GetThisWeekRightRange(monthEnd);
        int start = -1;
        int end = 0;
        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;
                }
            }
        }
        mAdapter = new RecyclerViewMaterialAdapter(new MonthViewRecyclerViewAdapter(start, end, mContext, position, monthNumber));
        mRecyclerView.setAdapter(mAdapter);
    } else {
        mAdapter = new RecyclerViewMaterialAdapter(new MonthViewRecyclerViewAdapter(-1, -1, mContext, 0, -1));
        mRecyclerView.setAdapter(mAdapter);
    }
    MaterialViewPagerHelper.registerRecyclerView(getActivity(), mRecyclerView, null);
}
Also used : RecordManager(com.nightonke.saver.model.RecordManager) MonthViewRecyclerViewAdapter(com.nightonke.saver.adapter.MonthViewRecyclerViewAdapter) Calendar(java.util.Calendar) RecyclerView(android.support.v7.widget.RecyclerView) RecyclerViewMaterialAdapter(com.github.florent37.materialviewpager.adapter.RecyclerViewMaterialAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3 RecyclerViewMaterialAdapter (com.github.florent37.materialviewpager.adapter.RecyclerViewMaterialAdapter)3 RecyclerView (android.support.v7.widget.RecyclerView)2 RecordManager (com.nightonke.saver.model.RecordManager)2 Calendar (java.util.Calendar)2 MonthViewRecyclerViewAdapter (com.nightonke.saver.adapter.MonthViewRecyclerViewAdapter)1 TagViewRecyclerViewAdapter (com.nightonke.saver.adapter.TagViewRecyclerViewAdapter)1 TodayViewRecyclerViewAdapter (com.nightonke.saver.adapter.TodayViewRecyclerViewAdapter)1 CoCoinRecord (com.nightonke.saver.model.CoCoinRecord)1