Skip to content

Commit

Permalink
Theme and audio settings (#1172)
Browse files Browse the repository at this point in the history
* use saved app theme

* keep refreshing audio devices in settings

* Remove println

Co-Authored-By: Joe <jsarabia1247@gmail.com>
  • Loading branch information
AnonymousWalker and jsarabia authored Aug 6, 2024
1 parent 66fb59f commit c9ccf6b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
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

0 comments on commit c9ccf6b

Please sign in to comment.