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);
}
Aggregations