-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from jama5262/issue-56
Add Shared preferences in the core module (Issue 56)
- Loading branch information
Showing
4 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
10 changes: 10 additions & 0 deletions
10
core/src/main/java/com/android254/droidconKE2020/core/Preferences.kt
This file contains 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,10 @@ | ||
package com.android254.droidconKE2020.core | ||
|
||
import android.content.SharedPreferences | ||
|
||
interface Preferences { | ||
val sharedPref: SharedPreferences | ||
|
||
// fun getUserName(defaultValue: String): String? | ||
// fun setUserName(username: String) | ||
} |
28 changes: 28 additions & 0 deletions
28
core/src/main/java/com/android254/droidconKE2020/core/PreferencesImpl.kt
This file contains 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,28 @@ | ||
package com.android254.droidconKE2020.core | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import com.android254.droidconKE2020.core.di.Constants.SHARED_PREF_FILE_NAME | ||
|
||
class PreferencesImpl(context: Context): Preferences { | ||
|
||
override val sharedPref: SharedPreferences = context | ||
.getSharedPreferences(SHARED_PREF_FILE_NAME, Context.MODE_PRIVATE) | ||
|
||
private fun editSharedPref(action: (s: SharedPreferences.Editor) -> Unit) { | ||
with (sharedPref.edit()) { | ||
action(this) | ||
apply() | ||
} | ||
} | ||
|
||
// override fun getUserName(defaultValue: String): String? { | ||
// return sharedPref.getString("userName", defaultValue) | ||
// } | ||
// | ||
// override fun setUserName(username: String) { | ||
// editSharedPref { | ||
// it.putString("userName", username) | ||
// } | ||
// } | ||
} |
5 changes: 5 additions & 0 deletions
5
core/src/main/java/com/android254/droidconKE2020/core/di/Constants.kt
This file contains 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,5 @@ | ||
package com.android254.droidconKE2020.core.di | ||
|
||
object Constants { | ||
const val SHARED_PREF_FILE_NAME = "com.android254.droidconKE2020" | ||
} |