From 027bc64f0f7bb1f4d58078744acc02cdc974ba1e Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 3 May 2020 15:04:08 +0200 Subject: [PATCH] Skins --- .../dependencyInjection/AppComponent.kt | 3 +- .../dependencyInjection/AppModule.kt | 53 ++----------------- .../dependencyInjection/SkinsModule.kt | 30 +++++++++++ .../dependencyInjection/UIModule.kt | 21 ++++++++ .../general/overview/OverviewFragment.kt | 16 ++---- .../androidaps/skins/SkinButtonsOn.kt | 20 +++++++ .../androidaps/skins/SkinClassic.kt | 21 ++++++++ .../androidaps/skins/SkinInterface.kt | 10 ++++ .../androidaps/skins/SkinListPreference.kt | 29 ++++++++++ .../androidaps/skins/SkinProvider.kt | 22 ++++++++ app/src/main/res/values/strings.xml | 4 ++ app/src/main/res/xml/pref_general.xml | 5 +- 12 files changed, 171 insertions(+), 63 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/dependencyInjection/SkinsModule.kt create mode 100644 app/src/main/java/info/nightscout/androidaps/dependencyInjection/UIModule.kt create mode 100644 app/src/main/java/info/nightscout/androidaps/skins/SkinButtonsOn.kt create mode 100644 app/src/main/java/info/nightscout/androidaps/skins/SkinClassic.kt create mode 100644 app/src/main/java/info/nightscout/androidaps/skins/SkinInterface.kt create mode 100644 app/src/main/java/info/nightscout/androidaps/skins/SkinListPreference.kt create mode 100644 app/src/main/java/info/nightscout/androidaps/skins/SkinProvider.kt diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt index 91153bd867..b843d36ecb 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt @@ -67,7 +67,8 @@ import javax.inject.Singleton PreferencesModule::class, OverviewModule::class, DataClassesModule::class, - SMSModule::class + SMSModule::class, + UIModule::class ] ) interface AppComponent : AndroidInjector { diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt index 871f88a503..7195cdc1f0 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt @@ -6,63 +6,18 @@ import dagger.Binds import dagger.Lazy import dagger.Module import dagger.Provides -import dagger.android.ContributesAndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.Config import info.nightscout.androidaps.MainApp -import info.nightscout.androidaps.data.Profile -import info.nightscout.androidaps.data.ProfileStore -import info.nightscout.androidaps.data.PumpEnactResult -import info.nightscout.androidaps.db.BgReading -import info.nightscout.androidaps.db.CareportalEvent -import info.nightscout.androidaps.db.ProfileSwitch -import info.nightscout.androidaps.db.TemporaryBasal import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLoggerProduction -import info.nightscout.androidaps.plugins.aps.loop.APSResult -import info.nightscout.androidaps.plugins.aps.openAPSAMA.DetermineBasalResultAMA -import info.nightscout.androidaps.plugins.aps.logger.LoggerCallback -import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalAdapterSMBJS -import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalResultSMB import info.nightscout.androidaps.plugins.configBuilder.PluginStore import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImplementation -import info.nightscout.androidaps.plugins.constraints.objectives.objectives.* -import info.nightscout.androidaps.plugins.general.automation.AutomationEvent -import info.nightscout.androidaps.plugins.general.automation.actions.* -import info.nightscout.androidaps.plugins.general.automation.elements.* -import info.nightscout.androidaps.plugins.general.automation.triggers.* -import info.nightscout.androidaps.plugins.general.overview.graphData.GraphData -import info.nightscout.androidaps.plugins.general.maintenance.ImportExportPrefs -import info.nightscout.androidaps.plugins.general.maintenance.formats.ClassicPrefsFormat -import info.nightscout.androidaps.plugins.general.maintenance.formats.EncryptedPrefsFormat -import info.nightscout.androidaps.plugins.general.nsclient.NSUpload -import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationWithAction -import info.nightscout.androidaps.plugins.general.smsCommunicator.AuthRequest -import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData -import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus -import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobOref1Thread -import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobThread -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkBLE -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.SendAndListen -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.SetPreamble -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RadioPacket -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RadioResponse -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.* -import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager -import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUITask -import info.nightscout.androidaps.plugins.treatments.Treatment import info.nightscout.androidaps.queue.CommandQueue -import info.nightscout.androidaps.queue.commands.* -import info.nightscout.androidaps.setupwizard.SWEventListener -import info.nightscout.androidaps.setupwizard.SWScreen -import info.nightscout.androidaps.setupwizard.elements.* -import info.nightscout.androidaps.utils.CryptoUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelperImplementation @@ -70,11 +25,13 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SPImplementation import info.nightscout.androidaps.utils.storage.FileStorage import info.nightscout.androidaps.utils.storage.Storage -import info.nightscout.androidaps.utils.wizard.BolusWizard -import info.nightscout.androidaps.utils.wizard.QuickWizardEntry import javax.inject.Singleton -@Module(includes = [AppModule.AppBindings::class, PluginsModule::class]) +@Module(includes = [ + AppModule.AppBindings::class, + PluginsModule::class, + SkinsModule::class +]) open class AppModule { @Provides diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/SkinsModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/SkinsModule.kt new file mode 100644 index 0000000000..ebd4691f38 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/SkinsModule.kt @@ -0,0 +1,30 @@ +package info.nightscout.androidaps.dependencyInjection + +import dagger.Binds +import dagger.Module +import dagger.Provides +import dagger.multibindings.IntKey +import dagger.multibindings.IntoMap +import info.nightscout.androidaps.skins.SkinButtonsOn +import info.nightscout.androidaps.skins.SkinClassic +import info.nightscout.androidaps.skins.SkinInterface +import javax.inject.Qualifier + +@Module +open class SkinsModule { + + @Provides + @Skin + @IntoMap + @IntKey(0) + fun bindsSkinClassic(skinClassic: SkinClassic): SkinInterface = skinClassic + + @Provides + @Skin + @IntoMap + @IntKey(10) + fun bindsSkinButtonsOn(skinButtonsOn: SkinButtonsOn): SkinInterface = skinButtonsOn + + @Qualifier + annotation class Skin +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/UIModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/UIModule.kt new file mode 100644 index 0000000000..50abc0b69a --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/UIModule.kt @@ -0,0 +1,21 @@ +package info.nightscout.androidaps.dependencyInjection + +import dagger.Module +import dagger.android.ContributesAndroidInjector +import info.nightscout.androidaps.plugins.aps.loop.APSResult +import info.nightscout.androidaps.plugins.aps.openAPSAMA.DetermineBasalResultAMA +import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalAdapterSMBJS +import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalResultSMB +import info.nightscout.androidaps.plugins.constraints.objectives.objectives.* +import info.nightscout.androidaps.plugins.general.overview.graphData.GraphData +import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationWithAction +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobOref1Thread +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobThread +import info.nightscout.androidaps.skins.SkinListPreference + +@Module +@Suppress("unused") +abstract class UIModule { + @ContributesAndroidInjector abstract fun skinListPreferenceInjector(): SkinListPreference +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt index 6c7e77f15f..5da208d62b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt @@ -57,6 +57,7 @@ import info.nightscout.androidaps.plugins.source.DexcomPlugin import info.nightscout.androidaps.plugins.source.XdripPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.queue.CommandQueue +import info.nightscout.androidaps.skins.SkinProvider import info.nightscout.androidaps.utils.* import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.buildHelper.BuildHelper @@ -131,6 +132,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList @Inject lateinit var protectionCheck: ProtectionCheck @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var overviewMenus: OverviewMenus + @Inject lateinit var skinProvider: SkinProvider private val disposable = CompositeDisposable() @@ -161,19 +163,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList smallHeight = screenHeight <= Constants.SMALL_HEIGHT val landscape = screenHeight < screenWidth - return when { - resourceHelper.gb(R.bool.isTablet) && Config.NSCLIENT -> - inflater.inflate(R.layout.overview_fragment_nsclient_tablet, container, false) - - Config.NSCLIENT -> - inflater.inflate(R.layout.overview_fragment_nsclient, container, false) - - smallHeight || landscape -> - inflater.inflate(R.layout.overview_fragment_landscape, container, false) - - else -> - inflater.inflate(R.layout.overview_fragment, container, false) - } + return inflater.inflate(skinProvider.activeSkin().overviewLayout(landscape, resourceHelper.gb(R.bool.isTablet), smallHeight), container, false) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { diff --git a/app/src/main/java/info/nightscout/androidaps/skins/SkinButtonsOn.kt b/app/src/main/java/info/nightscout/androidaps/skins/SkinButtonsOn.kt new file mode 100644 index 0000000000..3bc092dfc2 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/skins/SkinButtonsOn.kt @@ -0,0 +1,20 @@ +package info.nightscout.androidaps.skins + +import info.nightscout.androidaps.Config +import info.nightscout.androidaps.R +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class SkinButtonsOn @Inject constructor() : SkinInterface { + + override val description: Int get() = R.string.buttonson_desrciption + + override fun overviewLayout(isLandscape: Boolean, isTablet: Boolean, isSmallHeight: Boolean): Int = + when { + Config.NSCLIENT && isTablet -> R.layout.overview_fragment_nsclient_tablet + Config.NSCLIENT -> R.layout.overview_fragment_nsclient + else -> R.layout.overview_fragment + } + +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/skins/SkinClassic.kt b/app/src/main/java/info/nightscout/androidaps/skins/SkinClassic.kt new file mode 100644 index 0000000000..15e69e9ad9 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/skins/SkinClassic.kt @@ -0,0 +1,21 @@ +package info.nightscout.androidaps.skins + +import info.nightscout.androidaps.Config +import info.nightscout.androidaps.R +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class SkinClassic @Inject constructor(): SkinInterface { + + override val description: Int get() = R.string.classic_desrciption + + override fun overviewLayout(isLandscape: Boolean, isTablet: Boolean, isSmallHeight: Boolean): Int = + when { + Config.NSCLIENT && isTablet -> R.layout.overview_fragment_nsclient_tablet + Config.NSCLIENT -> R.layout.overview_fragment_nsclient + isSmallHeight || isLandscape -> R.layout.overview_fragment_landscape + else -> R.layout.overview_fragment + } + +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/skins/SkinInterface.kt b/app/src/main/java/info/nightscout/androidaps/skins/SkinInterface.kt new file mode 100644 index 0000000000..6a9d055a13 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/skins/SkinInterface.kt @@ -0,0 +1,10 @@ +package info.nightscout.androidaps.skins + +import androidx.annotation.LayoutRes +import androidx.annotation.StringRes + +interface SkinInterface { + @get:StringRes val description : Int + + @LayoutRes fun overviewLayout(isLandscape : Boolean, isTablet : Boolean, isSmallHeight : Boolean): Int +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/skins/SkinListPreference.kt b/app/src/main/java/info/nightscout/androidaps/skins/SkinListPreference.kt new file mode 100644 index 0000000000..977f19c268 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/skins/SkinListPreference.kt @@ -0,0 +1,29 @@ +package info.nightscout.androidaps.skins + +import android.content.Context +import android.util.AttributeSet +import androidx.preference.ListPreference +import dagger.android.HasAndroidInjector +import java.util.* +import javax.inject.Inject + +class SkinListPreference(context: Context, attrs: AttributeSet?) + : ListPreference(context, attrs) { + + @Inject lateinit var skinProvider: SkinProvider + + constructor(context: Context) : this(context, null) + + init { + (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) + val entries = Vector() + val values = Vector() + + for (skin in skinProvider.list) { + values.addElement(skin.javaClass.name) + entries.addElement(context.getString(skin.description)) + } + entryValues = values.toTypedArray() + setEntries(entries.toTypedArray()) + } +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/skins/SkinProvider.kt b/app/src/main/java/info/nightscout/androidaps/skins/SkinProvider.kt new file mode 100644 index 0000000000..5ea6a97501 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/skins/SkinProvider.kt @@ -0,0 +1,22 @@ +package info.nightscout.androidaps.skins + +import info.nightscout.androidaps.R +import info.nightscout.androidaps.dependencyInjection.SkinsModule +import info.nightscout.androidaps.utils.sharedPreferences.SP +import okhttp3.internal.toImmutableMap +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class SkinProvider @Inject constructor( + val sp: SP, + @SkinsModule.Skin val allSkins: Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards SkinInterface> +) { + + fun activeSkin(): SkinInterface = + list.firstOrNull { it.javaClass.name == sp.getString(R.string.key_skin, "") } + ?: list.first() + + val list: List + get() = allSkins.toImmutableMap().toList().sortedBy { it.first }.map { it.second } +} \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5714004be8..6313844558 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1827,4 +1827,8 @@ statuslights_copy_ns Copy NS settings (if exists)? statuslights_overview_advanced + Original skin + Buttons are always displayed on bottom of screen + skin + Skin diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index a672398b20..9ae1ff6b9a 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -20,7 +20,6 @@ android:key="@string/key_language" android:title="@string/language" /> - + + \ No newline at end of file