Skip to content

Commit 44bfcbd

Browse files
authored
Merge pull request #116 from synonymdev/feat/tags-edit-invoice
Implement tag feature in the EditInvoiceScreen
2 parents 39c15b8 + 49f5b79 commit 44bfcbd

File tree

13 files changed

+618
-180
lines changed

13 files changed

+618
-180
lines changed

app/schemas/to.bitkit.data.AppDb/1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'ea0d5b36d92a5a3fb1523c3064686f7d')"
3232
]
3333
}
34-
}
34+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"formatVersion": 1,
3+
"database": {
4+
"version": 2,
5+
"identityHash": "548162ed64d13ae0bed807c23709b850",
6+
"entities": [
7+
{
8+
"tableName": "config",
9+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`walletIndex` INTEGER NOT NULL, PRIMARY KEY(`walletIndex`))",
10+
"fields": [
11+
{
12+
"fieldPath": "walletIndex",
13+
"columnName": "walletIndex",
14+
"affinity": "INTEGER",
15+
"notNull": true
16+
}
17+
],
18+
"primaryKey": {
19+
"autoGenerate": false,
20+
"columnNames": [
21+
"walletIndex"
22+
]
23+
},
24+
"indices": [],
25+
"foreignKeys": []
26+
},
27+
{
28+
"tableName": "invoice_tag",
29+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`paymentHash` TEXT NOT NULL, `tags` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`paymentHash`))",
30+
"fields": [
31+
{
32+
"fieldPath": "paymentHash",
33+
"columnName": "paymentHash",
34+
"affinity": "TEXT",
35+
"notNull": true
36+
},
37+
{
38+
"fieldPath": "tags",
39+
"columnName": "tags",
40+
"affinity": "TEXT",
41+
"notNull": true
42+
},
43+
{
44+
"fieldPath": "createdAt",
45+
"columnName": "createdAt",
46+
"affinity": "INTEGER",
47+
"notNull": true
48+
}
49+
],
50+
"primaryKey": {
51+
"autoGenerate": false,
52+
"columnNames": [
53+
"paymentHash"
54+
]
55+
},
56+
"indices": [],
57+
"foreignKeys": []
58+
}
59+
],
60+
"views": [],
61+
"setupQueries": [
62+
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
63+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '548162ed64d13ae0bed807c23709b850')"
64+
]
65+
}
66+
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import androidx.room.Database
66
import androidx.room.Query
77
import androidx.room.Room
88
import androidx.room.RoomDatabase
9+
import androidx.room.TypeConverters
910
import androidx.room.Upsert
1011
import androidx.sqlite.db.SupportSQLiteDatabase
1112
import androidx.work.CoroutineWorker
@@ -15,17 +16,24 @@ import androidx.work.WorkerParameters
1516
import kotlinx.coroutines.coroutineScope
1617
import kotlinx.coroutines.flow.Flow
1718
import to.bitkit.BuildConfig
19+
import to.bitkit.data.dao.InvoiceTagDao
1820
import to.bitkit.data.entities.ConfigEntity
21+
import to.bitkit.data.entities.InvoiceTagEntity
22+
import to.bitkit.data.typeConverters.StringListConverter
1923
import to.bitkit.env.Env
2024

2125
@Database(
2226
entities = [
2327
ConfigEntity::class,
28+
InvoiceTagEntity::class
2429
],
25-
version = 1,
30+
version = 2,
2631
)
32+
33+
@TypeConverters(StringListConverter::class)
2734
abstract class AppDb : RoomDatabase() {
2835
abstract fun configDao(): ConfigDao
36+
abstract fun invoiceTagDao(): InvoiceTagDao
2937

3038
companion object {
3139
private val DB_NAME = "${BuildConfig.APPLICATION_ID}.${Env.network.name.lowercase()}.sqlite"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package to.bitkit.data.dao
2+
3+
import androidx.room.Dao
4+
import androidx.room.Delete
5+
import androidx.room.Insert
6+
import androidx.room.OnConflictStrategy
7+
import androidx.room.Query
8+
import to.bitkit.data.entities.InvoiceTagEntity
9+
10+
@Dao
11+
interface InvoiceTagDao {
12+
13+
@Insert(onConflict = OnConflictStrategy.REPLACE)
14+
suspend fun saveInvoice(invoiceTag: InvoiceTagEntity)
15+
16+
@Query("SELECT * FROM invoice_tag WHERE paymentHash = :paymentHash LIMIT 1")
17+
suspend fun searchInvoice(paymentHash: String) : InvoiceTagEntity?
18+
19+
@Delete
20+
suspend fun deleteInvoice(invoiceTag: InvoiceTagEntity)
21+
22+
@Query("DELETE FROM invoice_tag WHERE paymentHash = :paymentHash")
23+
suspend fun deleteInvoiceByPaymentHash(paymentHash: String)
24+
25+
@Query("DELETE FROM invoice_tag")
26+
suspend fun deleteAllInvoices()
27+
28+
@Query("DELETE FROM invoice_tag WHERE createdAt < :expirationTimeStamp")
29+
suspend fun deleteExpiredInvoices(expirationTimeStamp: Long)
30+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package to.bitkit.data.entities
2+
3+
import androidx.room.Entity
4+
import androidx.room.PrimaryKey
5+
6+
@Entity(tableName = "invoice_tag")
7+
data class InvoiceTagEntity(
8+
@PrimaryKey val paymentHash: String,
9+
val tags: List<String>,
10+
val createdAt: Long
11+
)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package to.bitkit.data.typeConverters
2+
3+
import androidx.room.TypeConverter
4+
5+
class StringListConverter {
6+
@TypeConverter
7+
fun fromString(value: String): List<String> {
8+
return value.split(",").map { it.trim() }
9+
}
10+
11+
@TypeConverter
12+
fun fromList(list: List<String>): String {
13+
return list.joinToString(",")
14+
}
15+
}

app/src/main/java/to/bitkit/models/NodeLifecycleState.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ sealed class NodeLifecycleState {
1212
fun isRunningOrStarting() = this is Running || this is Starting
1313
fun isStarting() = this is Starting
1414
fun isRunning() = this is Running
15+
fun canRun() = this.isRunningOrStarting() || this is Initializing
1516

1617
val displayState: String
1718
get() = when (this) {

0 commit comments

Comments
 (0)