Skip to content

Commit 94abebd

Browse files
authored
Merge pull request #452 from synonymdev/feat/backup-categories
feat: all backup categories
2 parents 9d6cbd0 + 3fdd2f3 commit 94abebd

27 files changed

+647
-264
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
.externalNativeBuild
99
.cxx
1010
local.properties
11+
# AI
12+
.ai
1113
.cursor
1214
*.local.*
1315
CLAUDE.md
14-
1516
# Secrets
1617
google-services.json
1718
.env

app/src/main/java/to/bitkit/data/CacheStore.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class CacheStore @Inject constructor(
3131
private val store = context.appCacheDataStore
3232

3333
val data: Flow<AppCacheData> = store.data
34-
3534
val backupStatuses: Flow<Map<BackupCategory, BackupItemStatus>> = data.map { it.backupStatuses }
3635

3736
suspend fun update(transform: (AppCacheData) -> AppCacheData) {

app/src/main/java/to/bitkit/data/SettingsStore.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import javax.inject.Singleton
2020

2121
private val Context.settingsDataStore: DataStore<SettingsData> by dataStore(
2222
fileName = "settings.json",
23-
serializer = SettingsSerializer
23+
serializer = SettingsSerializer,
2424
)
2525

2626
@Singleton

app/src/main/java/to/bitkit/data/WidgetsStore.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import javax.inject.Singleton
2727

2828
private val Context.widgetsDataStore: DataStore<WidgetsData> by dataStore(
2929
fileName = "widgets.json",
30-
serializer = WidgetsSerializer
30+
serializer = WidgetsSerializer,
3131
)
3232

3333
@Singleton

app/src/main/java/to/bitkit/data/dao/TagMetadataDao.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@ import androidx.room.Delete
55
import androidx.room.Insert
66
import androidx.room.OnConflictStrategy
77
import androidx.room.Query
8+
import androidx.room.Upsert
9+
import kotlinx.coroutines.flow.Flow
810
import to.bitkit.data.entities.TagMetadataEntity
911

1012
@Dao
1113
interface TagMetadataDao {
1214

1315
@Insert(onConflict = OnConflictStrategy.REPLACE)
14-
suspend fun saveTagMetadata(tagMetadata: TagMetadataEntity)
16+
suspend fun insert(tagMetadata: TagMetadataEntity)
17+
18+
@Upsert
19+
suspend fun upsert(tagMetadata: TagMetadataEntity)
20+
21+
@Query("SELECT * FROM tag_metadata")
22+
fun observeAll(): Flow<List<TagMetadataEntity>>
1523

1624
@Query("SELECT * FROM tag_metadata")
1725
suspend fun getAll(): List<TagMetadataEntity>

app/src/main/java/to/bitkit/data/dao/TransferDao.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.room.Insert
55
import androidx.room.OnConflictStrategy
66
import androidx.room.Query
77
import androidx.room.Update
8+
import androidx.room.Upsert
89
import kotlinx.coroutines.flow.Flow
910
import to.bitkit.data.entities.TransferEntity
1011

@@ -13,9 +14,18 @@ interface TransferDao {
1314
@Insert(onConflict = OnConflictStrategy.REPLACE)
1415
suspend fun insert(transfer: TransferEntity)
1516

17+
@Upsert
18+
suspend fun upsert(transfer: TransferEntity)
19+
1620
@Update
1721
suspend fun update(transfer: TransferEntity)
1822

23+
@Query("SELECT * FROM transfers")
24+
suspend fun getAll(): List<TransferEntity>
25+
26+
@Query("SELECT * FROM transfers")
27+
fun observeAll(): Flow<List<TransferEntity>>
28+
1929
@Query("SELECT * FROM transfers WHERE isSettled = 0")
2030
fun getActiveTransfers(): Flow<List<TransferEntity>>
2131

app/src/main/java/to/bitkit/data/entities/TagMetadataEntity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package to.bitkit.data.entities
22

33
import androidx.room.Entity
44
import androidx.room.PrimaryKey
5+
import kotlinx.serialization.Serializable
56

7+
@Serializable
68
@Entity(tableName = "tag_metadata")
79
/**
810
* @param id This will be paymentHash, txId, or address depending on context

app/src/main/java/to/bitkit/env/Env.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ internal object Env {
134134
return "$BIT_REFILL_URL/$page/$BITREFILL_PARAMS"
135135
}
136136

137+
/**
138+
* Generates the storage path for a specified wallet index, network, and directory.
139+
*
140+
* Output format:
141+
*
142+
* `appStoragePath/network/walletN/dir`
143+
*/
137144
private fun storagePathOf(walletIndex: Int, network: String, dir: String): String {
138145
require(::appStoragePath.isInitialized) { "App storage path should be 'context.filesDir.absolutePath'." }
139146
val path = Path(appStoragePath, network, "wallet$walletIndex", dir)

app/src/main/java/to/bitkit/ext/DateTime.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:Suppress("TooManyFunctions")
2+
13
package to.bitkit.ext
24

35
import android.icu.text.DateFormat
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package to.bitkit.models
2+
3+
import androidx.annotation.DrawableRes
4+
import androidx.annotation.StringRes
5+
import kotlinx.serialization.Serializable
6+
import to.bitkit.R
7+
8+
@Serializable
9+
enum class BackupCategory(
10+
@DrawableRes val icon: Int,
11+
@StringRes val title: Int,
12+
) {
13+
LIGHTNING_CONNECTIONS(
14+
icon = R.drawable.ic_lightning,
15+
title = R.string.settings__backup__category_connections,
16+
),
17+
BLOCKTANK(
18+
icon = R.drawable.ic_note,
19+
title = R.string.settings__backup__category_connection_receipts,
20+
),
21+
ACTIVITY(
22+
icon = R.drawable.ic_transfer,
23+
title = R.string.settings__backup__category_transaction_log,
24+
),
25+
WALLET(
26+
icon = R.drawable.ic_timer_alt,
27+
title = R.string.settings__backup__category_wallet,
28+
),
29+
SETTINGS(
30+
icon = R.drawable.ic_settings,
31+
title = R.string.settings__backup__category_settings,
32+
),
33+
WIDGETS(
34+
icon = R.drawable.ic_rectangles_two,
35+
title = R.string.settings__backup__category_widgets,
36+
),
37+
METADATA(
38+
icon = R.drawable.ic_tag,
39+
title = R.string.settings__backup__category_tags,
40+
),
41+
// Descoped in v1, will return in v2:
42+
// PROFILE(
43+
// icon = R.drawable.ic_user,
44+
// title = R.string.settings__backup__category_profile,
45+
// ),
46+
// CONTACTS(
47+
// icon = R.drawable.ic_users,
48+
// title = R.string.settings__backup__category_contacts,
49+
// ),
50+
}
51+
52+
/**
53+
* @property running In progress
54+
* @property synced Timestamp in ms of last time this backup was synced
55+
* @property required Timestamp in ms of last time this backup was required
56+
*/
57+
@Serializable
58+
data class BackupItemStatus(
59+
val running: Boolean = false,
60+
val synced: Long = 0L,
61+
val required: Long = 0L,
62+
)

0 commit comments

Comments
 (0)