Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only refreshes the list of devices when dropdown is open #1187

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ package org.wycliffeassociates.otter.jvm.workbookapp.ui.components.drawer

import io.github.palexdev.materialfx.controls.MFXProgressBar
import javafx.application.Platform
import javafx.beans.property.SimpleBooleanProperty
import javafx.collections.ObservableList
import javafx.scene.control.Button
import javafx.scene.control.ComboBox
import javafx.scene.control.ProgressBar
import javafx.scene.control.ToggleGroup
import javafx.scene.input.KeyCode
Expand All @@ -47,6 +49,8 @@ class SettingsView : View() {
orientationProperty.set(viewModel.orientationProperty.value)
}

private val outputDeviceLoadingProperty = SimpleBooleanProperty()
private val inputDeviceLoadingProperty = SimpleBooleanProperty()
private lateinit var closeButton: Button

lateinit var progressBar: ProgressBar
Expand Down Expand Up @@ -157,6 +161,8 @@ class SettingsView : View() {
progressindicator {
prefWidth = 25.0
prefHeight = 25.0

visibleWhen { outputDeviceLoadingProperty }
}
}

Expand All @@ -179,6 +185,7 @@ class SettingsView : View() {
overrideDefaultKeyEventHandler {
viewModel.updateOutputDevice(it)
}
outputDeviceLoadingProperty.bind(showingProperty())
}

hbox {
Expand All @@ -189,6 +196,8 @@ class SettingsView : View() {
progressindicator {
prefWidth = 25.0
prefHeight = 25.0

visibleWhen { inputDeviceLoadingProperty }
}
}
combobox(viewModel.selectedInputDeviceProperty, viewModel.inputDevices) {
Expand All @@ -210,6 +219,7 @@ class SettingsView : View() {
overrideDefaultKeyEventHandler {
viewModel.updateInputDevice(it)
}
inputDeviceLoadingProperty.bind(showingProperty())
}
}

Expand Down Expand Up @@ -432,6 +442,13 @@ class SettingsView : View() {
openDrawer()
}
}

outputDeviceLoadingProperty.onChangeAndDoNow {
if (it == true) viewModel.watchForNewDevices() else viewModel.cancelDeviceWatcher()
}
inputDeviceLoadingProperty.onChangeAndDoNow {
if (it == true) viewModel.watchForNewDevices() else viewModel.cancelDeviceWatcher()
}
}

override fun onDock() {
Expand Down Expand Up @@ -482,7 +499,6 @@ class SettingsView : View() {
viewModel.refreshDevices()
focusCloseButton()
resetUpdateLanguagesStatus()
viewModel.watchForNewDevices()
}

private fun collapse() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ class SettingsViewModel : ViewModel() {
loadCurrentInputDevice()
loadLanguageNamesUrl()
loadDefaultLanguageNamesUrl()
watchForNewDevices()

supportedThemes.setAll(ColorTheme.values().asList())
theme.preferredTheme
Expand Down Expand Up @@ -275,18 +274,22 @@ class SettingsViewModel : ViewModel() {
fun watchForNewDevices() {
disposableDeviceWatcher.clear()
Observable
.interval(2, 2, TimeUnit.SECONDS)
.interval(2, TimeUnit.SECONDS)
.subscribeOn(Schedulers.io())
.observeOnFx()
.subscribe {
refreshDevices()
}.addTo(disposableDeviceWatcher)
}

fun onDrawerCollapsed() {
fun cancelDeviceWatcher() {
disposableDeviceWatcher.clear()
}

fun onDrawerCollapsed() {
cancelDeviceWatcher()
}

fun updateLanguage(language: Language) {
logger.info("Selected app language: ${language.slug}")
localeLanguage.setPreferredLanguage(language)
Expand Down
Loading