enpassio / Databinding

Various examples on databinding which can help not only understand how to get started with it but it also shows how this can be used in complex and real use cases
Apache License 2.0
26 stars 14 forks source link

Dev databinding newsapi - java #38

Closed OyaCanli closed 5 years ago

OyaCanli commented 5 years ago

I refactored connectivity check again: connectivity check is done in viewmodel as we talked before. But considering the situation that user might quit the app with back button and return hours later, I made some small changes. So now: If user quits the app with back button and returns later: -He can still see the old data (if system didn't kill the app of course) -IF there is no internet, he can still see the data but he also sees a snack warning. -If turns on the internet and click retry, new data is fetched and shown. -And UIState doesn't turn to NETWORK_ERROR state if there is data. It shows a snack, but it shows also the list, if there is some old data.

I also moved the openWebSite method to the fragment. I had put it in viewmodel, with the aim to demonstrate method references. But as far as I understand, it is not good practice to put something with a reference to a view inside viewmodel. So I moved it back to the fragment.

OyaCanli commented 5 years ago

I added two more commits: -I replaced ObservableField with LiveData, since according to this article published today: “Android Data Binding Library — From Observable Fields to LiveData in two steps” by Jose Alcérreca https://link.medium.com/C6b1SZ6WlV it is now what Google advises. -I also reorganized packages.