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

Locally store user profile info

Open Priyansh-Kedia opened this issue 4 years ago • 28 comments

In the current app, whenever the profile section is opened, an API call is made. This kind of API calling abuses the use of API. As the profile info is just small texts, they can be stored locally so that every time profile is opened, there is no API call

Describe the solution you'd like Store profile information locally and update it accordingly

Priyansh-Kedia avatar Jun 05 '20 21:06 Priyansh-Kedia

@isabelcosta @m-murad May I work on this

Also as this is related to calls to the backend API, @mtreacy002 your reviews would be helpful

Priyansh-Kedia avatar Jun 05 '20 21:06 Priyansh-Kedia

@isabelcosta @foongminwong If this one's available, I'd like to work on it.

devptyagi avatar Jun 06 '20 21:06 devptyagi

@devptyagi I was waiting for approval on this issue Nevertheless, can you discuss the approach?

Priyansh-Kedia avatar Jun 07 '20 11:06 Priyansh-Kedia

Can you share your thoughts on how you'll store it locally, @Priyansh-Kedia?

mtreacy002 avatar Jun 09 '20 06:06 mtreacy002

Hello @mtreacy002 I was thinking of storing the profile info you preferences in android

Priyansh-Kedia avatar Jun 09 '20 06:06 Priyansh-Kedia

The thing is At this time, whenever we open the profile fragment, API call is made. I think that it is a wrong use of API calling as the information does not change

Priyansh-Kedia avatar Jun 09 '20 06:06 Priyansh-Kedia

That makes sense. Are you thinking of using cache or something like that?

mtreacy002 avatar Jun 09 '20 06:06 mtreacy002

Yes In the local caches

Priyansh-Kedia avatar Jun 09 '20 06:06 Priyansh-Kedia

sounds good to me, but we need maintainers or @anitab-org/coding-team approval first so you can start working on it.

mtreacy002 avatar Jun 09 '20 06:06 mtreacy002

Yeah Thanks for your reviews @mtreacy002

Priyansh-Kedia avatar Jun 09 '20 06:06 Priyansh-Kedia

@Priyansh-Kedia do you want to work on this issue?

aditmehta9 avatar Jun 09 '20 06:06 aditmehta9

Yes

Priyansh-Kedia avatar Jun 09 '20 06:06 Priyansh-Kedia

Assigned.

aditmehta9 avatar Jun 09 '20 06:06 aditmehta9

Thanks @aditmehta9

Priyansh-Kedia avatar Jun 09 '20 06:06 Priyansh-Kedia

is this issue available @isabelcosta ? I am interested to work on it to implement storing the user info in local cache(Android SharedPreferences) .

ahk4815 avatar Jan 28 '21 08:01 ahk4815

is this issue available @isabelcosta ? I am interested to work on it to implement storing the user info in local cache(Android SharedPreferences) .

Sure, this issue can be assigned to you, but Priyansh had asked to re-assign this issue to him on his PR so the decision is up to Isabel or Vaishnavi who should work on this issue?

aditmehta9 avatar Jan 28 '21 08:01 aditmehta9

@aditmehta9 hey @Priyansh-Kedia has contributed here before, but @ahk4815 hasn't so it'll be nice to assign it to @ahk4815 . What say, sounds good?

vj-codes avatar Jan 28 '21 14:01 vj-codes

Sure @vj-codes

Priyansh-Kedia avatar Jan 28 '21 14:01 Priyansh-Kedia

Assigning you @ahk4815 Happy coding!

vj-codes avatar Jan 28 '21 15:01 vj-codes

solving this issue will take some more time. Can it get extended to a couple of days more?

ahk4815 avatar Jan 31 '21 10:01 ahk4815

solving this issue will take some more time. Can it get extended to a couple of days more?

How are you planning to do it @ahk4815

Priyansh-Kedia avatar Jan 31 '21 10:01 Priyansh-Kedia

solving this issue will take some more time. Can it get extended to a couple of days more?

How are you planning to do it @ahk4815

Thanks @Priyansh-Kedia for asking .A PreferenceManager class is already present in the project. I would be adding the functions of updating and fetching user's profile details in the preferenceManager class. Since the profile data is of custom <User> class, it would be required to convert this into json string and upload in the shared preference according to this Custom Object in preference . In the getProfile() function of ProfileViewModel class i will fetch the user details from the shared preference. In case the details are NULL or not set it will get fetched by api call and updated in the preference. In the updateProfile() of the same class, updation in the shared preference for profile details will be done besides the api calls which are being made. I hope i am clear in this explanation?

ahk4815 avatar Jan 31 '21 13:01 ahk4815

Don't you think datastore should be used instead of preference manager, as datastore provides type safety and is main thread safe. Also shared preferences has been deprecated.

What do you think @vj-codes @isabelcosta

Priyansh-Kedia avatar Jan 31 '21 13:01 Priyansh-Kedia

Don't you think datastore should be used instead of preference manager, as datastore provides type safety and is main thread safe. Also shared preferences has been deprecated.

What do you think @vj-codes @isabelcosta

Yeah Shared Preference is depreciated. A Preference Manager class for SharedPreference was already present in the current project for authorization related work. So i thought of implementing the same for this issue. But datastore is currently preferred over sharedPreference for the reason stated by @Priyansh-Kedia. So i can work with the same for this issue.

ahk4815 avatar Jan 31 '21 14:01 ahk4815

Don't you think datastore should be used instead of preference manager, as datastore provides type safety and is main thread safe. Also shared preferences has been deprecated.

What do you think @vj-codes @isabelcosta

Yeah Shared Preference is depreciated. A Preference Manager class for SharedPreference was already present in the current project for authorization related work. So i thought of implementing the same for this issue. But datastore is currently preferred over sharedPreference for the reason stated by @Priyansh-Kedia. So i can work with the same for this issue.

Sounds good What do you think @vj-codes

Priyansh-Kedia avatar Jan 31 '21 14:01 Priyansh-Kedia

Don't you think datastore should be used instead of preference manager, as datastore provides type safety and is main thread safe. Also shared preferences has been deprecated.

What do you think @vj-codes @isabelcosta

Datastore is still in alpha ,I think we should wait for a stable release before using it. Also I don't see the deprecation warning for shared preferences in the docs can you share the link where you saw the shared preference deprecated warning? Are you talking about the PreferenceManager class ,because that has been deprecated.

epicadk avatar Jan 31 '21 15:01 epicadk

Don't you think datastore should be used instead of preference manager, as datastore provides type safety and is main thread safe. Also shared preferences has been deprecated. What do you think @vj-codes @isabelcosta

Datastore is still in alpha ,I think we should wait for a stable release before using it. Also I don't see the deprecation warning for shared preferences in the docs can you share the link where you saw the shared preference deprecated warning? Are you talking about the PreferenceManager class ,because that has been deprecated.

For updating the user's profile, two tasks needs to be performed: Firstly, an API call which is updating the details Secondly, the user's data in the Shared Preference needs to be updated as well.

The API call feature is already implemented in the current project. Incase the device is offline(not connected to internet) the API call will fail but the shared preference feature will store the info in the local cache. So now a discrepancy of data will be present in the cache ( having updated info) and the database(having previous version of data). This error will happen only if the user tries to edit the profile while device is offline. So far i have implemented the fetching and updating of user profile from the shared preference in the app. One simple solution i have thought is that is the device is offline, the updating operation will not take place in Shared Preference. Is it okay @vj-codes @isabelcosta

ahk4815 avatar Feb 01 '21 10:02 ahk4815

I am working on this issue

kartikeysaran avatar Feb 23 '21 11:02 kartikeysaran