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

After multiple load Material-Calendar-View shows the wrong day icon. #80

Closed
assembleMHN opened this issue May 9, 2018 · 8 comments
Closed

Comments

@assembleMHN
Copy link

assembleMHN commented May 9, 2018

Hi.

I have debugged this issue for ages now, and can conclude that after multiple loads the calendar might show the wrong icon. I have 59 event days i load in to the calendar, they can have one of two icons.

In my activity i have a toggle functionality between two calendars "week" and "month", when i switch between these multiple times material calendar view will begin showing the wrong icons and at some point stop showing icons at all. I can recreate this very easy just by jumping from the week to the month calendar multiple times.

Everytime i change from month to week the fragment that holds the material calendar view gets destroyed and therefor its a complete fresh version that is failing. The eventdays im passing is hardcoded and cannot change, but i even debugged the calendar view adapter with a breakpoint in the seteventdays function and have concluded that the eventdays are correct, even dough the calendar shows the wrong icons and none at all. Something goes completely haywire when destroying and loading the calendar again.

Currently im in a state where the calendar view refuses to show any icons at all, even dough i pass 59 hardcoded eventdays to it.

This image shows the correct layout build from the eventdays:

screen shot 2018-05-09 at 09 58 11

This image shows the error after i changed between "dag (day)" and "måned (month)" 4 times, as you can see the one row of icons changed, the eventdays are exactly the same (hardcoded) this is also verified in the "seteventdays" in CalendarView where i can see that the eventdays do indeed have the correct icon, but the calendar shows them wrong anyways.

screen shot 2018-05-09 at 09 59 30

Please help.

Best Regards
Morten

@assembleMHN
Copy link
Author

I have debugged some more, and can see that in this function:

private void loadIcon(ImageView dayIcon, Calendar day) {
    if (mCalendarProperties.getEventDays() == null || mCalendarProperties.getCalendarType() != CalendarView.CLASSIC) {
        dayIcon.setVisibility(View.GONE);
        return;
    }

    Stream.of(mCalendarProperties.getEventDays()).filter(eventDate ->
            eventDate.getCalendar().equals(day)).findFirst().executeIfPresent(eventDay -> {

        ImageUtils.loadResource(dayIcon, eventDay.getImageResource());

        // If a day doesn't belong to current month then image is transparent
        if (!isCurrentMonthDay(day) || !isActiveDay(day)) {
            dayIcon.setAlpha(0.12f);
        }

    });
}

The icon ID (eventDay.getImageResource()) is correct, but the calendar is loading the wrong one and not the one returned by "eventDay.getImageResource()"

@assembleMHN
Copy link
Author

We have narrowed it down to a issue with Glide, probably its diskcache, clearing the cache greatly reduce how often the error happens. the reason why it still happens is probably that the clean runs in a backgroundtask and had not completed.

I would strongly suggest that you update glide to its current version 4.7.0

@assembleMHN
Copy link
Author

Seems that my problem has been solved in Glide 4.4.0:

"Fixed a couple of cases where calling load(Bitmap) or load(Drawable) could cause Glide to re-use or recycle the given Bitmap or Drawable (cff4f2c)."

https://github.com/bumptech/glide/releases

@assembleMHN
Copy link
Author

assembleMHN commented May 11, 2018

I forked the project, update glide to current version, implemented it in my project and the error is gone. I can therefore confirm that the error is in Glide and that updating the project to newest version of glide will solve this problem. Please close when you have confirmed that you will update to the latest version of glide, there where no breaking changes only thing needed is to push compilesdktarget to 27.

@karthikslegend
Copy link

Hi, I need to add a single dot below a date, Please tell me how to do that or an example will also be fine? I have no idea.

@lsaulcastro
Copy link

@karthikslegend I am trying to add some events with an icon and it does not work. Nothing happens underneath I leave the code!

Urgent help!

image
image

@assembleMHN
Copy link
Author

The developer seems to not support this library anymore, i never got a answer to my question, i fixed it my self and are now running on a private branch to make sure that a update to this library wont break my own. Good luck fixing :)

@kormateusz
Copy link
Member

We will make more tests and probably remove Glide in one of next release if calendar will be working without any issues. Thank you for your effort.

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

4 participants