wip
This commit is contained in:
@@ -8,6 +8,8 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import com.mycrib.storage.TokenManager
|
||||
import com.mycrib.storage.TokenStorage
|
||||
import com.mycrib.storage.TaskCacheManager
|
||||
import com.mycrib.storage.TaskCacheStorage
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -17,6 +19,9 @@ class MainActivity : ComponentActivity() {
|
||||
// Initialize TokenStorage with Android TokenManager
|
||||
TokenStorage.initialize(TokenManager.getInstance(applicationContext))
|
||||
|
||||
// Initialize TaskCacheStorage for offline task caching
|
||||
TaskCacheStorage.initialize(TaskCacheManager.getInstance(applicationContext))
|
||||
|
||||
setContent {
|
||||
App()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.mycrib.storage
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
|
||||
/**
|
||||
* Android implementation of TaskCacheManager using SharedPreferences.
|
||||
*/
|
||||
actual class TaskCacheManager(private val context: Context) {
|
||||
private val prefs: SharedPreferences = context.getSharedPreferences(
|
||||
PREFS_NAME,
|
||||
Context.MODE_PRIVATE
|
||||
)
|
||||
|
||||
actual fun saveTasks(tasksJson: String) {
|
||||
prefs.edit().putString(KEY_TASKS, tasksJson).apply()
|
||||
}
|
||||
|
||||
actual fun getTasks(): String? {
|
||||
return prefs.getString(KEY_TASKS, null)
|
||||
}
|
||||
|
||||
actual fun clearTasks() {
|
||||
prefs.edit().remove(KEY_TASKS).apply()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val PREFS_NAME = "mycrib_cache"
|
||||
private const val KEY_TASKS = "cached_tasks"
|
||||
|
||||
@Volatile
|
||||
private var instance: TaskCacheManager? = null
|
||||
|
||||
fun getInstance(context: Context): TaskCacheManager {
|
||||
return instance ?: synchronized(this) {
|
||||
instance ?: TaskCacheManager(context.applicationContext).also { instance = it }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user