-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- make sure notifications are clickable on android
- notification takes user to open trades tab - refactor main notification open trade code into its own service [Ticket: X]
- Loading branch information
Showing
15 changed files
with
120 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
shared/domain/src/androidMain/kotlin/network/bisq/mobile/domain/di/DomainModule.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
.../kotlin/network/bisq/mobile/domain/service/notifications/OpenTradesNotificationService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package network.bisq.mobile.domain.service.notifications | ||
|
||
import network.bisq.mobile.domain.data.replicated.presentation.open_trades.TradeItemPresentationModel | ||
import network.bisq.mobile.domain.service.notifications.controller.NotificationServiceController | ||
import network.bisq.mobile.domain.service.offers.OffersServiceFacade | ||
import network.bisq.mobile.domain.service.trades.TradesServiceFacade | ||
import network.bisq.mobile.domain.utils.Logging | ||
|
||
class OpenTradesNotificationService( | ||
val notificationServiceController: NotificationServiceController, | ||
private val tradesServiceFacade: TradesServiceFacade): Logging { | ||
|
||
fun launchNotificationService() { | ||
notificationServiceController.startService() | ||
runCatching { | ||
notificationServiceController.registerObserver(tradesServiceFacade.openTradeItems) { newValue -> | ||
log.d { "open trades in total: ${newValue.size}" } | ||
newValue.sortedByDescending { it.bisqEasyTradeModel.takeOfferDate } | ||
.forEach { trade -> | ||
onTradeUpdate(trade) | ||
} | ||
} | ||
}.onFailure { | ||
log.e(it) { "Failed to register observer" } | ||
} | ||
} | ||
|
||
fun stopNotificationService() { | ||
notificationServiceController.unregisterObserver(tradesServiceFacade.openTradeItems) | ||
// TODO unregister all ? | ||
notificationServiceController.stopService() | ||
} | ||
|
||
/** | ||
* Register to observe open trade state. Unregister when the trade concludes | ||
* Triggers push notifications | ||
*/ | ||
private fun onTradeUpdate(trade: TradeItemPresentationModel) { | ||
log.d { "open trade: $trade" } | ||
notificationServiceController.registerObserver(trade.bisqEasyTradeModel.tradeState) { | ||
log.d { "Open trade State Changed to: $it" } | ||
if (OffersServiceFacade.isTerminalNode(it)) { | ||
notificationServiceController.unregisterObserver(trade.bisqEasyTradeModel.tradeState) | ||
notificationServiceController.pushNotification( | ||
"Trade [${trade.shortTradeId}] completed", | ||
"Your trade with ${trade.peersUserName} has finished as ${it}" | ||
) | ||
} else { | ||
notificationServiceController.pushNotification( | ||
"Trade [${trade.shortTradeId}] activity", | ||
"Your trade with ${trade.peersUserName} needs your attention" | ||
) | ||
} | ||
|
||
} | ||
} | ||
} |
4 changes: 1 addition & 3 deletions
4
...ntroller/NotificationServiceController.kt → ...ntroller/NotificationServiceController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...n/service/controller/ServiceController.kt → ...fications/controller/ServiceController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ller/NotificationServiceController.ios.kt → ...ller/NotificationServiceController.ios.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters