This commit is contained in:
Trey t
2025-11-04 10:51:20 -06:00
parent 78c62cfc52
commit de1c7931e9
21 changed files with 1645 additions and 87 deletions

View File

@@ -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()
}

View File

@@ -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 }
}
}
}
}