Commit 3b193e43 authored by Varun Patil's avatar Varun Patil

Fix popping back stack to calendar

parent 721b01f0
...@@ -64,6 +64,7 @@ public class CalendarFragment extends BaseFragment { ...@@ -64,6 +64,7 @@ public class CalendarFragment extends BaseFragment {
private FeedAdapter feedAdapter = null; private FeedAdapter feedAdapter = null;
private List<Event> events = new ArrayList<>(); private List<Event> events = new ArrayList<>();
private HashSet<CalendarDay> haveMonths = new HashSet<>(); private HashSet<CalendarDay> haveMonths = new HashSet<>();
private boolean initialized = false;
public CalendarFragment() { public CalendarFragment() {
...@@ -178,7 +179,13 @@ public class CalendarFragment extends BaseFragment { ...@@ -178,7 +179,13 @@ public class CalendarFragment extends BaseFragment {
private void updateEvents(CalendarDay calendarDay, final boolean setToday) { private void updateEvents(CalendarDay calendarDay, final boolean setToday) {
// Do not make duplicate calls // Do not make duplicate calls
if (!setToday && haveMonths.contains(calendarDay)) return; if (haveMonths.contains(calendarDay)) {
if (!setToday) {
return;
} else {
setupCalendar(true);
}
}
haveMonths.add(calendarDay); haveMonths.add(calendarDay);
// Parsers // Parsers
...@@ -187,9 +194,6 @@ public class CalendarFragment extends BaseFragment { ...@@ -187,9 +194,6 @@ public class CalendarFragment extends BaseFragment {
final SimpleDateFormat isoFormatter = new SimpleDateFormat(ISO_FORMAT); final SimpleDateFormat isoFormatter = new SimpleDateFormat(ISO_FORMAT);
isoFormatter.setTimeZone(utc); isoFormatter.setTimeZone(utc);
// Get the date to start at
final Date today = new Date();
// Get the start date // Get the start date
final Date startDate; final Date startDate;
try { try {
...@@ -223,35 +227,7 @@ public class CalendarFragment extends BaseFragment { ...@@ -223,35 +227,7 @@ public class CalendarFragment extends BaseFragment {
if (!events.contains(event)) events.add(event); if (!events.contains(event)) events.add(event);
} }
// Make the calendar visible if it isn't setupCalendar(setToday);
final LinearLayout calendarLayout = getView().findViewById(R.id.calendar_layout);
if (calendarLayout.getVisibility() == View.GONE) {
calendarLayout.setVisibility(VISIBLE);
getView().findViewById(R.id.loadingPanel).setVisibility(View.GONE);
AlphaAnimation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(250);
calendarLayout.startAnimation(anim);
}
// Initialize to show today's date
if (setToday) {
// Show today
try {
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
Date todayWithZeroTime = formatter.parse(formatter.format(today));
showEventsForDate(todayWithZeroTime);
} catch (ParseException ignored) {}
// Select today's date
final MaterialCalendarView matCalendarView = view.findViewById(R.id.simpleCalendarView);
matCalendarView.setSelectedDate(CalendarDay.today());
// Show the fab
showFab();
}
// Generate the decorators
showHeatMap(events);
} }
} }
...@@ -263,6 +239,42 @@ public class CalendarFragment extends BaseFragment { ...@@ -263,6 +239,42 @@ public class CalendarFragment extends BaseFragment {
}); });
} }
/** Show the calendar */
private void setupCalendar(boolean setToday) {
// Make the calendar visible if it isn't
final LinearLayout calendarLayout = getView().findViewById(R.id.calendar_layout);
if (calendarLayout.getVisibility() == View.GONE) {
calendarLayout.setVisibility(VISIBLE);
getView().findViewById(R.id.loadingPanel).setVisibility(View.GONE);
AlphaAnimation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(250);
calendarLayout.startAnimation(anim);
}
// Initialize to show today's date
final MaterialCalendarView matCalendarView = view.findViewById(R.id.simpleCalendarView);
if (setToday) {
// Select today's date
if (!initialized) {
initialized = true;
matCalendarView.setSelectedDate(CalendarDay.today());
}
// Show the fab
showFab();
}
// Show today
try {
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
Date todayWithZeroTime = formatter.parse(formatter.format(toDate(matCalendarView.getSelectedDate())));
showEventsForDate(todayWithZeroTime);
} catch (ParseException ignored) {}
// Generate the decorators
showHeatMap(events);
}
/** Build and show the heat map from the list of events */ /** Build and show the heat map from the list of events */
private void showHeatMap(List<Event> eventList) { private void showHeatMap(List<Event> eventList) {
// Build strength map for each date // Build strength map for each date
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment