Skip to content

Commit

Permalink
Nits contribution
Browse files Browse the repository at this point in the history
 - fix double call on view attached for the special case of the
   MainPresenter
 - remove double static configuration of bisq core jars (left in
   MainApplication override only)
 - provide single instance of android memory report service and adjust
   usages
 - cleanup/comment dead code
 - cleanup unused imports
  • Loading branch information
rodvar committed Nov 20, 2024
1 parent 066108b commit 5daa232
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import network.bisq.mobile.presentation.MainPresenter
class AndroidClientMainPresenter(
private val applicationBootstrapFacade: ApplicationBootstrapFacade
) : MainPresenter(GreetingRepository()) {

// FIXME onViewAttached is called twice
var applicationServiceInited = false
override fun onViewAttached() {
super.onViewAttached()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,13 @@
*/
package network.bisq.mobile.android.node

import android.content.Context
import android.os.Process
import androidx.core.util.Supplier
import bisq.account.AccountService
import bisq.application.ApplicationService
import bisq.application.State
import bisq.bonded_roles.BondedRolesService
import bisq.bonded_roles.security_manager.alert.AlertNotificationsService
import bisq.chat.ChatService
import bisq.common.facades.FacadeProvider
import bisq.common.facades.android.AndroidGuavaFacade
import bisq.common.facades.android.AndroidJdkFacade
import bisq.common.network.AndroidEmulatorLocalhostFacade
import bisq.common.observable.Observable
import bisq.common.util.ExceptionUtil
import bisq.contract.ContractService
Expand All @@ -49,11 +43,9 @@ import lombok.Getter
import lombok.Setter
import lombok.extern.slf4j.Slf4j
import network.bisq.mobile.android.node.service.AndroidMemoryReportService
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.nio.file.Path
import java.security.Security
import java.util.Optional
import java.util.concurrent.CompletableFuture
import java.util.concurrent.TimeUnit
Expand All @@ -66,7 +58,7 @@ import java.util.concurrent.TimeUnit
*/
@Slf4j
@Getter
class AndroidApplicationService(context: Context, userDataDir: Path?) :
class AndroidApplicationService(androidMemoryReportService: AndroidMemoryReportService, userDataDir: Path?) :
ApplicationService("android", arrayOf<String>(), userDataDir) {

@Getter
Expand Down Expand Up @@ -115,23 +107,10 @@ class AndroidApplicationService(context: Context, userDataDir: Path?) :
val log: Logger = LoggerFactory.getLogger(ApplicationService::class.java)
}

init {
FacadeProvider.setLocalhostFacade(AndroidEmulatorLocalhostFacade())
FacadeProvider.setJdkFacade(AndroidJdkFacade(Process.myPid()))
FacadeProvider.setGuavaFacade(AndroidGuavaFacade())

// Androids default BC version does not support all algorithms we need, thus we remove
// it and add our BC provider
Security.removeProvider("BC")
Security.addProvider(BouncyCastleProvider())
}

val state = Observable(State.INITIALIZE_APP)
private val shutDownErrorMessage = Observable<String>()
private val startupErrorMessage = Observable<String>()

val androidMemoryService = AndroidMemoryReportService(context)

val securityService =
SecurityService(persistenceService, SecurityService.Config.from(getConfig("security")))

Expand All @@ -144,7 +123,7 @@ class AndroidApplicationService(context: Context, userDataDir: Path?) :
securityService.keyBundleService,
securityService.hashCashProofOfWorkService,
securityService.equihashProofOfWorkService,
androidMemoryService
androidMemoryReportService
)
val identityService = IdentityService(
persistenceService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package network.bisq.mobile.android.node.di

import network.bisq.mobile.android.node.AndroidApplicationService
import network.bisq.mobile.android.node.domain.bootstrap.NodeApplicationBootstrapFacade
import network.bisq.mobile.android.node.domain.data.repository.NodeGreetingRepository
import network.bisq.mobile.android.node.domain.user_profile.NodeUserProfileServiceFacade
import network.bisq.mobile.android.node.main.bootstrap.NodeApplicationBootstrapFacade
import network.bisq.mobile.android.node.presentation.NodeMainPresenter
import network.bisq.mobile.android.node.service.AndroidMemoryReportService
import network.bisq.mobile.domain.data.repository.main.bootstrap.ApplicationBootstrapFacade
import network.bisq.mobile.domain.user_profile.UserProfileServiceFacade
import network.bisq.mobile.presentation.MainPresenter
import network.bisq.mobile.presentation.ui.AppPresenter
import org.koin.android.ext.koin.androidContext
import org.koin.dsl.bind
import org.koin.dsl.module

val androidNodeModule = module {
// this one is for example properties, will be eliminated soon
single<NodeGreetingRepository> { NodeGreetingRepository() }

single<AndroidMemoryReportService> {
AndroidMemoryReportService(androidContext())
}

single { AndroidApplicationService.Supplier() }

single<ApplicationBootstrapFacade> { NodeApplicationBootstrapFacade(get()) }
Expand All @@ -25,26 +31,5 @@ val androidNodeModule = module {

// this line showcases both, the possibility to change behaviour of the app by changing one definition
// and binding the same obj to 2 different abstractions
single<MainPresenter> { NodeMainPresenter(get(), get(), get()) } bind AppPresenter::class


// Services
// TODO might not work because of the jars dependencies, needs more work
// single <AndroidMemoryReportService> {
// val context = androidContext()
// AndroidMemoryReportService(context)
// }
// single <AndroidApplicationService> {
// val filesDirsPath = androidContext().filesDir.toPath()
// val androidMemoryService: AndroidMemoryReportService = get()
// AndroidApplicationService(androidMemoryService, filesDirsPath)
// }
// single <UserIdentityService> {
// val applicationService: AndroidApplicationService = get()
// applicationService.userService.userIdentityService
// }
// single <SecurityService> {
// val applicationService: AndroidApplicationService = get()
// applicationService.securityService
// }
single<MainPresenter> { NodeMainPresenter(get(), get(), get(), get()) } bind AppPresenter::class
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package network.bisq.mobile.android.node.main.bootstrap
package network.bisq.mobile.android.node.domain.bootstrap

import bisq.application.State
import network.bisq.mobile.android.node.AndroidApplicationService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package network.bisq.mobile.android.node.presentation
import android.app.Activity
import network.bisq.mobile.android.node.AndroidApplicationService
import network.bisq.mobile.android.node.domain.data.repository.NodeGreetingRepository
import network.bisq.mobile.android.node.service.AndroidMemoryReportService
import network.bisq.mobile.domain.data.model.Greeting
import network.bisq.mobile.domain.data.repository.GreetingRepository
import network.bisq.mobile.domain.data.repository.main.bootstrap.ApplicationBootstrapFacade
Expand All @@ -12,10 +13,10 @@ import network.bisq.mobile.presentation.MainPresenter
class NodeMainPresenter(
greetingRepository: NodeGreetingRepository,
private val supplier: AndroidApplicationService.Supplier,
private val androidMemoryReportService: AndroidMemoryReportService,
private val applicationBootstrapFacade: ApplicationBootstrapFacade
) : MainPresenter(greetingRepository as GreetingRepository<Greeting>) {

// FIXME onViewAttached is called twice
var applicationServiceInited = false
override fun onViewAttached() {
super.onViewAttached()
Expand All @@ -25,7 +26,7 @@ class NodeMainPresenter(
val context = (view as Activity).applicationContext
val filesDirsPath = (view as Activity).filesDir.toPath()
supplier.applicationService =
AndroidApplicationService(context, filesDirsPath)
AndroidApplicationService(androidMemoryReportService, filesDirsPath)
applicationBootstrapFacade.initialize()
supplier.applicationService.initialize()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package network.bisq.mobile.presentation

import co.touchlab.kermit.Logger
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import network.bisq.mobile.android.node.BuildNodeConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package network.bisq.mobile.presentation.ui

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.runtime.*
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import cafe.adriel.lyricist.ProvideStrings
import cafe.adriel.lyricist.rememberStrings
Expand Down Expand Up @@ -38,11 +36,13 @@ fun App() {

var isNavControllerSet by remember { mutableStateOf(false) }

val presenter: AppPresenter = koinInject()
// Looks like the main view composable is not needing the presenter at all - uncomment this if this changes
// val presenter: AppPresenter = koinInject()


LaunchedEffect(rootNavController) {
presenter.onViewAttached()
// For the main presenter use case we leave this for the moment the activity/viewcontroller respectively gets attached
// presenter.onViewAttached()
getKoin().setProperty("RootNavController", rootNavController)
getKoin().setProperty("TabNavController", tabNavController)
isNavControllerSet = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import network.bisq.mobile.domain.data.repository.main.bootstrap.ApplicationBoot
class IosClientMainPresenter(
private val applicationBootstrapFacade: ApplicationBootstrapFacade
) : MainPresenter(GreetingRepository()) {

// FIXME onViewAttached is called twice
var applicationServiceInited = false
override fun onViewAttached() {
super.onViewAttached()
Expand Down

0 comments on commit 5daa232

Please sign in to comment.