-
Notifications
You must be signed in to change notification settings - Fork 90
Open
Description
I noticed in the MainActivity the calendar often would leave empty rows before and after.
For example for Jan 2023 the calendar would create 7 empty slots before, thus creating an empty row, causing rather ugly browsing.
I updated the code for myself from the 'daysInMonthArray' to prevent generating rows before and after to enhance user browsing experience.
// Define current day of week
int dayOfWeek = firstOfMonth.getDayOfWeek().getValue();
// Define maximum amount of iterations
int dayOfWeekIterator = 42;
// Define days per week
int daysPerWeek = 7;
// Loop through the max amount of entries of days if sorted per 7
for(int i = 1; i <= dayOfWeekIterator; i++)
{
// Scenarios for empty slots:
// - BEFORE: Iterator is below current day of week
// - BEFORE: Current weekday is not 7 (empty row before)
// - AFTER: Iterator is not above days in month + current week day.
// - AFTER: Current iterator is not creating empty slots with 7 days to go (empty row after)
if((i <= dayOfWeek && dayOfWeek != daysPerWeek) || i > daysInMonth + dayOfWeek)
{
// Prevent making an empty row after
if((dayOfWeekIterator - i) == (daysPerWeek - 1)) {
break;
}
// Add empty slot
else {
daysInMonthArray.add("");
}
}
else
{
// If not below 0, has to be declared to prevent empty row before
if(i - dayOfWeek > 0) {
// Add current weekday
daysInMonthArray.add(String.valueOf(i - dayOfWeek));
}
}
}
Metadata
Metadata
Assignees
Labels
No labels