ThemeSwitcherPlugin -> plugins module
This commit is contained in:
parent
139e788e6e
commit
683f87cd15
7 changed files with 89 additions and 84 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -151,16 +151,4 @@
|
|||
<item>4</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="darkMode">
|
||||
<item>@string/dark_theme</item>
|
||||
<item>@string/light_theme</item>
|
||||
<item>@string/follow_system_theme</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="darkModeValues">
|
||||
<item>@string/value_dark_theme</item>
|
||||
<item>@string/value_light_theme</item>
|
||||
<item>@string/value_system_theme</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -921,15 +921,6 @@
|
|||
<string name="a11y_clone_profile">clone current profile</string>
|
||||
<string name="a11y_delete_current_profile">delete current profile</string>
|
||||
<string name="a11y_add_new_to_list">add new to list</string>
|
||||
<!-- Theme switcher dark and light mode-->
|
||||
<string name="theme_switcher_summary">Choose dark, light, or to follow the system theme</string>
|
||||
<string name="app_color_scheme">App Color Scheme</string>
|
||||
<string name="dark_theme">Dark theme</string>
|
||||
<string name="light_theme">Light theme</string>
|
||||
<string name="follow_system_theme">Use device theme</string>
|
||||
<string name="value_dark_theme" translatable="false">dark</string>
|
||||
<string name="value_light_theme" translatable="false">light</string>
|
||||
<string name="value_system_theme" translatable="false">system</string>
|
||||
<!-- WEAR OS-->
|
||||
<string name="wear_action_tempt_preset_error">Temptarget unknown preset: %1$s</string>
|
||||
<string name="wear_action_tempt_cancel_message">Cancelling running Temp-Targets?</string>
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
15
plugins/src/main/res/values/arrays.xml
Normal file
15
plugins/src/main/res/values/arrays.xml
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- Theme switcher dark and light mode-->
|
||||
<string-array name="darkMode">
|
||||
<item>@string/dark_theme</item>
|
||||
<item>@string/light_theme</item>
|
||||
<item>@string/follow_system_theme</item>
|
||||
</string-array>
|
||||
<string-array name="darkModeValues">
|
||||
<item>@string/value_dark_theme</item>
|
||||
<item>@string/value_light_theme</item>
|
||||
<item>@string/value_system_theme</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
|
@ -157,5 +157,16 @@
|
|||
<string name="shortenergy">En</string>
|
||||
<string name="shortprotein">Pr</string>
|
||||
<string name="shortfat">Fat</string>
|
||||
<string name="theme_switcher">Theme switcher</string>
|
||||
|
||||
<!-- Theme switcher dark and light mode-->
|
||||
<string name="theme_switcher_summary">Choose dark, light, or to follow the system theme</string>
|
||||
<string name="app_color_scheme">App Color Scheme</string>
|
||||
<string name="dark_theme">Dark theme</string>
|
||||
<string name="light_theme">Light theme</string>
|
||||
<string name="follow_system_theme">Use device theme</string>
|
||||
<string name="value_dark_theme" translatable="false">dark</string>
|
||||
<string name="value_light_theme" translatable="false">light</string>
|
||||
<string name="value_system_theme" translatable="false">system</string>
|
||||
|
||||
</resources>
|
Loading…
Reference in a new issue