-
Notifications
You must be signed in to change notification settings - Fork 13
Feat/profile sign out #202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mayorjay
wants to merge
7
commits into
development
Choose a base branch
from
feat/profile_sign_out
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e64388f
.
mayorjay e966ca0
Merge remote-tracking branch 'origin/development' into development
mayorjay be753e1
feat: Complete profile sign out
mayorjay bb75808
Resolve PR Commit
mayorjay 8993e7b
Resolve PR Commit
mayorjay 7b2d75d
feat: load profile screen after login
carl05 b86d5a6
fix: ignore codestyle
carl05 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
235 changes: 235 additions & 0 deletions
235
core/src/main/java/com/fightpandemics/core/utils/SharedPrefUtil.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,235 @@ | ||
| package com.fightpandemics.core.utils | ||
|
|
||
| import android.content.Context | ||
mayorjay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import android.content.SharedPreferences | ||
|
|
||
| import android.text.TextUtils | ||
| import androidx.preference.PreferenceManager | ||
|
|
||
|
|
||
mayorjay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * A pack of helpful getter and setter methods for reading/writing to {@link SharedPreferences}. | ||
| */ | ||
|
|
||
| /** | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * Helper method to retrieve a String value from [SharedPreferences]. | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @param context a [Context] object. | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @param key | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @return The value from shared preferences, or null if the value could not be read. | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fun getStringPreference(context: Context?, key: String?): String? { | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| var value: String? = null | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| val preferences = PreferenceManager.getDefaultSharedPreferences(context) | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (preferences != null) { | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| value = preferences.getString(key, null) | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return value | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
mayorjay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * Helper method to write a String value to [SharedPreferences]. | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @param context a [Context] object. | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @param key | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @param value | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @return true if the new value was successfully written to persistent storage. | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fun setStringPreference( | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| context: Context?, | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| key: String?, | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| value: String? | ||
mayorjay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ): Boolean { | ||
| val preferences = PreferenceManager.getDefaultSharedPreferences(context) | ||
| if (preferences != null && !TextUtils.isEmpty(key)) { | ||
| val editor = preferences.edit() | ||
| editor.putString(key, value) | ||
| return editor.commit() | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| /** | ||
| * Helper method to retrieve a float value from [SharedPreferences]. | ||
| * | ||
| * @param context a [Context] object. | ||
| * @param key | ||
| * @param defaultValue A default to return if the value could not be read. | ||
| * @return The value from shared preferences, or the provided default. | ||
| */ | ||
| fun getFloatPreference( | ||
| context: Context?, | ||
| key: String?, | ||
| defaultValue: Float | ||
| ): Float { | ||
| var value = defaultValue | ||
| val preferences = PreferenceManager.getDefaultSharedPreferences(context) | ||
| if (preferences != null) { | ||
| value = preferences.getFloat(key, defaultValue) | ||
| } | ||
| return value | ||
| } | ||
|
|
||
| /** | ||
| * Helper method to write a float value to [SharedPreferences]. | ||
| * | ||
| * @param context a [Context] object. | ||
| * @param key | ||
| * @param value | ||
| * @return true if the new value was successfully written to persistent storage. | ||
| */ | ||
| fun setFloatPreference( | ||
| context: Context?, | ||
| key: String?, | ||
| value: Float | ||
| ): Boolean { | ||
| val preferences = PreferenceManager.getDefaultSharedPreferences(context) | ||
| if (preferences != null) { | ||
| val editor = preferences.edit() | ||
| editor.putFloat(key, value) | ||
| return editor.commit() | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| /** | ||
| * Helper method to retrieve a long value from [SharedPreferences]. | ||
| * | ||
| * @param context a [Context] object. | ||
| * @param key | ||
| * @param defaultValue A default to return if the value could not be read. | ||
| * @return The value from shared preferences, or the provided default. | ||
| */ | ||
| fun getLongPreference( | ||
| context: Context?, | ||
| key: String?, | ||
| defaultValue: Long | ||
| ): Long { | ||
| var value = defaultValue | ||
| val preferences = PreferenceManager.getDefaultSharedPreferences(context) | ||
| if (preferences != null) { | ||
| value = preferences.getLong(key, defaultValue) | ||
| } | ||
| return value | ||
| } | ||
|
|
||
| /** | ||
| * Helper method to write a long value to [SharedPreferences]. | ||
| * | ||
| * @param context a [Context] object. | ||
| * @param key | ||
| * @param value | ||
| * @return true if the new value was successfully written to persistent storage. | ||
| */ | ||
| fun setLongPreference( | ||
| context: Context?, | ||
| key: String?, | ||
| value: Long | ||
| ): Boolean { | ||
| val preferences = PreferenceManager.getDefaultSharedPreferences(context) | ||
| if (preferences != null) { | ||
| val editor = preferences.edit() | ||
| editor.putLong(key, value) | ||
| return editor.commit() | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| /** | ||
| * Helper method to retrieve an integer value from [SharedPreferences]. | ||
| * | ||
| * @param context a [Context] object. | ||
| * @param key | ||
| * @param defaultValue A default to return if the value could not be read. | ||
| * @return The value from shared preferences, or the provided default. | ||
| */ | ||
| fun getIntegerPreference(context: Context?, key: String?, defaultValue: Int): Int { | ||
| var value = defaultValue | ||
| val preferences = PreferenceManager.getDefaultSharedPreferences(context) | ||
| if (preferences != null) { | ||
| value = preferences.getInt(key, defaultValue) | ||
| } | ||
| return value | ||
| } | ||
|
|
||
| /** | ||
| * Helper method to write an integer value to [SharedPreferences]. | ||
| * | ||
| * @param context a [Context] object. | ||
| * @param key | ||
| * @param value | ||
| * @return true if the new value was successfully written to persistent storage. | ||
| */ | ||
| fun setIntegerPreference( | ||
| context: Context?, | ||
| key: String?, | ||
| value: Int | ||
| ): Boolean { | ||
| val preferences = PreferenceManager.getDefaultSharedPreferences(context) | ||
| if (preferences != null) { | ||
| val editor = preferences.edit() | ||
| editor.putInt(key, value) | ||
| return editor.commit() | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| /** | ||
| * Helper method to retrieve a boolean value from [SharedPreferences]. | ||
| * | ||
| * @param context a [Context] object. | ||
| * @param key | ||
| * @param defaultValue A default to return if the value could not be read. | ||
| * @return The value from shared preferences, or the provided default. | ||
| */ | ||
| fun getBooleanPreference( | ||
| context: Context?, | ||
| key: String?, | ||
| defaultValue: Boolean | ||
| ): Boolean { | ||
| var value = defaultValue | ||
| val preferences = PreferenceManager.getDefaultSharedPreferences(context) | ||
| if (preferences != null) { | ||
| value = preferences.getBoolean(key, defaultValue) | ||
| } | ||
| return value | ||
| } | ||
|
|
||
| /** | ||
| * Helper method to write a boolean value to [SharedPreferences]. | ||
| * | ||
| * @param context a [Context] object. | ||
| * @param key | ||
| * @param value | ||
| * @return true if the new value was successfully written to persistent storage. | ||
| */ | ||
| fun setBooleanPreference( | ||
| context: Context?, | ||
| key: String?, | ||
| value: Boolean | ||
| ): Boolean { | ||
| val preferences = PreferenceManager.getDefaultSharedPreferences(context) | ||
| if (preferences != null) { | ||
| val editor = preferences.edit() | ||
| editor.putBoolean(key, value) | ||
| return editor.commit() | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| /** | ||
| * Helper method to delete a particular key from [SharedPreferences]. | ||
| * | ||
| * @param context a [Context] object. | ||
| * @param key | ||
| * @return true if the new value was successfully written to persistent storage. | ||
| */ | ||
| fun removePreference(context: Context?, key: String?): Boolean { | ||
| val preferences = PreferenceManager.getDefaultSharedPreferences(context) | ||
| if (preferences != null) { | ||
| val editor = preferences.edit() | ||
| editor.remove(key) | ||
| return editor.commit() | ||
| } | ||
| return false | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.