summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAlbin <albin@mullvad.net>2022-07-28 08:19:34 +0200
committerAlbin <albin@mullvad.net>2022-07-29 13:01:20 +0200
commita398be971f403c5accd6d4b0b649ba352bc12c86 (patch)
tree1daddf4646fd07b509a62679bb004c53cedf3396
parent45eaba30c34d303dd26103bca42c65fc62775ea9 (diff)
downloadmullvadvpn-a398be971f403c5accd6d4b0b649ba352bc12c86.tar.xz
mullvadvpn-a398be971f403c5accd6d4b0b649ba352bc12c86.zip
Add toast capability to device list view
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragments/DeviceListFragment.kt20
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceListViewModel.kt6
2 files changed, 26 insertions, 0 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragments/DeviceListFragment.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragments/DeviceListFragment.kt
index 2a6756abe9..5fe2cf46b1 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragments/DeviceListFragment.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragments/DeviceListFragment.kt
@@ -4,9 +4,16 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import android.widget.Toast
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.res.colorResource
import androidx.fragment.app.Fragment
+import androidx.lifecycle.Lifecycle
+import androidx.lifecycle.flowWithLifecycle
+import androidx.lifecycle.lifecycleScope
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.flow.collect
+import kotlinx.coroutines.launch
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.compose.component.ScaffoldWithTopBar
import net.mullvad.mullvadvpn.compose.screen.DeviceListScreen
@@ -19,6 +26,11 @@ class DeviceListFragment : Fragment() {
private val deviceListViewModel by viewModel<DeviceListViewModel>()
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ lifecycleScope.launchUiSubscriptionsOnResume()
+ }
+
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
@@ -46,6 +58,14 @@ class DeviceListFragment : Fragment() {
}
}
+ private fun CoroutineScope.launchUiSubscriptionsOnResume() = launch {
+ deviceListViewModel.toastMessages
+ .flowWithLifecycle(lifecycle, Lifecycle.State.RESUMED)
+ .collect {
+ Toast.makeText(context, it, Toast.LENGTH_SHORT).show()
+ }
+ }
+
private fun openLoginView(doTriggerAutoLogin: Boolean) {
parentActivity()?.clearBackStack()
val loginFragment = LoginFragment().apply {
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceListViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceListViewModel.kt
index 027520d293..1dfc7cc596 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceListViewModel.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceListViewModel.kt
@@ -2,8 +2,10 @@ package net.mullvad.mullvadvpn.viewmodel
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
+import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
+import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.stateIn
import net.mullvad.mullvadvpn.compose.state.DeviceListUiState
@@ -15,6 +17,10 @@ class DeviceListViewModel(
private val deviceRepository: DeviceRepository
) : ViewModel() {
private val _stagedForRemoval = MutableStateFlow<Device?>(null)
+
+ private val _toastMessages = MutableSharedFlow<String>(extraBufferCapacity = 1)
+ val toastMessages = _toastMessages.asSharedFlow()
+
var accountToken: String? = null
val uiState = deviceRepository.deviceList