kiwix-android icon indicating copy to clipboard operation
kiwix-android copied to clipboard

Using DataStore instead of SharedPreferences

Open 4shutosh opened this issue 4 years ago • 14 comments

Is your feature request related to a problem? Please describe.

SharedPreferences are used for storing key-value pairs in local storage, which is now deprecated.

Describe the solution you'd like

Jetpack DataStore Preferences should be used instead of shared preferences A good article explaining the benefits is here. Its stable version is out, and can be implemented in our app.

Additional context

Files to be modified mainly includes SharedPreferenceUtil for implementing the DataStore

4shutosh avatar Aug 28 '21 08:08 4shutosh

Hey, may I work on this?

xtanion avatar Nov 23 '21 12:11 xtanion

Thank you for your interest @xtanion.

Priority: Bugs > Enhancements

Please try to solve one of the bugs floating around first. (good-first-issue && bug) If you cannot yes, you may go ahead and start working on this issue.

4shutosh avatar Nov 24 '21 07:11 4shutosh

Thanks for the suggestions @4shutosh, I'll look for good-first-issue that I can solve ;).

xtanion avatar Nov 24 '21 10:11 xtanion

I would like to work on this issue for now, can you please assign it to me?

xtanion avatar Dec 11 '21 06:12 xtanion

This issue has been automatically marked as stale because it has not had recent activity. It will be now be reviewed manually. Thank you for your contributions.

stale[bot] avatar Apr 16 '22 06:04 stale[bot]

@gouri-panda @mhutti1 Do you confirm that SharedPreferences is really deprecated? Do you confirm that using Jetpack DataStore is the most appropriate replacement?

kelson42 avatar Jan 11 '23 18:01 kelson42

@kelson42 SharedPreferences hasn't been deprecated yet. But we think it'll be deprecated soon with the alternative of DataStore. DataStore offers many things that SharedPreference lacks. It's a very good idea to replace and use it now.

gouri-panda avatar Jan 11 '23 19:01 gouri-panda

@gouri-panda Thank you for your feedback. I have a bit difficulties to judge how difficult and how much work would be needed. Do you have a few hints/answers?

kelson42 avatar Jan 11 '23 19:01 kelson42

@kelson42 In a nutshell we have SharedPreferenceUtil class which lets store all the default key and value and we use it over all the functions and tests in our project. We'll be adding a new implementation of DataStore and There'll be some code refactoring in both functions and tests as well. I think it's a little big.

gouri-panda avatar Jan 11 '23 19:01 gouri-panda

I can work on this, and I guess it will be a lengthy task, I think it's would be better if we discuss this out before implementing it.

shankarpriyank avatar Feb 07 '23 15:02 shankarpriyank

Please feel free to list down your questions here @shankarpriyank

4shutosh avatar Feb 07 '23 15:02 4shutosh

@4shutosh One major thing I have in mind is that, will there not be a migration problem? Like we have different ways to manage migrations of databases in room, do we something like that in this case? Cause let's assume a user has the app with the previous version(with shared preferences installed) and then he updated the app to the datastore version, will that not cause an inconsistency? Maybe break the app too?

shankarpriyank avatar Feb 07 '23 17:02 shankarpriyank

@gouri-panda @4shutosh @shankarpriyank Considering that:

  • SharePreferences is not deprecated yet
  • This move is not straight I would like we keep this ticket for the future and maybe give it to someone already pretty familiar with the codebase.

kelson42 avatar Feb 09 '23 16:02 kelson42