Haptic-Apps / Slide

Slide is an open-source, ad-free Reddit browser for Android.
https://reddit.com/r/slideforreddit
GNU General Public License v3.0
1.78k stars 344 forks source link

Retain Comment position when user navigates away to another app #1981

Closed piyush-rvc closed 8 years ago

piyush-rvc commented 8 years ago

Currently, the comments are reloaded if Slide is killed in background. Sync for reddit restores comments and the position of comment, even after the app is killed.

I am willing to implement this feature, but I will need pointers as to what is to be done.

ccrama commented 8 years ago

This is not possible as you cannot get the current position of a RecyclerView at any moment in time. The only possibility is to save the current rv.getLayoutManager().findFirstVisibleView() method on onPause(), and if the dataset has to be reloaded go back to that position after. I've personally never run into Slide comments getting killed, this shouldn't really occur ever. How do you reproduce that?

piyush-rvc commented 8 years ago

and if the dataset has to be reloaded go back to that position after.

this would only work in happy scenario. If user had clicked on "load more comments" before he navigates to another app, then this would not work.

How do you reproduce that?

Easy for me. I have entry level samsung phone, with all the bloatware. So RAM is pretty low. As soon as I switch to another app, the background app gets killed. In your case, you can open some RAM intensive program to kill the background app.

The only possibility is to save the current rv.getLayoutManager().findFirstVisibleView() method on onPause()

Have you ever tried Sync For reddit? It doesn't reload the data, It simply repopulates the saved data, an "load more comments" and other links/actions work. I don't know how they are doing it.

ccrama commented 8 years ago

Sync stores the comments for every loaded post, which Slide does not. We operate differently and therefore the apps behave differently, one way is not better than the other. This is why it works there and not in Slide, I don't think rewriting how Slide is written (aiming for speed and low ram/storage use) is worth this issue (which would result in saving every post, using a lot more RAM (compare Slide and Sync ram usage), and a lot more storage space used).

piyush-rvc commented 8 years ago

one way is not better than the other

I didn't mean that. You said "the only possibility", I was merely responding to that :)

which would result in saving every post

The result that I seek may be side effect of Sync saving every post, but that doesn't mean we have to save every post. We can only save the current post, and when the app restart, remove all the saved posts. We also discard the saved post associated with activities that finish by back button.

It is okay, if you don't want to implement it. I can fork and implement it for people like me who have entry level phones. I love the customization of slide and the ability to flip between subs. It is very traumatizing to come back from another app and have the comments reload. :(

How to serialize the comment data? Is it even possible using JRAW? I don't see any serialize option for CommentNode.

ccrama commented 8 years ago

How will you detect whether the dataset is reloading? I feel like this may lead to false positives or other unforseen issues. But an answer to your question, Slide already has this ability to do offline syncing, and that code can be found here. If you would like to take a stab at it, feel free to! Let me know if you have any other questions as well

ccrama commented 8 years ago

Seems to be an Android bug, put a workaround to tell Android not to remove the app savedInstanceState. Will hopefully fix your issue!

ccrama commented 8 years ago

Can you confirm whether this fixed the issue or not?