Skip to content

Commit

Permalink
- tidy up code
Browse files Browse the repository at this point in the history
 - presenters related to trade process not singleton (use factory instead)
  • Loading branch information
rodvar committed Jan 23, 2025
1 parent 0c12695 commit 402d73d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -57,6 +56,7 @@ class NodeMainPresenter(
log.e("Initializing applicationService failed", throwable)
}
}
applicationServiceCreated = true
} else {
settingsServiceFacade.activate()
offersServiceFacade.activate()
Expand All @@ -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()
}

Expand All @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) }
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -28,7 +26,7 @@ class SellerState2bPresenter(
}

fun onConfirmFiatReceipt() {
job = CoroutineScope(BackgroundDispatcher).launch {
job = backgroundScope.launch {
tradesServiceFacade.sellerConfirmFiatReceipt()
}
}
Expand Down

0 comments on commit 402d73d

Please sign in to comment.