Open-API-Android-App icon indicating copy to clipboard operation
Open-API-Android-App copied to clipboard

RecyclerView Not Updating Edits and Deletes till Swiperefresh

Open Morons opened this issue 4 years ago • 6 comments

Can you please test Open-Api where you delete a blog, It looks like SHOULD_REFRESH is not refreshing the blogList!, I think you have missed BlogEvent.Refresh, I may be wrong UpdateBlog Reflect Nicely on ViewBlog But does not filter through to ListBlog

Morons avatar Jul 23 '21 20:07 Morons

remove this bloc from BlogViewModel : //// init { onTriggerEvent(BlogEvents.GetOrderAndFilter) } //// and add this to the onViewCreated() in BlogFragment : //// onTriggerEvent(BlogEvents.GetOrderAndFilter)

HaythemMejerbi avatar Jul 25 '21 23:07 HaythemMejerbi

You mean in BlogFragment viewModel.onTriggerEvent(BlogEvents.GetOrderAndFilter)

The problem with this it is forced not by trigger!

The problem having this is it generate extra Network traffic - Even if Change was NOT made! AND Loding keeps Spinnig!!

I'd think Mitch will have a different solution, but it works! Thanx

Morons avatar Jul 26 '21 07:07 Morons

@Zlagi You put me on the correct Track However

Add in BlogFragment onViewCreated

// If an update occurred from UpdateBlogFragment, refresh the Blog findNavController().currentBackStackEntry?.savedStateHandle?.getLiveData<Boolean>(SHOULD_REFRESH) ?.observe(viewLifecycleOwner) { shouldRefresh -> shouldRefresh?.run { viewModel.onTriggerEvent(BlogEvents.GetOrderAndFilter) findNavController().currentBackStackEntry?.savedStateHandle?.set(SHOULD_REFRESH, null) } }

Remove from ViewBlogFragment the line that re-set the flag SHOULD_REFRESH so that it is still there for the BlogFragment

findNavController().currentBackStackEntry?.savedStateHandle?.set(SHOULD_REFRESH, null)

The BlogFragment will then Re-Set the flag! if needed and would cause NO extra traffic plus the isLoading is working correct!

Works as Intended!

Morons avatar Jul 26 '21 07:07 Morons

It's not as simple as you suggested. If you refresh in BlogFragment the list position is lost. We would need a use-case that only updates that specific blogpost in the list. Feel free to write it :)

mitchtabian avatar Jul 27 '21 16:07 mitchtabian

Ok I guess you will sort that, I have mostly tested on the Top blog 👍

Morons avatar Jul 28 '21 10:07 Morons

I had a thought Maybe if you refresh the changed data to the Server and re-cache it before returning to the Recycler view you will get the changed record in there and keep your location, Replacing the need for SHOULD_REFRESH 100% all places! @mitchtabian As us suggested!

Morons avatar Sep 09 '21 08:09 Morons