diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ef4d517..e66ca23 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -46,6 +46,7 @@ android { dependencies { implementation (project(BuildModules.Libraries.Data)) + implementation (project(BuildModules.Libraries.Core)) implementation (project(BuildModules.Libraries.Network)) implementation (project(BuildModules.Libraries.Repository)) diff --git a/core/src/main/java/com/android254/droidconKE2020/core/Preferences.kt b/core/src/main/java/com/android254/droidconKE2020/core/Preferences.kt new file mode 100644 index 0000000..275fa52 --- /dev/null +++ b/core/src/main/java/com/android254/droidconKE2020/core/Preferences.kt @@ -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) +} \ No newline at end of file diff --git a/core/src/main/java/com/android254/droidconKE2020/core/PreferencesImpl.kt b/core/src/main/java/com/android254/droidconKE2020/core/PreferencesImpl.kt new file mode 100644 index 0000000..c067849 --- /dev/null +++ b/core/src/main/java/com/android254/droidconKE2020/core/PreferencesImpl.kt @@ -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) +// } +// } +} \ No newline at end of file diff --git a/core/src/main/java/com/android254/droidconKE2020/core/di/Constants.kt b/core/src/main/java/com/android254/droidconKE2020/core/di/Constants.kt new file mode 100644 index 0000000..9774bdc --- /dev/null +++ b/core/src/main/java/com/android254/droidconKE2020/core/di/Constants.kt @@ -0,0 +1,5 @@ +package com.android254.droidconKE2020.core.di + +object Constants { + const val SHARED_PREF_FILE_NAME = "com.android254.droidconKE2020" +} \ No newline at end of file