generated from AND-SOPT-ANDROID/and-sopt-android-template
-
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
3 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
app/src/main/java/org/sopt/and/data/repository/SharedPreferencesHelper.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,34 @@ | ||
package org.sopt.and.data.repository | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object AppModule { | ||
@Provides | ||
@Singleton | ||
fun provideSharedPreferencesHelper(@ApplicationContext context: Context): SharedPreferencesHelper { | ||
return SharedPreferencesHelper(context) | ||
} | ||
} | ||
|
||
|
||
class SharedPreferencesHelper(context: Context) { | ||
private val prefs: SharedPreferences = | ||
context.getSharedPreferences("app_prefs", Context.MODE_PRIVATE) | ||
|
||
fun saveToken(token: String) { | ||
prefs.edit().putString("auth_token", token).apply() | ||
} | ||
|
||
fun getToken(): String? { | ||
return prefs.getString("auth_token", null) | ||
} | ||
} |
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