rob729 / Quiet_Hours

No more trouble to make silent mode ON/OFF manually every time.
3 stars 9 forks source link

Replace the shared preferences with Preferences DataStore #57

Open rob729 opened 3 years ago

rob729 commented 3 years ago

Describe the feature you'd like Currently, the app uses shared preferences for storing data used in general computation purposes. Replace it with Preferences DataStore as it is one of the recommended ways now. It has to implement it in an optimal way like how the shared preferences has been implemented in the app.

Would you like to work on the issue?

coder2699 commented 3 years ago

@rob729 i want to claim this issue

rob729 commented 3 years ago

Go Ahead @coder2699

coder2699 commented 3 years ago

@rob729 There are many problems that are coming in implementing the task. One of the major problem is coming while using viewModel to store ACTIVE_PROFILE_NAME, etc. inside StartAlarm and EndAlarm.

Since we are saving a lot of data from StartAlarm and EndAlarm (like BEGIN_STATUS, ACTIVE_PROFILE_ID, END_TIME......etc), many issues are arising.

The following link describes the problem very similar to what I m facing: https://stackoverflow.com/questions/50892220/how-to-get-a-viewmodel-from-a-worker-class

And the solutions mentioned either don't work or require too many changes in the application's code.

rob729 commented 3 years ago

Why are you using view model to store ACTIVE_PROFILE_NAME, etc. inside StartAlarm and EndAlarm?

coder2699 commented 3 years ago

@rob729 Because we need "viewModelScope" to read/write values...this is what I understood after going through the articles. Please correct me if I have misunderstood something.

https://developer.android.com/codelabs/android-preferences-datastore#7 https://blog.mindorks.com/jetpack-datastore-preferences

rob729 commented 3 years ago

What is actually viewModelScope? This is the question that you should be searching for. The ViewModel is not a requirement for Preferences DataStore. The basic concept behind the Preferences DataStore is that data is read/write on a background thread. In the above example, the same is achieved using coroutine. There are more ways to use coroutines. You should explore more about Preferences DataStore & coroutines to get a proper idea.

coder2699 commented 3 years ago

@rob729 I am unable to implement Preference Data Store, so it will be better if you unassign me.

rob729 commented 3 years ago

Okay