From 6f22c5122ffd50b9c3ff19d91b60ec67d59b10a9 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 15 May 2023 11:13:36 +0200 Subject: [PATCH] actions: do not show labels in low-res landscape mode --- .../general/actions/ActionsFragment.kt | 32 +++++++------------ .../general/overview/OverviewFragment.kt | 2 +- .../nightscout/plugins/skins/SkinClassic.kt | 5 ++- .../nightscout/plugins/skins/SkinInterface.kt | 12 ++----- .../plugins/skins/SkinLargeDisplay.kt | 5 ++- .../nightscout/plugins/skins/SkinLowRes.kt | 14 ++++---- .../res/layout/actions_stats_fragment.xml | 4 ++- 7 files changed, 29 insertions(+), 45 deletions(-) diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/actions/ActionsFragment.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/actions/ActionsFragment.kt index 545edfee91..b6b53de968 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/actions/ActionsFragment.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/actions/ActionsFragment.kt @@ -1,9 +1,7 @@ package info.nightscout.plugins.general.actions -import android.content.Context import android.content.Intent import android.os.Bundle -import android.util.DisplayMetrics import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -59,7 +57,6 @@ class ActionsFragment : DaggerFragment() { @Inject lateinit var sp: SP @Inject lateinit var dateUtil: DateUtil @Inject lateinit var profileFunction: ProfileFunction - @Inject lateinit var ctx: Context @Inject lateinit var rh: ResourceHelper @Inject lateinit var statusLightHandler: StatusLightHandler @Inject lateinit var fabricPrivacy: FabricPrivacy @@ -78,31 +75,22 @@ class ActionsFragment : DaggerFragment() { private val pumpCustomActions = HashMap() private val pumpCustomButtons = ArrayList() - private lateinit var dm: DisplayMetrics private var _binding: ActionsFragmentBinding? = null // This property is only valid between onCreateView and onDestroyView. private val binding get() = _binding!! - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { - //check screen width - dm = DisplayMetrics() - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) { - @Suppress("DEPRECATION") - activity?.display?.getRealMetrics(dm) - } else { - @Suppress("DEPRECATION") - activity?.windowManager?.defaultDisplay?.getMetrics(dm) - } - _binding = ActionsFragmentBinding.inflate(inflater, container, false) - return binding.root - } + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View = + ActionsFragmentBinding.inflate(inflater, container, false).also { _binding = it }.root override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - skinProvider.activeSkin().preProcessLandscapeActionsLayout(dm, binding) + val screenWidth = activity?.window?.decorView?.width ?: 0 + val screenHeight = activity?.window?.decorView?.height ?: 0 + val isLandscape = screenHeight < screenWidth + skinProvider.activeSkin().preProcessLandscapeActionsLayout(isLandscape, binding) binding.profileSwitch.setOnClickListener { activity?.let { activity -> @@ -285,7 +273,7 @@ class ActionsFragment : DaggerFragment() { binding.tddStats.visibility = pump.pumpDescription.supportsTDDs.toVisibility() val isPatchPump = pump.pumpDescription.isPatchPump binding.status.apply { - cannulaOrPatch.text = if (isPatchPump) rh.gs(R.string.patch_pump) else rh.gs(R.string.cannula) + cannulaOrPatch.text = if (cannulaOrPatch.text.isEmpty()) "" else if (isPatchPump) rh.gs(R.string.patch_pump) else rh.gs(R.string.cannula) val imageResource = if (isPatchPump) info.nightscout.core.main.R.drawable.ic_patch_pump_outline else R.drawable.ic_cp_age_cannula cannulaOrPatch.setCompoundDrawablesWithIntrinsicBounds(imageResource, 0, 0, 0) batteryLayout.visibility = (!isPatchPump || pump.pumpDescription.useHardwareLink).toVisibility() @@ -293,7 +281,11 @@ class ActionsFragment : DaggerFragment() { cannulaUsage.visibility = isPatchPump.not().toVisibility() if (!config.NSCLIENT) { - statusLightHandler.updateStatusLights(cannulaAge, cannulaUsage, insulinAge, reservoirLevel, sensorAge, sensorLevel, pbAge, batteryLevel) + statusLightHandler.updateStatusLights( + cannulaAge, cannulaUsage, insulinAge, + reservoirLevel, sensorAge, sensorLevel, + pbAge, pbLevel + ) sensorLevelLabel.text = if (activeBgSource.sensorBatteryLevel == -1) "" else rh.gs(R.string.level_label) } else { statusLightHandler.updateStatusLights(cannulaAge, cannulaUsage, insulinAge, null, sensorAge, null, pbAge, null) diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/overview/OverviewFragment.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/overview/OverviewFragment.kt index 50b801c878..f59254d745 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/overview/OverviewFragment.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/overview/OverviewFragment.kt @@ -188,7 +188,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList smallHeight = screenHeight <= Constants.SMALL_HEIGHT val landscape = screenHeight < screenWidth - skinProvider.activeSkin().preProcessLandscapeOverviewLayout(dm, binding, landscape, rh.gb(info.nightscout.shared.R.bool.isTablet), smallHeight) + skinProvider.activeSkin().preProcessLandscapeOverviewLayout(binding, landscape, rh.gb(info.nightscout.shared.R.bool.isTablet), smallHeight) binding.nsclientCard.visibility = config.NSCLIENT.toVisibility() binding.notifications.setHasFixedSize(false) diff --git a/plugins/main/src/main/java/info/nightscout/plugins/skins/SkinClassic.kt b/plugins/main/src/main/java/info/nightscout/plugins/skins/SkinClassic.kt index 34b3fa3ec8..66c5e9277a 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/skins/SkinClassic.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/skins/SkinClassic.kt @@ -1,6 +1,5 @@ package info.nightscout.plugins.skins -import android.util.DisplayMetrics import info.nightscout.interfaces.Config import info.nightscout.plugins.R import info.nightscout.plugins.databinding.OverviewFragmentBinding @@ -14,8 +13,8 @@ class SkinClassic @Inject constructor(private val config: Config) : SkinInterfac override val mainGraphHeight: Int get() = 200 override val secondaryGraphHeight: Int get() = 100 - override fun preProcessLandscapeOverviewLayout(dm: DisplayMetrics, binding: OverviewFragmentBinding, isLandscape: Boolean, isTablet: Boolean, isSmallHeight: Boolean) { - super.preProcessLandscapeOverviewLayout(dm, binding, isLandscape, isTablet, isSmallHeight) + override fun preProcessLandscapeOverviewLayout(binding: OverviewFragmentBinding, isLandscape: Boolean, isTablet: Boolean, isSmallHeight: Boolean) { + super.preProcessLandscapeOverviewLayout(binding, isLandscape, isTablet, isSmallHeight) if (!config.NSCLIENT && (isSmallHeight || isLandscape)) moveButtonsLayout(binding.root) } } diff --git a/plugins/main/src/main/java/info/nightscout/plugins/skins/SkinInterface.kt b/plugins/main/src/main/java/info/nightscout/plugins/skins/SkinInterface.kt index 55259fb599..8c00941204 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/skins/SkinInterface.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/skins/SkinInterface.kt @@ -1,6 +1,5 @@ package info.nightscout.plugins.skins -import android.util.DisplayMetrics import android.util.TypedValue.COMPLEX_UNIT_PX import android.view.View import android.widget.LinearLayout @@ -18,16 +17,11 @@ interface SkinInterface { val secondaryGraphHeight: Int // in dp // no pre processing by default - fun preProcessLandscapeActionsLayout(dm: DisplayMetrics, binding: ActionsFragmentBinding) { + fun preProcessLandscapeActionsLayout(isLandscape: Boolean, binding: ActionsFragmentBinding) { } - fun preProcessLandscapeOverviewLayout(dm: DisplayMetrics, binding: OverviewFragmentBinding, isLandscape: Boolean, isTablet: Boolean, isSmallHeight: Boolean) { - // pre-process landscape mode - val screenWidth = dm.widthPixels - val screenHeight = dm.heightPixels - val landscape = screenHeight < screenWidth - - if (landscape) { + fun preProcessLandscapeOverviewLayout(binding: OverviewFragmentBinding, isLandscape: Boolean, isTablet: Boolean, isSmallHeight: Boolean) { + if (isLandscape) { val iobLayout = binding.infoLayout.iobLayout val iobLayoutParams = iobLayout.layoutParams as ConstraintLayout.LayoutParams val timeLayout = binding.infoLayout.timeLayout diff --git a/plugins/main/src/main/java/info/nightscout/plugins/skins/SkinLargeDisplay.kt b/plugins/main/src/main/java/info/nightscout/plugins/skins/SkinLargeDisplay.kt index 3ef880d299..69497bf3dd 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/skins/SkinLargeDisplay.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/skins/SkinLargeDisplay.kt @@ -1,6 +1,5 @@ package info.nightscout.plugins.skins -import android.util.DisplayMetrics import info.nightscout.interfaces.Config import info.nightscout.plugins.R import info.nightscout.plugins.databinding.OverviewFragmentBinding @@ -14,8 +13,8 @@ class SkinLargeDisplay @Inject constructor(private val config: Config) : SkinInt override val mainGraphHeight: Int get() = 400 override val secondaryGraphHeight: Int get() = 150 - override fun preProcessLandscapeOverviewLayout(dm: DisplayMetrics, binding: OverviewFragmentBinding, isLandscape: Boolean, isTablet: Boolean, isSmallHeight: Boolean) { - super.preProcessLandscapeOverviewLayout(dm, binding, isLandscape, isTablet, isSmallHeight) + override fun preProcessLandscapeOverviewLayout(binding: OverviewFragmentBinding, isLandscape: Boolean, isTablet: Boolean, isSmallHeight: Boolean) { + super.preProcessLandscapeOverviewLayout(binding, isLandscape, isTablet, isSmallHeight) if (!config.NSCLIENT && (isSmallHeight || isLandscape)) moveButtonsLayout(binding.root) } } diff --git a/plugins/main/src/main/java/info/nightscout/plugins/skins/SkinLowRes.kt b/plugins/main/src/main/java/info/nightscout/plugins/skins/SkinLowRes.kt index 4af731facf..f09f389af6 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/skins/SkinLowRes.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/skins/SkinLowRes.kt @@ -1,6 +1,5 @@ package info.nightscout.plugins.skins -import android.util.DisplayMetrics import android.view.View.GONE import android.view.ViewGroup import info.nightscout.interfaces.Config @@ -17,27 +16,26 @@ class SkinLowRes @Inject constructor(private val config: Config) : SkinInterface override val mainGraphHeight: Int get() = 200 override val secondaryGraphHeight: Int get() = 100 - override fun preProcessLandscapeActionsLayout(dm: DisplayMetrics, binding: ActionsFragmentBinding) { - val screenWidth = dm.widthPixels - val screenHeight = dm.heightPixels - val isLandscape = screenHeight < screenWidth - + override fun preProcessLandscapeActionsLayout(isLandscape: Boolean, binding: ActionsFragmentBinding) { if (!isLandscape) { binding.status.apply { - sensorAgeLabel.visibility = GONE + sensorLabel.text = "" sensorAgeLabel.visibility = GONE sensorLevelLabel.visibility = GONE insulinAgeLabel.visibility = GONE + insulinLabel.text = "" insulinLevelLabel.visibility = GONE + cannulaOrPatch.text = "" cannulaAgeLabel.visibility = GONE cannulaUsageLabel.visibility = GONE + pbLabel.text = "" pbAgeLabel.visibility = GONE pbLevelLabel.visibility = GONE } } } - override fun preProcessLandscapeOverviewLayout(dm: DisplayMetrics, binding: OverviewFragmentBinding, isLandscape: Boolean, isTablet: Boolean, isSmallHeight: Boolean) { + override fun preProcessLandscapeOverviewLayout(binding: OverviewFragmentBinding, isLandscape: Boolean, isTablet: Boolean, isSmallHeight: Boolean) { if (!config.NSCLIENT && isLandscape) moveButtonsLayout(binding.root) binding.apply { diff --git a/plugins/main/src/main/res/layout/actions_stats_fragment.xml b/plugins/main/src/main/res/layout/actions_stats_fragment.xml index 01cd378ed7..92369d4d14 100644 --- a/plugins/main/src/main/res/layout/actions_stats_fragment.xml +++ b/plugins/main/src/main/res/layout/actions_stats_fragment.xml @@ -12,6 +12,7 @@ android:focusable="true">