diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.kt b/app/src/main/java/info/nightscout/androidaps/MainApp.kt index fe14807af7..020153365a 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.kt +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.kt @@ -34,7 +34,7 @@ import info.nightscout.androidaps.plugins.configBuilder.PluginStore import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerUtils import info.nightscout.androidaps.plugins.general.overview.notifications.Notification import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationStore -import info.nightscout.androidaps.plugins.general.themes.ThemeSwitcherPlugin +import info.nightscout.plugins.general.themes.ThemeSwitcherPlugin import info.nightscout.androidaps.receivers.BTReceiver import info.nightscout.androidaps.receivers.ChargingStateReceiver import info.nightscout.androidaps.receivers.KeepAliveWorker diff --git a/app/src/main/java/info/nightscout/androidaps/di/PluginsListModule.kt b/app/src/main/java/info/nightscout/androidaps/di/PluginsListModule.kt index d9c3a79014..43f1e79b08 100644 --- a/app/src/main/java/info/nightscout/androidaps/di/PluginsListModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/di/PluginsListModule.kt @@ -31,7 +31,7 @@ import info.nightscout.androidaps.plugins.general.maintenance.MaintenancePlugin import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin import info.nightscout.androidaps.plugins.general.persistentNotification.PersistentNotificationPlugin -import info.nightscout.androidaps.plugins.general.themes.ThemeSwitcherPlugin +import info.nightscout.plugins.general.themes.ThemeSwitcherPlugin import info.nightscout.androidaps.plugins.general.tidepool.TidepoolPlugin import info.nightscout.androidaps.plugins.general.wear.WearPlugin import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index d01d0e0b58..618523df4d 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -151,16 +151,4 @@ 4 - - @string/dark_theme - @string/light_theme - @string/follow_system_theme - - - - @string/value_dark_theme - @string/value_light_theme - @string/value_system_theme - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e494ff1155..2ea5624195 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -921,15 +921,6 @@ clone current profile delete current profile add new to list - - Choose dark, light, or to follow the system theme - App Color Scheme - Dark theme - Light theme - Use device theme - dark - light - system Temptarget unknown preset: %1$s Cancelling running Temp-Targets? diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/themes/ThemeSwitcherPlugin.kt b/plugins/src/main/java/info/nightscout/plugins/general/themes/ThemeSwitcherPlugin.kt similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/general/themes/ThemeSwitcherPlugin.kt rename to plugins/src/main/java/info/nightscout/plugins/general/themes/ThemeSwitcherPlugin.kt index c02ea27396..26e70af0d2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/themes/ThemeSwitcherPlugin.kt +++ b/plugins/src/main/java/info/nightscout/plugins/general/themes/ThemeSwitcherPlugin.kt @@ -1,61 +1,61 @@ -package info.nightscout.androidaps.plugins.general.themes - -import androidx.appcompat.app.AppCompatDelegate -import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM -import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES -import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO -import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R -import info.nightscout.androidaps.events.EventPreferenceChange -import info.nightscout.androidaps.events.EventThemeSwitch -import info.nightscout.androidaps.interfaces.PluginBase -import info.nightscout.androidaps.interfaces.PluginDescription -import info.nightscout.androidaps.interfaces.PluginType -import info.nightscout.shared.logging.AAPSLogger -import info.nightscout.androidaps.plugins.bus.RxBus -import info.nightscout.androidaps.interfaces.ResourceHelper -import info.nightscout.shared.sharedPreferences.SP -import io.reactivex.rxjava3.disposables.CompositeDisposable -import javax.inject.Inject -import javax.inject.Singleton - -@Singleton -class ThemeSwitcherPlugin @Inject constructor( - injector: HasAndroidInjector, - aapsLogger: AAPSLogger, - rh: ResourceHelper, - private val sp: SP, - private val rxBus: RxBus, -) : PluginBase(PluginDescription() - .mainType(PluginType.GENERAL) - .neverVisible(true) - .alwaysEnabled(true) - .showInList(false) - .pluginName(R.string.dst_plugin_name), - aapsLogger, rh, injector -) { - - private val compositeDisposable = CompositeDisposable() - - override fun onStart() { - compositeDisposable.add(rxBus.toObservable(EventPreferenceChange::class.java).subscribe { - if (it.isChanged(rh, id = R.string.key_use_dark_mode)) { - setThemeMode() - rxBus.send(EventThemeSwitch()) - } - }) - } - - fun setThemeMode() { - val mode = when (sp.getString(R.string.key_use_dark_mode, "dark")) { - sp.getString(R.string.value_dark_theme, "dark") -> MODE_NIGHT_YES - sp.getString(R.string.value_light_theme, "light") -> MODE_NIGHT_NO - else -> MODE_NIGHT_FOLLOW_SYSTEM - } - AppCompatDelegate.setDefaultNightMode(mode) - } - - override fun onStop() { - compositeDisposable.dispose() - } -} +package info.nightscout.plugins.general.themes + +import androidx.appcompat.app.AppCompatDelegate +import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM +import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO +import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.events.EventPreferenceChange +import info.nightscout.androidaps.events.EventThemeSwitch +import info.nightscout.androidaps.interfaces.PluginBase +import info.nightscout.androidaps.interfaces.PluginDescription +import info.nightscout.androidaps.interfaces.PluginType +import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.androidaps.plugins.bus.RxBus +import info.nightscout.plugins.R +import info.nightscout.shared.logging.AAPSLogger +import info.nightscout.shared.sharedPreferences.SP +import io.reactivex.rxjava3.disposables.CompositeDisposable +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class ThemeSwitcherPlugin @Inject constructor( + injector: HasAndroidInjector, + aapsLogger: AAPSLogger, + rh: ResourceHelper, + private val sp: SP, + private val rxBus: RxBus, +) : PluginBase(PluginDescription() + .mainType(PluginType.GENERAL) + .neverVisible(true) + .alwaysEnabled(true) + .showInList(false) + .pluginName(R.string.theme_switcher), + aapsLogger, rh, injector +) { + + private val compositeDisposable = CompositeDisposable() + + override fun onStart() { + compositeDisposable.add(rxBus.toObservable(EventPreferenceChange::class.java).subscribe { + if (it.isChanged(rh, id = R.string.key_use_dark_mode)) { + setThemeMode() + rxBus.send(EventThemeSwitch()) + } + }) + } + + fun setThemeMode() { + val mode = when (sp.getString(R.string.key_use_dark_mode, "dark")) { + sp.getString(R.string.value_dark_theme, "dark") -> MODE_NIGHT_YES + sp.getString(R.string.value_light_theme, "light") -> MODE_NIGHT_NO + else -> MODE_NIGHT_FOLLOW_SYSTEM + } + AppCompatDelegate.setDefaultNightMode(mode) + } + + override fun onStop() { + compositeDisposable.dispose() + } +} diff --git a/plugins/src/main/res/values/arrays.xml b/plugins/src/main/res/values/arrays.xml new file mode 100644 index 0000000000..3360615473 --- /dev/null +++ b/plugins/src/main/res/values/arrays.xml @@ -0,0 +1,15 @@ + + + + + @string/dark_theme + @string/light_theme + @string/follow_system_theme + + + @string/value_dark_theme + @string/value_light_theme + @string/value_system_theme + + + \ No newline at end of file diff --git a/plugins/src/main/res/values/strings.xml b/plugins/src/main/res/values/strings.xml index 7adbd905ad..39ab35103f 100644 --- a/plugins/src/main/res/values/strings.xml +++ b/plugins/src/main/res/values/strings.xml @@ -157,5 +157,16 @@ En Pr Fat + Theme switcher + + + Choose dark, light, or to follow the system theme + App Color Scheme + Dark theme + Light theme + Use device theme + dark + light + system \ No newline at end of file