Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty rows before and after #5

Open
Orifiael opened this issue Jan 19, 2023 · 1 comment
Open

Empty rows before and after #5

Orifiael opened this issue Jan 19, 2023 · 1 comment

Comments

@Orifiael
Copy link

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));
            }
        }
    }
@agrawalswapnesh
Copy link

Hi @Orifiael , this code was super helpful. How can we add dates from previous and next months so that it looks continuous in the UI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants