wip
This commit is contained in:
@@ -6,12 +6,17 @@ import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import com.mycrib.storage.TokenManager
|
||||
import com.mycrib.storage.TokenStorage
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
enableEdgeToEdge()
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
// Initialize TokenStorage with Android TokenManager
|
||||
TokenStorage.initialize(TokenManager.getInstance(applicationContext))
|
||||
|
||||
setContent {
|
||||
App()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.mycrib.storage
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
|
||||
/**
|
||||
* Android implementation of TokenManager using SharedPreferences.
|
||||
*/
|
||||
actual class TokenManager(private val context: Context) {
|
||||
private val prefs: SharedPreferences = context.getSharedPreferences(
|
||||
PREFS_NAME,
|
||||
Context.MODE_PRIVATE
|
||||
)
|
||||
|
||||
actual fun saveToken(token: String) {
|
||||
prefs.edit().putString(KEY_TOKEN, token).apply()
|
||||
}
|
||||
|
||||
actual fun getToken(): String? {
|
||||
return prefs.getString(KEY_TOKEN, null)
|
||||
}
|
||||
|
||||
actual fun clearToken() {
|
||||
prefs.edit().remove(KEY_TOKEN).apply()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val PREFS_NAME = "mycrib_prefs"
|
||||
private const val KEY_TOKEN = "auth_token"
|
||||
|
||||
@Volatile
|
||||
private var instance: TokenManager? = null
|
||||
|
||||
fun getInstance(context: Context): TokenManager {
|
||||
return instance ?: synchronized(this) {
|
||||
instance ?: TokenManager(context.applicationContext).also { instance = it }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user