From 402d73d440435eb074c3d6d6a371a1c0dffebd33 Mon Sep 17 00:00:00 2001 From: Rodrigo Varela Date: Thu, 23 Jan 2025 15:43:18 +1100 Subject: [PATCH] - tidy up code - presenters related to trade process not singleton (use factory instead) --- .../node/presentation/NodeMainPresenter.kt | 13 ++++---- .../NotificationServiceController.android.kt | 30 +++++++++---------- .../presentation/di/PresentationModule.kt | 28 ++++++++--------- .../selected/states/SellerState2bPresenter.kt | 4 +-- 4 files changed, 38 insertions(+), 37 deletions(-) diff --git a/androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/presentation/NodeMainPresenter.kt b/androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/presentation/NodeMainPresenter.kt index dc4ba43f..30a613c7 100644 --- a/androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/presentation/NodeMainPresenter.kt +++ b/androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/presentation/NodeMainPresenter.kt @@ -30,7 +30,6 @@ class NodeMainPresenter( runCatching { if (!applicationServiceCreated) { - applicationServiceCreated = true val filesDirsPath = (view as Activity).filesDir.toPath() val applicationContext = (view as Activity).applicationContext val applicationService = @@ -57,6 +56,7 @@ class NodeMainPresenter( log.e("Initializing applicationService failed", throwable) } } + applicationServiceCreated = true } else { settingsServiceFacade.activate() offersServiceFacade.activate() @@ -77,8 +77,10 @@ class NodeMainPresenter( } override fun onDestroying() { -// TODO stop should be called here only if there are no open trades and no maker online users for this profile -// provider.applicationService.onStop() +// TODO for notifications to work even if the app gets killed this needs to be commented out +// but it can't be done yet because of lack of support in bisq2 jars + provider.applicationService.onStop() + applicationServiceCreated = false super.onDestroying() } @@ -87,7 +89,8 @@ class NodeMainPresenter( settingsServiceFacade.deactivate() offersServiceFacade.deactivate() marketPriceServiceFacade.deactivate() -// TODO stop should be called here only if there are no open trades and no maker online users for this profile -// tradesServiceFacade.deactivate() +// TODO for notifications to work even if the app gets killed this needs to be commented out +// but it can't be done yet because of lack of support in bisq2 jars + tradesServiceFacade.deactivate() } } \ No newline at end of file diff --git a/shared/domain/src/androidMain/kotlin/network/bisq/mobile/domain/service/controller/NotificationServiceController.android.kt b/shared/domain/src/androidMain/kotlin/network/bisq/mobile/domain/service/controller/NotificationServiceController.android.kt index e1338020..f7bb21b1 100644 --- a/shared/domain/src/androidMain/kotlin/network/bisq/mobile/domain/service/controller/NotificationServiceController.android.kt +++ b/shared/domain/src/androidMain/kotlin/network/bisq/mobile/domain/service/controller/NotificationServiceController.android.kt @@ -105,22 +105,22 @@ actual class NotificationServiceController (private val context: Context): Servi observerJobs.remove(stateFlow) } - // TODO support for on click + // TODO support for on click and decide if we block on foreground actual fun pushNotification(title: String, message: String) { - if (isForeground) { - log.w { "Skipping notification since app is in the foreground" } - } else { - val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager - val notification = NotificationCompat.Builder(context, BisqForegroundService.CHANNEL_ID) - .setContentTitle(title) - .setContentText(message) - .setSmallIcon(android.R.drawable.ic_notification_overlay) - .setPriority(NotificationCompat.PRIORITY_DEFAULT) // For android previous to O - .setOngoing(true) - .build() - notificationManager.notify(BisqForegroundService.PUSH_NOTIFICATION_ID, notification) - log.d {"Pushed notification: $title: $message" } - } +// if (isForeground) { +// log.w { "Skipping notification since app is in the foreground" } +// } else { + val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + val notification = NotificationCompat.Builder(context, BisqForegroundService.CHANNEL_ID) + .setContentTitle(title) + .setContentText(message) + .setSmallIcon(android.R.drawable.ic_notification_overlay) + .setPriority(NotificationCompat.PRIORITY_DEFAULT) // For android previous to O + .setOngoing(true) + .build() + notificationManager.notify(BisqForegroundService.PUSH_NOTIFICATION_ID, notification) + log.d {"Pushed notification: $title: $message" } +// } } actual override fun isServiceRunning() = isRunning diff --git a/shared/presentation/src/commonMain/kotlin/network/bisq/mobile/presentation/di/PresentationModule.kt b/shared/presentation/src/commonMain/kotlin/network/bisq/mobile/presentation/di/PresentationModule.kt index 238fe5c6..079203e0 100644 --- a/shared/presentation/src/commonMain/kotlin/network/bisq/mobile/presentation/di/PresentationModule.kt +++ b/shared/presentation/src/commonMain/kotlin/network/bisq/mobile/presentation/di/PresentationModule.kt @@ -108,23 +108,23 @@ val presentationModule = module { single { CreateOfferReviewPresenter(get(), get()) } // Trade Seller - single { SellerState1Presenter(get(), get()) } - single { SellerState2aPresenter(get(), get()) } - single { SellerState2bPresenter(get(), get()) } - single { SellerState3aPresenter(get(), get()) } - single { SellerStateMainChain3bPresenter(get(), get(), get()) } - single { SellerStateLightning3bPresenter(get(), get()) } - single { SellerState4Presenter(get(), get()) } + factory { SellerState1Presenter(get(), get()) } + factory { SellerState2aPresenter(get(), get()) } + factory { SellerState2bPresenter(get(), get()) } + factory { SellerState3aPresenter(get(), get()) } + factory { SellerStateMainChain3bPresenter(get(), get(), get()) } + factory { SellerStateLightning3bPresenter(get(), get()) } + factory { SellerState4Presenter(get(), get()) } // Trade Buyer - single { BuyerState1aPresenter(get(), get()) } + factory { BuyerState1aPresenter(get(), get()) } // BuyerState1bPresenter does not exist as it a static UI - single { BuyerState2aPresenter(get(), get()) } - single { BuyerState2bPresenter(get(), get()) } - single { BuyerState3aPresenter(get(), get()) } - single { BuyerStateMainChain3bPresenter(get(), get(), get()) } - single { BuyerStateLightning3bPresenter(get(), get()) } - single { BuyerState4Presenter(get(), get()) } + factory { BuyerState2aPresenter(get(), get()) } + factory { BuyerState2bPresenter(get(), get()) } + factory { BuyerState3aPresenter(get(), get()) } + factory { BuyerStateMainChain3bPresenter(get(), get(), get()) } + factory { BuyerStateLightning3bPresenter(get(), get()) } + factory { BuyerState4Presenter(get(), get()) } // Trade General process factory { TradeStatesProvider(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) } diff --git a/shared/presentation/src/commonMain/kotlin/network/bisq/mobile/presentation/ui/uicases/open_trades/selected/states/SellerState2bPresenter.kt b/shared/presentation/src/commonMain/kotlin/network/bisq/mobile/presentation/ui/uicases/open_trades/selected/states/SellerState2bPresenter.kt index 5080eff9..7d0504d2 100644 --- a/shared/presentation/src/commonMain/kotlin/network/bisq/mobile/presentation/ui/uicases/open_trades/selected/states/SellerState2bPresenter.kt +++ b/shared/presentation/src/commonMain/kotlin/network/bisq/mobile/presentation/ui/uicases/open_trades/selected/states/SellerState2bPresenter.kt @@ -1,10 +1,8 @@ package network.bisq.mobile.presentation.ui.uicases.open_trades.selected.states -import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch -import network.bisq.mobile.domain.data.BackgroundDispatcher import network.bisq.mobile.domain.data.replicated.presentation.open_trades.TradeItemPresentationModel import network.bisq.mobile.domain.service.trades.TradesServiceFacade import network.bisq.mobile.presentation.BasePresenter @@ -28,7 +26,7 @@ class SellerState2bPresenter( } fun onConfirmFiatReceipt() { - job = CoroutineScope(BackgroundDispatcher).launch { + job = backgroundScope.launch { tradesServiceFacade.sellerConfirmFiatReceipt() } }