-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPubkyStore.kt
More file actions
39 lines (32 loc) · 1.02 KB
/
PubkyStore.kt
File metadata and controls
39 lines (32 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package to.bitkit.data
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.dataStore
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.Flow
import kotlinx.serialization.Serializable
import to.bitkit.data.serializers.PubkyStoreSerializer
import javax.inject.Inject
import javax.inject.Singleton
private val Context.pubkyDataStore: DataStore<PubkyStoreData> by dataStore(
fileName = "pubky.json",
serializer = PubkyStoreSerializer,
)
@Singleton
class PubkyStore @Inject constructor(
@ApplicationContext private val context: Context,
) {
private val store = context.pubkyDataStore
val data: Flow<PubkyStoreData> = store.data
suspend fun update(transform: (PubkyStoreData) -> PubkyStoreData) {
store.updateData(transform)
}
suspend fun reset() {
store.updateData { PubkyStoreData() }
}
}
@Serializable
data class PubkyStoreData(
val cachedName: String? = null,
val cachedImageUri: String? = null,
)