-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bdfca5c
commit ba23a45
Showing
33 changed files
with
120 additions
and
113 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
18 changes: 18 additions & 0 deletions
18
android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/NewDeviceRepository.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,18 @@ | ||
package net.mullvad.mullvadvpn.repository | ||
|
||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
|
||
class NewDeviceRepository { | ||
private val _mutableShowNewDeviceNotification = MutableStateFlow(false) | ||
|
||
val isNewDevice: StateFlow<Boolean> = _mutableShowNewDeviceNotification | ||
|
||
fun newDeviceCreated() { | ||
_mutableShowNewDeviceNotification.value = true | ||
} | ||
|
||
fun clearNewDeviceCreatedNotification() { | ||
_mutableShowNewDeviceNotification.value = false | ||
} | ||
} |
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
21 changes: 7 additions & 14 deletions
21
android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/NewDeviceNotificationUseCase.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,32 +1,25 @@ | ||
package net.mullvad.mullvadvpn.usecase | ||
|
||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.combine | ||
import kotlinx.coroutines.flow.distinctUntilChanged | ||
import kotlinx.coroutines.flow.map | ||
import net.mullvad.mullvadvpn.lib.shared.DeviceRepository | ||
import net.mullvad.mullvadvpn.repository.InAppNotification | ||
import net.mullvad.mullvadvpn.repository.NewDeviceRepository | ||
|
||
class NewDeviceNotificationUseCase(private val deviceRepository: DeviceRepository) { | ||
private val _mutableShowNewDeviceNotification = MutableStateFlow(false) | ||
|
||
fun notifications() = | ||
class NewDeviceNotificationUseCase( | ||
private val newDeviceRepository: NewDeviceRepository, | ||
private val deviceRepository: DeviceRepository | ||
) { | ||
operator fun invoke() = | ||
combine( | ||
deviceRepository.deviceState.map { it?.displayName() }, | ||
_mutableShowNewDeviceNotification | ||
newDeviceRepository.isNewDevice | ||
) { deviceName, newDeviceCreated -> | ||
if (newDeviceCreated && deviceName != null) { | ||
InAppNotification.NewDevice(deviceName) | ||
} else null | ||
} | ||
.map(::listOfNotNull) | ||
.distinctUntilChanged() | ||
|
||
fun newDeviceCreated() { | ||
_mutableShowNewDeviceNotification.value = true | ||
} | ||
|
||
fun clearNewDeviceCreatedNotification() { | ||
_mutableShowNewDeviceNotification.value = false | ||
} | ||
} |
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
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
Oops, something went wrong.