AkshayChordiya / News

A sample News 🗞 app built using Modern Android Development [Architecture Components, Coroutines, Retrofit, Room, Kotlin, Dagger]
MIT License
848 stars 166 forks source link

How to get updated news data. #10

Closed debajyotibasak closed 6 years ago

debajyotibasak commented 6 years ago

I have forked your arch-news repo and ran the code.

I understood how everything works including the Network bound resource.

I am debugging using the android debugger.... (Let me know if I am wrong)

First it checks if it can load from db. Then since the data is not present in the db it goes to the should fetch method where it returns empty. Then since no data is present it creates a network call. Then it saves the call result in saveCallResult. *Then it again loads from db and shows the results.

Then everytime it loads the data from the db. Now if the news articles are updated. News results are not observed and hence not shown. Its only loaded from the database.

How can we periodically observe for new data and then update it in the database.

AkshayChordiya commented 6 years ago

You are pretty much right. Just that in 2nd step, the flow directly goes to shouldFetch method. It contains the logic if the fresh data is to be fetched from server. Here you could see the database is empty or not, or probably keep a refresh limiter. In this sample I have set it to true, hence the it always tries to fetch fresh data from server and updates the UI with new news on fetching.

Let me know if you were looking for something else

debajyotibasak commented 6 years ago

OK understood that the refreshing data logic should be present in the shouldFetch method. Thank you @AkshayChordiya