Skip to content

Commit 40090f1

Browse files
authored
android: Fix search not filtering machines from input (#478)
android: Fix search not filtering text input Fixes tailscale/tailscale#13218 * Filtering machines in the textfield works since the flow is now reachable * Updating the health icon works since the flow is now reachable Signed-off-by: Josh Vocal <[email protected]>
1 parent 502eada commit 40090f1

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

android/src/main/java/com/tailscale/ipn/ui/viewModel/MainViewModel.kt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ import com.tailscale.ipn.ui.util.PeerCategorizer
2323
import com.tailscale.ipn.ui.util.PeerSet
2424
import com.tailscale.ipn.ui.util.TimeUtil
2525
import com.tailscale.ipn.ui.util.set
26+
import kotlinx.coroutines.FlowPreview
2627
import kotlinx.coroutines.flow.MutableStateFlow
2728
import kotlinx.coroutines.flow.StateFlow
2829
import kotlinx.coroutines.flow.combine
30+
import kotlinx.coroutines.flow.debounce
2931
import kotlinx.coroutines.launch
3032
import java.time.Duration
3133

@@ -38,6 +40,7 @@ class MainViewModelFactory(private val vpnViewModel: VpnViewModel) : ViewModelPr
3840
}
3941
}
4042

43+
@OptIn(FlowPreview::class)
4144
class MainViewModel(private val vpnViewModel: VpnViewModel) : IpnViewModel() {
4245

4346
// The user readable state of the system
@@ -112,6 +115,14 @@ class MainViewModel(private val vpnViewModel: VpnViewModel) : IpnViewModel() {
112115
}
113116
}
114117

118+
viewModelScope.launch {
119+
searchTerm
120+
.debounce(250L)
121+
.collect { term ->
122+
peers.set(peerCategorizer.groupedAndFilteredPeers(term))
123+
}
124+
}
125+
115126
viewModelScope.launch {
116127
Notifier.netmap.collect { it ->
117128
it?.let { netmap ->
@@ -131,14 +142,10 @@ class MainViewModel(private val vpnViewModel: VpnViewModel) : IpnViewModel() {
131142
}
132143
}
133144
}
145+
}
134146

135-
viewModelScope.launch {
136-
searchTerm.collect { term -> peers.set(peerCategorizer.groupedAndFilteredPeers(term)) }
137-
}
138-
139-
viewModelScope.launch {
140-
App.get().healthNotifier?.currentIcon?.collect { icon -> healthIcon.set(icon) }
141-
}
147+
viewModelScope.launch {
148+
App.get().healthNotifier?.currentIcon?.collect { icon -> healthIcon.set(icon) }
142149
}
143150
}
144151

0 commit comments

Comments
 (0)