alamkanak / Android-Week-View

Android Week View is an android library to display calendars (week view or day view) within the app. It supports custom styling.
Apache License 2.0
3.42k stars 1.23k forks source link

Fork that addresses crashes on API 28 #521

Open thellmund opened 6 years ago

thellmund commented 6 years ago

Hi guys,

I’ve experienced some problems with the library when using API 28 in our app (deprecated canvas methods). Because the library seems to be no longer maintained, I’ve forked the repository and implemented a fix.

You can find it at https://github.com/thellmund/Android-Week-View. Hope this helps anyone who’s had similar problems 😊

marcoscgdev commented 6 years ago

Thank you :D

fersical commented 6 years ago

Que cambios has hecho para que funcione? Gracias!

fabien-ml commented 6 years ago

Thanks :)

marcoscgdev commented 6 years ago

I have made another fork that solves this problem. This time, it supports API 14+

marcoscgdev/Android-Week-View

This is what I have done:

I have replaced this

canvas.clipRect(0, mHeaderHeight + mHeaderRowPadding * 2, mHeaderColumnWidth, getHeight(), Region.Op.REPLACE);

with this

canvas.save();
canvas.clipRect(0, mHeaderHeight + mHeaderRowPadding * 2, mHeaderColumnWidth, getHeight());
canvas.restore();

So basically I have removed Region.Op.REPLACE and I have added canvas.save(); and canvas.restore();

thellmund commented 6 years ago

@fersical I’ve done exactly what @marcoscgdev has described above. In the future, I want to make more changes, such as improving the scrolling behavior and tweaking the design a little.

wallforfry commented 6 years ago

@thellmund Can you update your readme for your release 2.0 with new interfaces and attributes ?

thellmund commented 6 years ago

@wallforfry I hope to have some time this weekend to work on the library. This will include updating the readme.

thellmund commented 6 years ago

@wallforfry I finally just pushed a new version of the library and an update to the readme. Let me know if there's anything missing or if you have any improvement ideas.

wallforfry commented 6 years ago

@thellmund Thanks for your work ! I've got improvement ideas :

thellmund commented 6 years ago

@wallforfry Great suggestions – I’ll keep them in mind for the next versions 👍

nivritgupta commented 5 years ago

@thellmund this method won't work if I compile my app with API 28

canvas.save(); canvas.clipRect(0, mHeaderHeight + mHeaderRowPadding * 2, mHeaderColumnWidth, getHeight()); canvas.restore();

I am getting the same issue .

thellmund commented 5 years ago

@nivritgupta You’re referencing @marcoscgdev’s fork.

marcoscgdev commented 5 years ago

@thellmund I think @nivritgupta is implementing his own fork. Your fork and also my fork are correctly working.

thellmund commented 5 years ago

@marcoscgdev 🤷‍♂️

nivritgupta commented 5 years ago

@marcoscgdev in the last 2 years I customised this library according to my requirements but now I am using your fork in my app and do some changes according to my requirements but I am getting another issue , single event showing 3 times on same time slot , screen shot 2018-12-05 at 12 33 04 am

marcoscgdev commented 5 years ago

@nivritgupta Everything is working fine for me 🤔

Screenshot

nivritgupta commented 5 years ago

@marcoscgdev I understand your code is working fine , I am trying to find the exact cause of this issue in my code .

tylermarien commented 5 years ago

@nivritgupta You are likely not implementing the MonthChangeListener (or WeekViewLoader) correctly. It requests 3 periods (eg. previous month, current month, next month). If you return the same event each time then it will display 3 times. Make sure you are correctly constraining the events to the arguments passed into whatever method you've implemented to fetch the events.

WasifNadeem90 commented 5 years ago

Hey there, First of all i must appreciate your work, my developer use this library and he's no more with me so i have to do the changes but the changes i need wasnt in the real library but your updates really save my day. And now im having a little problem like @nivritgupta dose and i have read your suggestion to check MonthChangeListener but i dont find the issue. That would be really helpful if you can help me to make this right. The picture and the code of MonthChangeListener is mentioned below to better explain my problem.

override fun onMonthChange(startDate: Calendar?, endDate: Calendar?): ArrayList<WeekViewDisplayable<Event>>? { return events }

screenshot_2018-12-26-20-42-45-2

tylermarien commented 5 years ago

@WasifNadeem90 You need to filter out events that don't exist between the startDate and endDate.

Something like the following should work.

override fun onMonthChange(startDate: Calendar?, endDate: Calendar?): List<WeekViewDisplayable<Event>>? { 
  return events.filter { event ->
    (event.startTime >= startDate && event.startTime <= endDate) 
      || (event.endTime >= startDate && event.endTime <= endDate) 
  }
}

The reason is that the onMonthChange method will get called 3 times (once with the previous month, once with the current month and once with the next month). If you return the same set of events each time, each event will be returned 3 times. This will cause it to show 3 times.

nivritgupta commented 5 years ago

@marcoscgdev hope you are doing well , any ideas how we can implement drag and drop events features in this library ?

marcoscgdev commented 5 years ago

@nivritgupta Probably by adding a touch listener when long-pressing an item that listens for user drag events and changes the item position based on that events.

rahulpateel commented 4 years ago

how to disable horizontal scrolling

fukemy commented 3 years ago

thanks u work as expected