Mentorship-android: Locally store user profile info

Created on 5 Jun 2020  路  27Comments  路  Source: anitab-org/mentorship-android

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

Quality Assurance

All 27 comments

@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

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

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

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

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

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

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

Yes
In the local caches

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

Yeah
Thanks for your reviews @mtreacy002

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

Yes

Assigned.

Thanks @aditmehta9

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

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 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?

Sure @vj-codes

Assigning you @ahk4815
Happy coding!

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

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

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 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?

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

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.

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

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.

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

Was this page helpful?
0 / 5 - 0 ratings