-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
71 additions
and
8 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
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
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
25 changes: 23 additions & 2 deletions
25
app/src/main/java/com/example/infraandroid/id/viewmodel/Prefs.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 |
---|---|---|
@@ -1,14 +1,35 @@ | ||
package com.example.infraandroid.id.viewmodel | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
|
||
class Prefs(context: Context) { | ||
private val prefs=context.getSharedPreferences("prefs_name", Context.MODE_PRIVATE) | ||
private val prefs : SharedPreferences = context.getSharedPreferences("prefs_name", Context.MODE_PRIVATE) | ||
private val editor : SharedPreferences.Editor = prefs.edit() | ||
|
||
fun getString(key: String, defValue: String): String { | ||
return prefs.getString(key, defValue).toString() | ||
} | ||
fun setString(key: String, str: String) { | ||
prefs.edit().putString(key, str).apply() | ||
val editor : SharedPreferences.Editor = prefs.edit() | ||
editor.putString(key, str).apply() | ||
} | ||
fun setUserId(input: String){ | ||
editor.putString("MY_ID", input) | ||
editor.commit() | ||
} | ||
fun setUserPW(input: String){ | ||
editor.putString("MY_PW", input) | ||
editor.commit() | ||
} | ||
fun getUserId():String{ | ||
return prefs.getString("MY_ID", "").toString() | ||
} | ||
fun getUserPW():String{ | ||
return prefs.getString("MY_PW", "").toString() | ||
} | ||
fun clearUser(){ | ||
editor.clear() | ||
editor.commit() | ||
} | ||
} |