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

Theme and audio settings #1172

Merged
merged 3 commits into from
Aug 6, 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 @@ -27,10 +27,8 @@ import javax.inject.Inject
class AppTheme @Inject constructor(
private val appPrefRepo: IAppPreferencesRepository
) {
val preferredTheme: Single<ColorTheme> = Single.just(ColorTheme.LIGHT)
/* TODO: uncomment the line below when dark mode is supported:
* // get() = preferredTheme()
*/
val preferredTheme: Single<ColorTheme>
get() = preferredTheme()

private fun preferredTheme(): Single<ColorTheme> {
return appPrefRepo.appTheme()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,15 @@ class SettingsView : View() {
vbox {
addClass("app-drawer__section")

label(messages["playbackSettings"]).apply {
addClass("app-drawer__subtitle--small")
hbox {
spacing = 10.0
label(messages["playbackSettings"]).apply {
addClass("app-drawer__subtitle--small")
}
progressindicator {
prefWidth = 25.0
prefHeight = 25.0
}
}

combobox(viewModel.selectedOutputDeviceProperty, viewModel.outputDevices) {
Expand All @@ -174,8 +181,15 @@ class SettingsView : View() {
}
}

label(messages["recordSettings"]).apply {
addClass("app-drawer__subtitle--small")
hbox {
spacing = 10.0
label(messages["recordSettings"]).apply {
addClass("app-drawer__subtitle--small")
}
progressindicator {
prefWidth = 25.0
prefHeight = 25.0
}
}
combobox(viewModel.selectedInputDeviceProperty, viewModel.inputDevices) {
addClass("wa-combobox")
Expand Down Expand Up @@ -415,9 +429,7 @@ class SettingsView : View() {
// Devices are refreshed on dock and on drawer event otherwise it is not loaded the first time.
subscribe<DrawerEvent<UIComponent>> {
if (it.action == DrawerEventAction.OPEN) {
viewModel.refreshDevices()
focusCloseButton()
resetUpdateLanguagesStatus()
openDrawer()
}
}
}
Expand Down Expand Up @@ -466,8 +478,16 @@ class SettingsView : View() {
}
}

private fun openDrawer() {
viewModel.refreshDevices()
focusCloseButton()
resetUpdateLanguagesStatus()
viewModel.watchForNewDevices()
}

private fun collapse() {
fire(DrawerEvent(this::class, DrawerEventAction.CLOSE))
viewModel.onDrawerCollapsed()
}

private fun initChangeLanguageDialog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ package org.wycliffeassociates.otter.jvm.workbookapp.ui.viewmodel

import com.github.thomasnield.rxkotlinfx.observeOnFx
import com.jthemedetecor.OsThemeDetector
import io.reactivex.Observable
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.addTo
import io.reactivex.schedulers.Schedulers
import javafx.beans.property.SimpleBooleanProperty
import javafx.beans.property.SimpleObjectProperty
Expand All @@ -41,6 +44,7 @@ import org.wycliffeassociates.otter.jvm.device.audio.AudioDeviceProvider
import org.wycliffeassociates.otter.jvm.workbookapp.di.IDependencyGraphProvider
import org.wycliffeassociates.otter.jvm.workbookapp.ui.components.drawer.ThemeColorEvent
import tornadofx.*
import java.util.concurrent.TimeUnit
import javax.inject.Inject

class SettingsViewModel : ViewModel() {
Expand Down Expand Up @@ -80,6 +84,7 @@ class SettingsViewModel : ViewModel() {
val appColorMode = SimpleObjectProperty<ColorTheme>()
private val osThemeDetector = OsThemeDetector.getDetector()
private val isOSDarkMode = SimpleBooleanProperty(osThemeDetector.isDark)
private val disposableDeviceWatcher = CompositeDisposable()

val orientationProperty = SimpleObjectProperty<NodeOrientation>()
val orientationScaleProperty = orientationProperty.doubleBinding {
Expand Down Expand Up @@ -125,6 +130,7 @@ class SettingsViewModel : ViewModel() {
loadCurrentInputDevice()
loadLanguageNamesUrl()
loadDefaultLanguageNamesUrl()
watchForNewDevices()

supportedThemes.setAll(ColorTheme.values().asList())
theme.preferredTheme
Expand Down Expand Up @@ -259,6 +265,21 @@ class SettingsViewModel : ViewModel() {
loadCurrentInputDevice()
}

fun watchForNewDevices() {
disposableDeviceWatcher.clear()
Observable
.interval(2, 2, TimeUnit.SECONDS)
.subscribeOn(Schedulers.io())
.observeOnFx()
.subscribe {
refreshDevices()
}.addTo(disposableDeviceWatcher)
}

fun onDrawerCollapsed() {
disposableDeviceWatcher.clear()
}

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