-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/clients ongoing trades notifications (android) (#176)
* - land user in open trades when clicking notification implemented for bisq connect android * refactor: extract foreground detector into a separate platform based code controller * - android client working (Except kill app case for the reasons in discussion) - improved logging for iOS
- Loading branch information
Showing
15 changed files
with
204 additions
and
40 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
...oidClient/src/androidMain/kotlin/network/bisq/mobile/client/AndroidClientMainPresenter.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,29 @@ | ||
package network.bisq.mobile.client | ||
|
||
import network.bisq.mobile.client.websocket.WebSocketClientProvider | ||
import network.bisq.mobile.domain.UrlLauncher | ||
import network.bisq.mobile.domain.service.bootstrap.ApplicationBootstrapFacade | ||
import network.bisq.mobile.domain.service.market_price.MarketPriceServiceFacade | ||
import network.bisq.mobile.domain.service.notifications.OpenTradesNotificationService | ||
import network.bisq.mobile.domain.service.offers.OffersServiceFacade | ||
import network.bisq.mobile.domain.service.settings.SettingsServiceFacade | ||
import network.bisq.mobile.domain.service.trades.TradesServiceFacade | ||
|
||
/** | ||
* Redefinition to be able to access activity for trading notifications click handling | ||
*/ | ||
class AndroidClientMainPresenter(openTradesNotificationService: OpenTradesNotificationService, | ||
tradesServiceFacade: TradesServiceFacade, | ||
webSocketClientProvider: WebSocketClientProvider, | ||
applicationBootstrapFacade: ApplicationBootstrapFacade, | ||
offersServiceFacade: OffersServiceFacade, | ||
marketPriceServiceFacade: MarketPriceServiceFacade, | ||
settingsServiceFacade: SettingsServiceFacade, urlLauncher: UrlLauncher | ||
) : ClientMainPresenter( | ||
openTradesNotificationService, tradesServiceFacade, webSocketClientProvider, applicationBootstrapFacade, | ||
offersServiceFacade, marketPriceServiceFacade, settingsServiceFacade, urlLauncher | ||
) { | ||
init { | ||
openTradesNotificationService.notificationServiceController.activityClassForIntents = MainActivity::class.java | ||
} | ||
} |
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
6 changes: 5 additions & 1 deletion
6
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
package network.bisq.mobile.domain.di | ||
|
||
import network.bisq.mobile.domain.service.AppForegroundController | ||
import network.bisq.mobile.domain.service.ForegroundDetector | ||
import network.bisq.mobile.domain.service.notifications.controller.NotificationServiceController | ||
import org.koin.dsl.module | ||
import org.koin.android.ext.koin.androidContext | ||
import org.koin.dsl.bind | ||
|
||
val serviceModule = module { | ||
single<NotificationServiceController> { NotificationServiceController(androidContext()) } | ||
single<AppForegroundController> { AppForegroundController(androidContext()) } bind ForegroundDetector::class | ||
single<NotificationServiceController> { NotificationServiceController(get()) } | ||
} |
46 changes: 46 additions & 0 deletions
46
.../androidMain/kotlin/network/bisq/mobile/domain/service/AppForegroundController.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package network.bisq.mobile.domain.service | ||
|
||
import android.app.Activity | ||
import android.app.Application | ||
import android.content.Context | ||
import android.os.Bundle | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import network.bisq.mobile.domain.utils.Logging | ||
|
||
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING") | ||
actual class AppForegroundController(val context: Context) : ForegroundDetector, Logging { | ||
private val _isForeground = MutableStateFlow(false) | ||
override val isForeground: StateFlow<Boolean> = _isForeground | ||
|
||
init { | ||
(context.applicationContext as Application).registerActivityLifecycleCallbacks(object : Application.ActivityLifecycleCallbacks { | ||
override fun onActivityResumed(activity: Activity) { | ||
onAppWillEnterForeground() | ||
} | ||
|
||
override fun onActivityPaused(activity: Activity) { | ||
onAppDidEnterBackground() | ||
} | ||
|
||
// Other lifecycle methods can be left empty | ||
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {} | ||
override fun onActivityStarted(activity: Activity) {} | ||
override fun onActivityStopped(activity: Activity) {} | ||
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {} | ||
override fun onActivityDestroyed(activity: Activity) {} | ||
}) | ||
} | ||
|
||
|
||
private fun onAppDidEnterBackground() { | ||
log.d("App is in foreground -> false") | ||
_isForeground.value = false | ||
} | ||
|
||
private fun onAppWillEnterForeground() { | ||
log.d("App is in foreground -> true") | ||
_isForeground.value = true | ||
} | ||
|
||
} |
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
10 changes: 10 additions & 0 deletions
10
...omain/src/commonMain/kotlin/network/bisq/mobile/domain/service/AppForegroundController.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,10 @@ | ||
package network.bisq.mobile.domain.service | ||
|
||
import kotlinx.coroutines.flow.StateFlow | ||
|
||
interface ForegroundDetector { | ||
val isForeground: StateFlow<Boolean> | ||
} | ||
|
||
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING") | ||
expect class AppForegroundController |
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
43 changes: 43 additions & 0 deletions
43
...main/src/iosMain/kotlin/network/bisq/mobile/domain/service/AppForegroundController.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package network.bisq.mobile.domain.service | ||
|
||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import network.bisq.mobile.domain.utils.Logging | ||
import platform.Foundation.NSNotificationCenter | ||
import platform.UIKit.UIApplicationDidEnterBackgroundNotification | ||
import platform.UIKit.UIApplicationWillEnterForegroundNotification | ||
|
||
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING") | ||
actual class AppForegroundController : ForegroundDetector, Logging { | ||
private val _isForeground = MutableStateFlow(true) | ||
override val isForeground: StateFlow<Boolean> = _isForeground | ||
|
||
init { | ||
val notificationCenter = NSNotificationCenter.defaultCenter | ||
notificationCenter.addObserverForName( | ||
name = UIApplicationDidEnterBackgroundNotification, | ||
`object` = null, | ||
queue = null | ||
) { notification -> | ||
onAppDidEnterBackground() | ||
} | ||
notificationCenter.addObserverForName( | ||
name = UIApplicationWillEnterForegroundNotification, | ||
`object` = null, | ||
queue = null | ||
) { notification -> | ||
onAppWillEnterForeground() | ||
} | ||
} | ||
|
||
private fun onAppDidEnterBackground() { | ||
log.d {"App is in foreground -> false" } | ||
_isForeground.value = false | ||
|
||
} | ||
|
||
private fun onAppWillEnterForeground() { | ||
log.d {"App is in foreground -> true" } | ||
_isForeground.value = true | ||
} | ||
} |
Oops, something went wrong.