Search in sources :

Example 1 with MonthViewRecyclerViewAdapter

use of com.nightonke.saver.adapter.MonthViewRecyclerViewAdapter 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)1 RecyclerView (android.support.v7.widget.RecyclerView)1 RecyclerViewMaterialAdapter (com.github.florent37.materialviewpager.adapter.RecyclerViewMaterialAdapter)1 MonthViewRecyclerViewAdapter (com.nightonke.saver.adapter.MonthViewRecyclerViewAdapter)1 RecordManager (com.nightonke.saver.model.RecordManager)1 Calendar (java.util.Calendar)1