Grey out recyclerview items which the user has clicked


Grey out recyclerview items which the user has clicked



Working on an app where news get displayed in recyclerview. I want to add a functionality where when the user clicks on one of the recyclerview items (which opens the news in a new activity) the item gets greyed out (or something that indicates that the user has opened said news). My idea was to get the news ID the user clicked on and add it to sharedpreferences file. With that I could create a simple check and grey out news where the ID equals to the one in the SharedPreferences file. I feel like that isn't the best way to do it but I can't think of any other way. Any feedback is much appreciated! :)


clicks


recyclerview items


greyed out


SharedPreferences



Recyclerview


<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/mainTextBGColor"
android:scrollbars="vertical"/>





this depends on where you get the news content from
– Navneet Krishna
Jun 29 at 7:54





I get the news content from a database which I have made. News get added from a website into the database and then the app fetches the news. I also had the idea of using another database to store user IDs and then adding a specific user ID to the news which he has read but I don't personally like the idea as much cause that would mean the functionality would not work offline and every time a user opens a new news the app has to add something to a database.
– CrimzonWeb
Jun 29 at 8:31




1 Answer
1



since you can access the backend, consider making an endpoint which you can call when a particular news item gets clicked(pass the news id) and save the news item with the given id as viewed. Now when you fetch the news list, pass the viewed field also in the api. Now in the android end while you display it in recyclerview, check against this viewed field to consider if the item is to be grayed out or not


viewed


viewed


viewed



or you may use other persistent storage methods like realm , sqlite etc


realm


sqlite





Can't exactly understand what you mean, mind giving me an example?
– CrimzonWeb
Jun 29 at 8:44





what is the url that you have created to fetch the news items?
– Navneet Krishna
Jun 29 at 8:47





Currently its localhost. I feel like I explained it a little bad. I need to keep each user seperate. If user A1 has read news 1 and 3 then only those news should be greyed out. I don't want user B1 to see news 1 and 3 greyed on the app. The url gets 10 news at once and turns them into json which I have made a function for in the app to fetch.
– CrimzonWeb
Jun 29 at 8:58






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Export result set on Dbeaver to CSV

Opening a url is failing in Swift