generated from GO-SOPT-ANDROID/android-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Refactor/#9] SharedPreference 전역에서 공유
viewModel에서 사용할 수 있도록 SharedPrefernces를 Application 클래스로 옮김
- Loading branch information
Showing
4 changed files
with
65 additions
and
85 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
72 changes: 0 additions & 72 deletions
72
app/src/main/java/org/android/go/sopt/present/loginPage/MySharedPrefences.kt
This file was deleted.
Oops, something went wrong.
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
56 changes: 56 additions & 0 deletions
56
app/src/main/java/org/android/go/sopt/util/MySharedPreferences.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,56 @@ | ||
package org.android.go.sopt.util | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
|
||
class MySharedPreferences(context: Context) { | ||
private val MY_ACCOUNT: String = "account" | ||
private val prefs: SharedPreferences = | ||
context.getSharedPreferences(MY_ACCOUNT, Context.MODE_PRIVATE) | ||
|
||
fun setUserId(input: String) { | ||
val editor: SharedPreferences.Editor = prefs.edit() | ||
editor.putString("MY_ID", input) | ||
editor.commit() | ||
} | ||
|
||
fun getUserId(): String { | ||
return prefs.getString("MY_ID", "").toString() | ||
} | ||
|
||
fun setUserPass(input: String) { | ||
val editor: SharedPreferences.Editor = prefs.edit() | ||
editor.putString("MY_PASS", input) | ||
editor.commit() | ||
} | ||
|
||
fun getUserPass(): String { | ||
return prefs.getString("MY_PASS", "").toString() | ||
} | ||
|
||
fun setUserName(input: String) { | ||
val editor: SharedPreferences.Editor = prefs.edit() | ||
editor.putString("MY_NAME", input) | ||
editor.commit() | ||
} | ||
|
||
fun getUserName(): String { | ||
return prefs.getString("MY_NAME", "").toString() | ||
} | ||
|
||
fun setUserSpec(input: String) { | ||
val editor: SharedPreferences.Editor = prefs.edit() | ||
editor.putString("MY_SPEC", input) | ||
editor.commit() | ||
} | ||
|
||
fun getUserSpec(): String { | ||
return prefs.getString("MY_SPEC", "").toString() | ||
} | ||
|
||
fun clearUser() { | ||
val editor: SharedPreferences.Editor = prefs.edit() | ||
editor.clear() | ||
editor.commit() | ||
} | ||
} |