feat: add disabled theme switcher
This commit is contained in:
parent
5621d5e1a8
commit
0de9b705d6
6 changed files with 95 additions and 11 deletions
|
@ -29,6 +29,7 @@ import info.nightscout.androidaps.plugins.configBuilder.PluginStore
|
||||||
import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerUtils
|
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.Notification
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationStore
|
import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationStore
|
||||||
|
import info.nightscout.androidaps.plugins.general.themes.ThemeSwitcherPlugin
|
||||||
import info.nightscout.androidaps.receivers.BTReceiver
|
import info.nightscout.androidaps.receivers.BTReceiver
|
||||||
import info.nightscout.androidaps.receivers.ChargingStateReceiver
|
import info.nightscout.androidaps.receivers.ChargingStateReceiver
|
||||||
import info.nightscout.androidaps.receivers.KeepAliveReceiver.KeepAliveManager
|
import info.nightscout.androidaps.receivers.KeepAliveReceiver.KeepAliveManager
|
||||||
|
@ -74,6 +75,7 @@ class MainApp : DaggerApplication() {
|
||||||
@Inject lateinit var alarmSoundServiceHelper: AlarmSoundServiceHelper
|
@Inject lateinit var alarmSoundServiceHelper: AlarmSoundServiceHelper
|
||||||
@Inject lateinit var notificationStore: NotificationStore
|
@Inject lateinit var notificationStore: NotificationStore
|
||||||
@Inject lateinit var processLifecycleListener: ProcessLifecycleListener
|
@Inject lateinit var processLifecycleListener: ProcessLifecycleListener
|
||||||
|
@Inject lateinit var profileSwitchPlugin: ThemeSwitcherPlugin
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
@ -104,7 +106,7 @@ class MainApp : DaggerApplication() {
|
||||||
disposable += compatDBHelper.dbChangeDisposable()
|
disposable += compatDBHelper.dbChangeDisposable()
|
||||||
registerActivityLifecycleCallbacks(activityMonitor)
|
registerActivityLifecycleCallbacks(activityMonitor)
|
||||||
JodaTimeAndroid.init(this)
|
JodaTimeAndroid.init(this)
|
||||||
selectThemeMode()
|
profileSwitchPlugin.setThemeMode()
|
||||||
aapsLogger.debug("Version: " + BuildConfig.VERSION_NAME)
|
aapsLogger.debug("Version: " + BuildConfig.VERSION_NAME)
|
||||||
aapsLogger.debug("BuildVersion: " + BuildConfig.BUILDVERSION)
|
aapsLogger.debug("BuildVersion: " + BuildConfig.BUILDVERSION)
|
||||||
aapsLogger.debug("Remote: " + BuildConfig.REMOTE)
|
aapsLogger.debug("Remote: " + BuildConfig.REMOTE)
|
||||||
|
@ -125,16 +127,6 @@ class MainApp : DaggerApplication() {
|
||||||
passwordCheck.passwordResetCheck(this)
|
passwordCheck.passwordResetCheck(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun selectThemeMode() {
|
|
||||||
when(sp.getString(R.string.key_use_dark_mode, "dark")) {
|
|
||||||
sp.getString(R.string.value_dark_theme, "dark") -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
|
|
||||||
sp.getString(R.string.value_light_theme, "light") -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
|
|
||||||
else -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
|
|
||||||
}
|
|
||||||
// temp while switch is not public
|
|
||||||
setTheme(R.style.AppTheme)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setRxErrorHandler() {
|
private fun setRxErrorHandler() {
|
||||||
RxJavaPlugins.setErrorHandler { t: Throwable ->
|
RxJavaPlugins.setErrorHandler { t: Throwable ->
|
||||||
var e = t
|
var e = t
|
||||||
|
|
|
@ -32,6 +32,7 @@ import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin
|
||||||
import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin
|
import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin
|
||||||
import info.nightscout.androidaps.plugins.general.persistentNotification.PersistentNotificationPlugin
|
import info.nightscout.androidaps.plugins.general.persistentNotification.PersistentNotificationPlugin
|
||||||
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin
|
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin
|
||||||
|
import info.nightscout.androidaps.plugins.general.themes.ThemeSwitcherPlugin
|
||||||
import info.nightscout.androidaps.plugins.general.wear.WearPlugin
|
import info.nightscout.androidaps.plugins.general.wear.WearPlugin
|
||||||
import info.nightscout.androidaps.plugins.general.xdripStatusline.StatusLinePlugin
|
import info.nightscout.androidaps.plugins.general.xdripStatusline.StatusLinePlugin
|
||||||
import info.nightscout.androidaps.plugins.insulin.InsulinLyumjevPlugin
|
import info.nightscout.androidaps.plugins.insulin.InsulinLyumjevPlugin
|
||||||
|
@ -387,6 +388,12 @@ abstract class PluginsModule {
|
||||||
@IntKey(490)
|
@IntKey(490)
|
||||||
abstract fun bindConfigBuilderPlugin(plugin: ConfigBuilderPlugin): PluginBase
|
abstract fun bindConfigBuilderPlugin(plugin: ConfigBuilderPlugin): PluginBase
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
@AllConfigs
|
||||||
|
@IntoMap
|
||||||
|
@IntKey(500)
|
||||||
|
abstract fun bindThemeSwitcherPlugin(plugin: ThemeSwitcherPlugin): PluginBase
|
||||||
|
|
||||||
@Qualifier
|
@Qualifier
|
||||||
annotation class AllConfigs
|
annotation class AllConfigs
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
class EventThemeSwitch : Event()
|
|
@ -0,0 +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.utils.resources.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()
|
||||||
|
}
|
||||||
|
}
|
|
@ -147,4 +147,16 @@
|
||||||
<item>4</item>
|
<item>4</item>
|
||||||
</string-array>
|
</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>
|
</resources>
|
||||||
|
|
|
@ -101,6 +101,15 @@
|
||||||
android:key="@string/key_skin"
|
android:key="@string/key_skin"
|
||||||
android:title="@string/skin" />
|
android:title="@string/skin" />
|
||||||
|
|
||||||
|
<!-- Temp hide options till light mode is completed
|
||||||
|
<ListPreference
|
||||||
|
android:defaultValue="dark"
|
||||||
|
android:entries="@array/darkMode"
|
||||||
|
android:entryValues="@array/darkModeValues"
|
||||||
|
android:key="@string/key_use_dark_mode"
|
||||||
|
android:summary="@string/theme_switcher_summary"
|
||||||
|
android:title="@string/app_color_scheme" /> -->
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
</androidx.preference.PreferenceScreen>
|
</androidx.preference.PreferenceScreen>
|
||||||
|
|
Loading…
Reference in a new issue