mirror of
https://github.com/mollyim/monero-wallet-sdk.git
synced 2024-10-01 03:45:36 -04:00
demo: initialize remote node list with default values
This commit is contained in:
parent
db85c2234f
commit
743e9997c5
@ -2,7 +2,11 @@ package im.molly.monero.demo
|
||||
|
||||
import android.app.Application
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import im.molly.monero.demo.data.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* Naive container of global instances.
|
||||
@ -11,13 +15,20 @@ import im.molly.monero.demo.data.*
|
||||
*/
|
||||
object AppModule {
|
||||
private lateinit var application: Application
|
||||
private lateinit var populateInitialData: suspend (AppDatabase) -> Unit
|
||||
|
||||
private val applicationScope = kotlinx.coroutines.MainScope()
|
||||
|
||||
private val database: AppDatabase by lazy {
|
||||
Room.databaseBuilder(
|
||||
application, AppDatabase::class.java, "monero-demo.db"
|
||||
).build()
|
||||
).addCallback(object : RoomDatabase.Callback() {
|
||||
override fun onCreate(db: SupportSQLiteDatabase) {
|
||||
applicationScope.launch(Dispatchers.IO) {
|
||||
populateInitialData(database)
|
||||
}
|
||||
}
|
||||
}).build()
|
||||
}
|
||||
|
||||
private val walletDataSource: WalletDataSource by lazy {
|
||||
@ -40,7 +51,8 @@ object AppModule {
|
||||
WalletRepository(moneroSdkClient, walletDataSource, settingsRepository, applicationScope)
|
||||
}
|
||||
|
||||
fun provide(application: Application) {
|
||||
fun provide(application: Application, populateInitialData: suspend (AppDatabase) -> Unit) {
|
||||
this.application = application
|
||||
this.populateInitialData = populateInitialData
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
package im.molly.monero.demo
|
||||
|
||||
import android.net.Uri
|
||||
import im.molly.monero.MoneroNetwork
|
||||
import im.molly.monero.demo.data.AppDatabase
|
||||
import im.molly.monero.demo.data.entity.asEntity
|
||||
import im.molly.monero.demo.data.model.RemoteNode
|
||||
|
||||
val DefaultNodeList = listOf(
|
||||
MoneroNetwork.Mainnet to listOf(
|
||||
"http://node.monerodevs.org:18089",
|
||||
"http://node.sethforprivacy.com:18089",
|
||||
"http://xmr-node.cakewallet.com:18081",
|
||||
),
|
||||
MoneroNetwork.Testnet to listOf(
|
||||
"http://node2.monerodevs.org:28089",
|
||||
),
|
||||
)
|
||||
|
||||
suspend fun addDefaultRemoteNodes(appDatabase: AppDatabase) {
|
||||
val dao = appDatabase.remoteNodeDao()
|
||||
val nodes = DefaultNodeList.flatMap { (network, urls) ->
|
||||
urls.map { url ->
|
||||
RemoteNode(network = network, uri = Uri.parse(url)).asEntity()
|
||||
}
|
||||
}.toTypedArray()
|
||||
dao.upsert(*nodes)
|
||||
}
|
@ -12,7 +12,6 @@ import im.molly.monero.isIsolatedProcess
|
||||
val Context.preferencesDataStore: DataStore<Preferences> by preferencesDataStore(name = "settings")
|
||||
|
||||
class MainApplication : Application() {
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
StrictMode.setVmPolicy(
|
||||
@ -23,7 +22,12 @@ class MainApplication : Application() {
|
||||
if (isIsolatedProcess()) {
|
||||
return
|
||||
}
|
||||
AppModule.provide(this)
|
||||
AppModule.provide(
|
||||
application = this,
|
||||
populateInitialData = { db ->
|
||||
addDefaultRemoteNodes(db)
|
||||
},
|
||||
)
|
||||
SyncService.start(this)
|
||||
}
|
||||
}
|
||||
|
@ -75,6 +75,7 @@ private fun RemoteNodeItem(
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = remoteNode.uri.toString(),
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
modifier = (if (enabled) Modifier else Modifier.alpha(0.3f)),
|
||||
)
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user