hi-manshu / Kalendar

Kalendar is a powerful and customizable calendar library for Android applications. It provides a flexible and intuitive way to display and interact with calendars in your app. With Kalendar, you can easily render calendar views, handle date selection, pagination, and range selection, and customize the layout to match your app's design.
https://www.himanshoe.com
Apache License 2.0
818 stars 66 forks source link

Fixed InCorrect Month Progression Bug #159

Closed AndroidJunior9 closed 11 months ago

AndroidJunior9 commented 1 year ago

Problem Statement

I am working on this issue: KalendarPagingSource Class. I think the problem is with the KalendarPagingSource Class. In this class, we filter the kalendar items.

Code Snippets

Here are the code snippets that show the difference between the original code and the modified code:

Original Code

This is the original code that filters the kalendar items:

val kalendarItems = kalendarRepository.generateDates(page)
                .filter { date ->
                    date.year >= today.year && date.month.value >= today.monthNumber
                }

Modified Code

This is the modified code that filters the kalendar items:

val kalendarItems = kalendarRepository.generateDates(page).filter { date ->
                if (date.year == today.year) {
                    date.month.value >= today.monthNumber
                } else {
                    date.year > today.year
                }

Explanation

The reason why I changed the code is because the original code filters out some valid dates that should be displayed in the kalendar. For example, if today is August 19th, 2023, then the original code will only allow dates whose year is 2023 and later and whose month is August or later. This means that dates like January 1st, 2024, or February 29th, 2024, will not be shown in the calendar.

This code fixes this issue by allowing months which are before the current month if the year is greater than the current one else if the year is the current year, we only allow months which are after the current month and the current month. So now the months from January to July will not be filtered out and the next year will start with January.

Final Result

WhatsApp Image 2023-08-21 at 10 20 53 (1)

WhatsApp Image 2023-08-21 at 10 20 53

I you find any issues with this code please inform me. I will try to fix them. Any improvements, feedbacks, reviews are appreciated 😊.

AndroidJunior9 commented 11 months ago

Hi Himanshu,

I submitted a pull request on the Kalendar project and was wondering about its status. If there are any issues or improvements needed, please let me know.

AndroidJunior9

AndroidJunior9 commented 11 months ago

Thank you