From 5521122030156cb0ac044f34bca31ffcfb04511e Mon Sep 17 00:00:00 2001 From: Andries Smit Date: Fri, 11 Mar 2022 14:48:48 +0100 Subject: [PATCH 1/2] chore: use binding actions and skins --- .../general/actions/ActionsFragment.kt | 176 ++++------ .../general/overview/OverviewFragment.kt | 4 +- .../androidaps/skins/SkinButtonsOn.kt | 2 +- .../androidaps/skins/SkinClassic.kt | 9 +- .../androidaps/skins/SkinInterface.kt | 66 ++-- .../androidaps/skins/SkinLargeDisplay.kt | 9 +- .../androidaps/skins/SkinListPreference.kt | 2 +- .../nightscout/androidaps/skins/SkinLowRes.kt | 34 +- .../androidaps/skins/SkinProvider.kt | 2 +- app/src/main/res/layout/actions_fragment.xml | 36 +- .../res/layout/actions_fragment_lowres.xml | 311 ------------------ .../res/layout/careportal_stats_fragment.xml | 1 + 12 files changed, 151 insertions(+), 501 deletions(-) delete mode 100644 app/src/main/res/layout/actions_fragment_lowres.xml diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt index b42626de8d..60500b3f04 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt @@ -8,11 +8,8 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.LinearLayout -import android.widget.TableRow -import android.widget.TextView import androidx.core.content.ContextCompat import dagger.android.support.DaggerFragment -import info.nightscout.androidaps.Constants import info.nightscout.androidaps.R import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.activities.HistoryBrowseActivity @@ -21,6 +18,7 @@ import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.ValueWrapper import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Sources +import info.nightscout.androidaps.databinding.ActionsFragmentBinding import info.nightscout.androidaps.diaconn.DiaconnG8Plugin import info.nightscout.androidaps.dialogs.* import info.nightscout.androidaps.events.EventCustomActionsChanged @@ -82,83 +80,30 @@ class ActionsFragment : DaggerFragment() { private val pumpCustomActions = HashMap() private val pumpCustomButtons = ArrayList() - private var smallWidth = false - private var smallHeight = false private lateinit var dm: DisplayMetrics - private var buttonsLayout: LinearLayout? = null - private var profileSwitch: SingleClickButton? = null - private var tempTarget: SingleClickButton? = null - private var extendedBolus: SingleClickButton? = null - private var extendedBolusCancel: SingleClickButton? = null - private var setTempBasal: SingleClickButton? = null - private var cancelTempBasal: SingleClickButton? = null - private var fill: SingleClickButton? = null - private var historyBrowser: SingleClickButton? = null - private var tddStats: SingleClickButton? = null - private var pumpBatteryChange: SingleClickButton? = null + private var _binding: ActionsFragmentBinding? = null + // This property is only valid between onCreateView and onDestroyView. + private val binding get() = _binding!! - private var cannulaAge: TextView? = null - private var insulinAge: TextView? = null - private var reservoirLevel: TextView? = null - private var sensorAge: TextView? = null - private var sensorLevel: TextView? = null - private var pbAge: TextView? = null - private var batteryLevel: TextView? = null - private var sensorLevelLabel: TextView? = null - private var insulinLevelLabel: TextView? = null - private var pbLevelLabel: TextView? = null - private var cannulaOrPatch: TextView? = null - private var batteryLayout: TableRow? = null - - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { + 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) + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) { activity?.display?.getRealMetrics(dm) - else + } else { @Suppress("DEPRECATION") activity?.windowManager?.defaultDisplay?.getMetrics(dm) - - val screenWidth = dm.widthPixels - val screenHeight = dm.heightPixels - smallWidth = screenWidth <= Constants.SMALL_WIDTH - smallHeight = screenHeight <= Constants.SMALL_HEIGHT - val landscape = screenHeight < screenWidth - - return inflater.inflate(skinProvider.activeSkin().actionsLayout(landscape, smallWidth), container, false) + } + _binding = ActionsFragmentBinding.inflate(inflater, container, false) + return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - buttonsLayout = view.findViewById(R.id.action_buttons_layout) - profileSwitch = view.findViewById(R.id.actions_profileswitch) - tempTarget = view.findViewById(R.id.actions_temptarget) - extendedBolus = view.findViewById(R.id.actions_extendedbolus) - extendedBolusCancel = view.findViewById(R.id.actions_extendedbolus_cancel) - setTempBasal = view.findViewById(R.id.actions_settempbasal) - cancelTempBasal = view.findViewById(R.id.actions_canceltempbasal) - fill = view.findViewById(R.id.actions_fill) - historyBrowser = view.findViewById(R.id.actions_historybrowser) - tddStats = view.findViewById(R.id.actions_tddstats) - pumpBatteryChange = view.findViewById(R.id.actions_pumpbatterychange) - cannulaAge = view.findViewById(R.id.cannula_age) - insulinAge = view.findViewById(R.id.insulin_age) - reservoirLevel = view.findViewById(R.id.reservoir_level) - sensorAge = view.findViewById(R.id.sensor_age) - sensorLevel = view.findViewById(R.id.sensor_level) - pbAge = view.findViewById(R.id.pb_age) - batteryLevel = view.findViewById(R.id.battery_level) - sensorLevelLabel = view.findViewById(R.id.sensor_level_label) - insulinLevelLabel = view.findViewById(R.id.insulin_level_label) - pbLevelLabel = view.findViewById(R.id.pb_level_label) - cannulaOrPatch = view.findViewById(R.id.cannula_or_patch) - batteryLayout = view.findViewById(R.id.battery_layout) + skinProvider.activeSkin().preProcessLandscapeActionsLayout(dm, binding) - profileSwitch?.setOnClickListener { + binding.profileSwitch.setOnClickListener { activity?.let { activity -> protectionCheck.queryProtection( activity, @@ -166,7 +111,7 @@ class ActionsFragment : DaggerFragment() { UIRunnable { ProfileSwitchDialog().show(childFragmentManager, "ProfileSwitchDialog")}) } } - tempTarget?.setOnClickListener { + binding.tempTarget.setOnClickListener { activity?.let { activity -> protectionCheck.queryProtection( activity, @@ -174,7 +119,7 @@ class ActionsFragment : DaggerFragment() { UIRunnable { TempTargetDialog().show(childFragmentManager, "Actions") }) } } - extendedBolus?.setOnClickListener { + binding.extendedBolus.setOnClickListener { activity?.let { activity -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { OKDialog.showConfirmation( @@ -186,7 +131,7 @@ class ActionsFragment : DaggerFragment() { }) } } - extendedBolusCancel?.setOnClickListener { + binding.extendedBolusCancel.setOnClickListener { if (iobCobCalculator.getExtendedBolus(dateUtil.now()) != null) { uel.log(Action.CANCEL_EXTENDED_BOLUS, Sources.Actions) commandQueue.cancelExtended(object : Callback() { @@ -198,7 +143,7 @@ class ActionsFragment : DaggerFragment() { }) } } - setTempBasal?.setOnClickListener { + binding.setTempBasal.setOnClickListener { activity?.let { activity -> protectionCheck.queryProtection( activity, @@ -206,7 +151,7 @@ class ActionsFragment : DaggerFragment() { UIRunnable { TempBasalDialog().show(childFragmentManager, "Actions") }) } } - cancelTempBasal?.setOnClickListener { + binding.cancelTempBasal.setOnClickListener { if (iobCobCalculator.getTempBasalIncludingConvertedExtended(dateUtil.now()) != null) { uel.log(Action.CANCEL_TEMP_BASAL, Sources.Actions) commandQueue.cancelTempBasal(true, object : Callback() { @@ -218,32 +163,32 @@ class ActionsFragment : DaggerFragment() { }) } } - fill?.setOnClickListener { + binding.fill.setOnClickListener { activity?.let { activity -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { FillDialog().show(childFragmentManager, "FillDialog") }) } } - historyBrowser?.setOnClickListener { startActivity(Intent(context, HistoryBrowseActivity::class.java)) } - tddStats?.setOnClickListener { startActivity(Intent(context, TDDStatsActivity::class.java)) } - view.findViewById(R.id.actions_bgcheck).setOnClickListener { + binding.historyBrowser.setOnClickListener { startActivity(Intent(context, HistoryBrowseActivity::class.java)) } + binding.tddStats.setOnClickListener { startActivity(Intent(context, TDDStatsActivity::class.java)) } + binding.bgCheck.setOnClickListener { CareDialog().setOptions(CareDialog.EventType.BGCHECK, R.string.careportal_bgcheck).show(childFragmentManager, "Actions") } - view.findViewById(R.id.actions_cgmsensorinsert).setOnClickListener { + binding.cgmSensorInsert.setOnClickListener { CareDialog().setOptions(CareDialog.EventType.SENSOR_INSERT, R.string.careportal_cgmsensorinsert).show(childFragmentManager, "Actions") } - pumpBatteryChange?.setOnClickListener { + binding.pumpBatteryChange.setOnClickListener { CareDialog().setOptions(CareDialog.EventType.BATTERY_CHANGE, R.string.careportal_pumpbatterychange).show(childFragmentManager, "Actions") } - view.findViewById(R.id.actions_note).setOnClickListener { + binding.note.setOnClickListener { CareDialog().setOptions(CareDialog.EventType.NOTE, R.string.careportal_note).show(childFragmentManager, "Actions") } - view.findViewById(R.id.actions_exercise).setOnClickListener { + binding.exercise.setOnClickListener { CareDialog().setOptions(CareDialog.EventType.EXERCISE, R.string.careportal_exercise).show(childFragmentManager, "Actions") } - view.findViewById(R.id.actions_question).setOnClickListener { + binding.question.setOnClickListener { CareDialog().setOptions(CareDialog.EventType.QUESTION, R.string.careportal_question).show(childFragmentManager, "Actions") } - view.findViewById(R.id.actions_announcement).setOnClickListener { + binding.announcement.setOnClickListener { CareDialog().setOptions(CareDialog.EventType.ANNOUNCEMENT, R.string.careportal_announcement).show(childFragmentManager, "Actions") } @@ -282,13 +227,18 @@ class ActionsFragment : DaggerFragment() { disposable.clear() } + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } + @Synchronized fun updateGui() { val profile = profileFunction.getProfile() val pump = activePlugin.activePump - profileSwitch?.visibility = ( + binding.profileSwitch.visibility = ( activePlugin.activeProfileSource.profile != null && pump.pumpDescription.isSetBasalProfileCapable && pump.isInitialized() && @@ -296,56 +246,56 @@ class ActionsFragment : DaggerFragment() { !loop.isDisconnected).toVisibility() if (!pump.pumpDescription.isExtendedBolusCapable || !pump.isInitialized() || pump.isSuspended() || loop.isDisconnected || pump.isFakingTempsByExtendedBoluses || config.NSCLIENT) { - extendedBolus?.visibility = View.GONE - extendedBolusCancel?.visibility = View.GONE + binding.extendedBolus.visibility = View.GONE + binding.extendedBolusCancel.visibility = View.GONE } else { val activeExtendedBolus = repository.getExtendedBolusActiveAt(dateUtil.now()).blockingGet() if (activeExtendedBolus is ValueWrapper.Existing) { - extendedBolus?.visibility = View.GONE - extendedBolusCancel?.visibility = View.VISIBLE + binding.extendedBolus.visibility = View.GONE + binding.extendedBolusCancel.visibility = View.VISIBLE @Suppress("SetTextI18n") - extendedBolusCancel?.text = rh.gs(R.string.cancel) + " " + activeExtendedBolus.value.toStringMedium(dateUtil) + binding.extendedBolusCancel.text = rh.gs(R.string.cancel) + " " + activeExtendedBolus.value.toStringMedium(dateUtil) } else { - extendedBolus?.visibility = View.VISIBLE - extendedBolusCancel?.visibility = View.GONE + binding.extendedBolus.visibility = View.VISIBLE + binding.extendedBolusCancel.visibility = View.GONE } } if (!pump.pumpDescription.isTempBasalCapable || !pump.isInitialized() || pump.isSuspended() || loop.isDisconnected || config.NSCLIENT) { - setTempBasal?.visibility = View.GONE - cancelTempBasal?.visibility = View.GONE + binding.setTempBasal.visibility = View.GONE + binding.cancelTempBasal.visibility = View.GONE } else { val activeTemp = iobCobCalculator.getTempBasalIncludingConvertedExtended(System.currentTimeMillis()) if (activeTemp != null) { - setTempBasal?.visibility = View.GONE - cancelTempBasal?.visibility = View.VISIBLE + binding.setTempBasal.visibility = View.GONE + binding.cancelTempBasal.visibility = View.VISIBLE @Suppress("SetTextI18n") - cancelTempBasal?.text = rh.gs(R.string.cancel) + " " + activeTemp.toStringShort() + binding.cancelTempBasal.text = rh.gs(R.string.cancel) + " " + activeTemp.toStringShort() } else { - setTempBasal?.visibility = View.VISIBLE - cancelTempBasal?.visibility = View.GONE + binding.setTempBasal.visibility = View.VISIBLE + binding.cancelTempBasal.visibility = View.GONE } } val activeBgSource = activePlugin.activeBgSource - historyBrowser?.visibility = (profile != null).toVisibility() - fill?.visibility = (pump.pumpDescription.isRefillingCapable && pump.isInitialized() && !pump.isSuspended()).toVisibility() - pumpBatteryChange?.visibility = (pump.pumpDescription.isBatteryReplaceable || pump.isBatteryChangeLoggingEnabled()).toVisibility() - tempTarget?.visibility = (profile != null && !loop.isDisconnected).toVisibility() - tddStats?.visibility = pump.pumpDescription.supportsTDDs.toVisibility() + binding.historyBrowser.visibility = (profile != null).toVisibility() + binding.fill.visibility = (pump.pumpDescription.isRefillingCapable && pump.isInitialized() && !pump.isSuspended()).toVisibility() + binding.pumpBatteryChange.visibility = (pump.pumpDescription.isBatteryReplaceable || pump.isBatteryChangeLoggingEnabled()).toVisibility() + binding.tempTarget.visibility = (profile != null && !loop.isDisconnected).toVisibility() + binding.tddStats.visibility = pump.pumpDescription.supportsTDDs.toVisibility() val isPatchPump = pump.pumpDescription.isPatchPump - cannulaOrPatch?.text = if (isPatchPump) rh.gs(R.string.patch_pump) else rh.gs(R.string.cannula) + binding.cannulaOrPatch.text = if (isPatchPump) rh.gs(R.string.patch_pump) else rh.gs(R.string.cannula) val imageResource = if (isPatchPump) 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() + binding.cannulaOrPatch.setCompoundDrawablesWithIntrinsicBounds(imageResource, 0, 0, 0) + binding.batteryLayout.visibility = (!isPatchPump || pump.pumpDescription.useHardwareLink).toVisibility() if (!config.NSCLIENT) { - statusLightHandler.updateStatusLights(cannulaAge, insulinAge, reservoirLevel, sensorAge, sensorLevel, pbAge, batteryLevel) - sensorLevelLabel?.text = if (activeBgSource.sensorBatteryLevel == -1) "" else rh.gs(R.string.careportal_level_label) + statusLightHandler.updateStatusLights(stats.cannulaAge, stats.insulinAge, stats.reservoirLevel, stats.sensorAge, stats.sensorLevel, stats.pbAge, stats.batteryLevel) + stats.sensorLevelLabel.text = if (activeBgSource.sensorBatteryLevel == -1) "" else rh.gs(R.string.careportal_level_label) } else { - statusLightHandler.updateStatusLights(cannulaAge, insulinAge, null, sensorAge, null, pbAge, null) - sensorLevelLabel?.text = "" - insulinLevelLabel?.text = "" - pbLevelLabel?.text = "" + statusLightHandler.updateStatusLights(stats.cannulaAge, stats.insulinAge, null, stats.sensorAge, null, stats.pbAge, null) + stats.sensorLevelLabel.text = "" + stats.insulinLevelLabel.text = "" + stats.pbLevelLabel.text = "" } checkPumpCustomActions() @@ -378,7 +328,7 @@ class ActionsFragment : DaggerFragment() { val top = activity?.let { ContextCompat.getDrawable(it, customAction.iconResourceId) } btn.setCompoundDrawablesWithIntrinsicBounds(null, top, null, null) - buttonsLayout?.addView(btn) + binding.buttonsLayout.addView(btn) this.pumpCustomActions[rh.gs(customAction.name)] = customAction this.pumpCustomButtons.add(btn) @@ -386,7 +336,7 @@ class ActionsFragment : DaggerFragment() { } private fun removePumpCustomActions() { - for (customButton in pumpCustomButtons) buttonsLayout?.removeView(customButton) + for (customButton in pumpCustomButtons) binding.buttonsLayout.removeView(customButton) pumpCustomButtons.clear() } } 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 d2c0546d7f..b187005054 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 @@ -152,7 +152,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList _binding = it //check screen width dm = DisplayMetrics() - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) activity?.display?.getRealMetrics(dm) else @Suppress("DEPRECATION") activity?.windowManager?.defaultDisplay?.getMetrics(dm) @@ -168,7 +168,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList smallHeight = screenHeight <= Constants.SMALL_HEIGHT val landscape = screenHeight < screenWidth - skinProvider.activeSkin().preProcessLandscapeOverviewLayout(dm, view, landscape, rh.gb(R.bool.isTablet), smallHeight) + skinProvider.activeSkin().preProcessLandscapeOverviewLayout(dm, binding, landscape, rh.gb(R.bool.isTablet), smallHeight) binding.nsclientLayout.visibility = config.NSCLIENT.toVisibility() binding.notifications.setHasFixedSize(false) diff --git a/app/src/main/java/info/nightscout/androidaps/skins/SkinButtonsOn.kt b/app/src/main/java/info/nightscout/androidaps/skins/SkinButtonsOn.kt index 8c3595d069..aa04e0268e 100644 --- a/app/src/main/java/info/nightscout/androidaps/skins/SkinButtonsOn.kt +++ b/app/src/main/java/info/nightscout/androidaps/skins/SkinButtonsOn.kt @@ -11,4 +11,4 @@ class SkinButtonsOn @Inject constructor(private val config: Config) : SkinInterf override val description: Int get() = R.string.buttonson_description override val mainGraphHeight: Int get() = 200 override val secondaryGraphHeight: Int get() = 100 -} \ 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 index a6ae3b51b9..2513066d60 100644 --- a/app/src/main/java/info/nightscout/androidaps/skins/SkinClassic.kt +++ b/app/src/main/java/info/nightscout/androidaps/skins/SkinClassic.kt @@ -5,6 +5,7 @@ import android.view.View import android.widget.LinearLayout import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.R +import info.nightscout.androidaps.databinding.OverviewFragmentBinding import javax.inject.Inject import javax.inject.Singleton @@ -15,8 +16,8 @@ class SkinClassic @Inject constructor(private val config: Config): SkinInterface override val mainGraphHeight: Int get() = 200 override val secondaryGraphHeight: Int get() = 100 - override fun preProcessLandscapeOverviewLayout(dm: DisplayMetrics, view: View, isLandscape: Boolean, isTablet: Boolean, isSmallHeight: Boolean) { - super.preProcessLandscapeOverviewLayout(dm, view, isLandscape, isTablet, isSmallHeight) - if (!config.NSCLIENT && (isSmallHeight || isLandscape)) moveButtonsLayout(view as LinearLayout) + override fun preProcessLandscapeOverviewLayout(dm: DisplayMetrics, binding: OverviewFragmentBinding, isLandscape: Boolean, isTablet: Boolean, isSmallHeight: Boolean) { + super.preProcessLandscapeOverviewLayout(dm, binding, isLandscape, isTablet, isSmallHeight) + if (!config.NSCLIENT && (isSmallHeight || isLandscape)) moveButtonsLayout(binding.root) } -} \ 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 index 85ab6791ac..76ffbc0f75 100644 --- a/app/src/main/java/info/nightscout/androidaps/skins/SkinInterface.kt +++ b/app/src/main/java/info/nightscout/androidaps/skins/SkinInterface.kt @@ -4,11 +4,11 @@ import android.util.DisplayMetrics import android.util.TypedValue.COMPLEX_UNIT_PX import android.view.View import android.widget.LinearLayout -import android.widget.TextView -import androidx.annotation.LayoutRes import androidx.annotation.StringRes import androidx.constraintlayout.widget.ConstraintLayout import info.nightscout.androidaps.R +import info.nightscout.androidaps.databinding.ActionsFragmentBinding +import info.nightscout.androidaps.databinding.OverviewFragmentBinding interface SkinInterface { @@ -17,19 +17,19 @@ interface SkinInterface { val mainGraphHeight: Int // in dp val secondaryGraphHeight: Int // in dp - @LayoutRes - fun actionsLayout(isLandscape: Boolean, isSmallWidth: Boolean): Int = R.layout.actions_fragment + fun preProcessLandscapeActionsLayout(dm: DisplayMetrics, binding: ActionsFragmentBinding) { + } - fun preProcessLandscapeOverviewLayout(dm: DisplayMetrics, view: View, isLandscape: Boolean, isTablet: Boolean, isSmallHeight: Boolean) { + 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) { - val iobLayout = view.findViewById(R.id.iob_layout) + val iobLayout = binding.infoLayout.iobLayout val iobLayoutParams = iobLayout.layoutParams as ConstraintLayout.LayoutParams - val timeLayout = view.findViewById(R.id.time_layout) + val timeLayout = binding.infoLayout.timeLayout iobLayoutParams.startToStart = ConstraintLayout.LayoutParams.UNSET iobLayoutParams.startToEnd = timeLayout.id iobLayoutParams.topToBottom = ConstraintLayout.LayoutParams.UNSET @@ -37,43 +37,34 @@ interface SkinInterface { val timeLayoutParams = timeLayout.layoutParams as ConstraintLayout.LayoutParams timeLayoutParams.endToEnd = ConstraintLayout.LayoutParams.UNSET timeLayoutParams.endToStart = iobLayout.id - val cobLayoutParams = view.findViewById(R.id.cob_layout).layoutParams as ConstraintLayout.LayoutParams + val cobLayoutParams = binding.infoLayout.cobLayout.layoutParams as ConstraintLayout.LayoutParams cobLayoutParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID - val basalLayoutParams = view.findViewById(R.id.basal_layout).layoutParams as ConstraintLayout.LayoutParams + val basalLayoutParams = binding.infoLayout.basalLayout.layoutParams as ConstraintLayout.LayoutParams basalLayoutParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID - val extendedLayoutParams = view.findViewById(R.id.extended_layout).layoutParams as ConstraintLayout.LayoutParams + val extendedLayoutParams = binding.infoLayout.extendedLayout.layoutParams as ConstraintLayout.LayoutParams extendedLayoutParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID - val asLayoutParams = view.findViewById(R.id.as_layout).layoutParams as ConstraintLayout.LayoutParams + val asLayoutParams = binding.infoLayout.asLayout.layoutParams as ConstraintLayout.LayoutParams asLayoutParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID if (isTablet) { - for (v in listOf( - view.findViewById(R.id.bg), - view.findViewById(R.id.time), - view.findViewById(R.id.time_ago_short), - view.findViewById(R.id.iob), - view.findViewById(R.id.cob), - view.findViewById(R.id.base_basal), - view.findViewById(R.id.extended_bolus), - view.findViewById(R.id.sensitivity) - )) v?.setTextSize(COMPLEX_UNIT_PX, v.textSize * 1.5f) - for (v in listOf( - view.findViewById(R.id.pump), - view.findViewById(R.id.openaps), - view.findViewById(R.id.uploader), - view.findViewById(R.id.cannula_age), - view.findViewById(R.id.insulin_age), - view.findViewById(R.id.reservoir_level), - view.findViewById(R.id.sensor_age), - view.findViewById(R.id.pb_age), - view.findViewById(R.id.battery_level) - )) v?.setTextSize(COMPLEX_UNIT_PX, v.textSize * 1.3f) - timeLayout?.orientation = LinearLayout.HORIZONTAL - view.findViewById(R.id.time_ago_short)?.setTextSize(COMPLEX_UNIT_PX, view.findViewById(R.id.time).textSize) + binding.infoLayout.apply { + val texts = listOf(bg, time, timeAgoShort, iob, cob, baseBasal, extendedBolus, sensitivity) + for (v in texts) v.setTextSize(COMPLEX_UNIT_PX, v.textSize * 1.5f) + } + binding.apply { + val texts = listOf(pump, openaps, uploader) + for (v in texts) v.setTextSize(COMPLEX_UNIT_PX, v.textSize * 1.3f) + } + binding.statusLightsLayout.apply { + val texts = listOf(cannulaAge, insulinAge, reservoirLevel, sensorAge, pbAge, batteryLevel) + for (v in texts) v.setTextSize(COMPLEX_UNIT_PX, v.textSize * 1.3f) + } + timeLayout.orientation = LinearLayout.HORIZONTAL + binding.infoLayout.timeAgoShort.setTextSize(COMPLEX_UNIT_PX, binding.infoLayout.time.textSize) - view.findViewById(R.id.delta_large)?.visibility = View.VISIBLE + binding.infoLayout.deltaLarge.visibility = View.VISIBLE } else { - view.findViewById(R.id.delta_large)?.visibility = View.GONE + binding.infoLayout.deltaLarge.visibility = View.GONE } } } @@ -84,4 +75,5 @@ interface SkinInterface { val innerLayout = root.findViewById(R.id.inner_layout) innerLayout.addView(buttonsLayout) } -} \ No newline at end of file + +} diff --git a/app/src/main/java/info/nightscout/androidaps/skins/SkinLargeDisplay.kt b/app/src/main/java/info/nightscout/androidaps/skins/SkinLargeDisplay.kt index 751e0b3ad0..73b49bf9bb 100644 --- a/app/src/main/java/info/nightscout/androidaps/skins/SkinLargeDisplay.kt +++ b/app/src/main/java/info/nightscout/androidaps/skins/SkinLargeDisplay.kt @@ -5,6 +5,7 @@ import android.view.View import android.widget.LinearLayout import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.R +import info.nightscout.androidaps.databinding.OverviewFragmentBinding import javax.inject.Inject import javax.inject.Singleton @@ -15,8 +16,8 @@ class SkinLargeDisplay @Inject constructor(private val config: Config): SkinInte override val mainGraphHeight: Int get() = 400 override val secondaryGraphHeight: Int get() = 150 - override fun preProcessLandscapeOverviewLayout(dm: DisplayMetrics, view: View, isLandscape: Boolean, isTablet: Boolean, isSmallHeight: Boolean) { - super.preProcessLandscapeOverviewLayout(dm, view, isLandscape, isTablet, isSmallHeight) - if (!config.NSCLIENT && (isSmallHeight || isLandscape)) moveButtonsLayout(view as LinearLayout) + override fun preProcessLandscapeOverviewLayout(dm: DisplayMetrics, binding: OverviewFragmentBinding, isLandscape: Boolean, isTablet: Boolean, isSmallHeight: Boolean) { + super.preProcessLandscapeOverviewLayout(dm, binding, isLandscape, isTablet, isSmallHeight) + if (!config.NSCLIENT && (isSmallHeight || isLandscape)) moveButtonsLayout(binding.root) } -} \ 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 index 977f19c268..51b546ce71 100644 --- a/app/src/main/java/info/nightscout/androidaps/skins/SkinListPreference.kt +++ b/app/src/main/java/info/nightscout/androidaps/skins/SkinListPreference.kt @@ -26,4 +26,4 @@ class SkinListPreference(context: Context, attrs: AttributeSet?) entryValues = values.toTypedArray() setEntries(entries.toTypedArray()) } -} \ No newline at end of file +} diff --git a/app/src/main/java/info/nightscout/androidaps/skins/SkinLowRes.kt b/app/src/main/java/info/nightscout/androidaps/skins/SkinLowRes.kt index c4384db93b..a875f9c812 100644 --- a/app/src/main/java/info/nightscout/androidaps/skins/SkinLowRes.kt +++ b/app/src/main/java/info/nightscout/androidaps/skins/SkinLowRes.kt @@ -1,10 +1,11 @@ package info.nightscout.androidaps.skins import android.util.DisplayMetrics -import android.view.View -import android.widget.LinearLayout +import android.view.View.GONE import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.R +import info.nightscout.androidaps.databinding.ActionsFragmentBinding +import info.nightscout.androidaps.databinding.OverviewFragmentBinding import javax.inject.Inject import javax.inject.Singleton @@ -15,13 +16,28 @@ class SkinLowRes @Inject constructor(private val config: Config) : SkinInterface override val mainGraphHeight: Int get() = 200 override val secondaryGraphHeight: Int get() = 100 - override fun actionsLayout(isLandscape: Boolean, isSmallWidth: Boolean): Int = - when { - isLandscape -> R.layout.actions_fragment - else -> R.layout.actions_fragment_lowres - } + override fun preProcessLandscapeActionsLayout(dm: DisplayMetrics, binding: ActionsFragmentBinding) { + val screenWidth = dm.widthPixels + val screenHeight = dm.heightPixels + val isLandscape = screenHeight < screenWidth - override fun preProcessLandscapeOverviewLayout(dm: DisplayMetrics, view: View, isLandscape: Boolean, isTablet: Boolean, isSmallHeight: Boolean) { - if (!config.NSCLIENT && isLandscape) moveButtonsLayout(view as LinearLayout) + if (!isLandscape) { + binding.stats.apply { + sensorAgeLabel.visibility = GONE + sensorAgeLabel.visibility = GONE + sensorLevelLabel.visibility = GONE + insulinAgeLabel.visibility = GONE + insulinLevelLabel.visibility = GONE + cannulaAgeLabel.visibility = GONE + cannulaPlaceholder.visibility = GONE + pbAgeLabel.visibility = GONE + pbLevelLabel.visibility = GONE + } + } } + + override fun preProcessLandscapeOverviewLayout(dm: DisplayMetrics, binding: OverviewFragmentBinding, isLandscape: Boolean, isTablet: Boolean, isSmallHeight: Boolean) { + if (!config.NSCLIENT && isLandscape) moveButtonsLayout(binding.root) + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/skins/SkinProvider.kt b/app/src/main/java/info/nightscout/androidaps/skins/SkinProvider.kt index a119f102a8..b9d51adcda 100644 --- a/app/src/main/java/info/nightscout/androidaps/skins/SkinProvider.kt +++ b/app/src/main/java/info/nightscout/androidaps/skins/SkinProvider.kt @@ -19,4 +19,4 @@ class SkinProvider @Inject constructor( 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/layout/actions_fragment.xml b/app/src/main/res/layout/actions_fragment.xml index 9e2810b77b..3272362088 100644 --- a/app/src/main/res/layout/actions_fragment.xml +++ b/app/src/main/res/layout/actions_fragment.xml @@ -6,7 +6,7 @@ tools:context=".plugins.general.actions.ActionsFragment"> @@ -26,7 +26,7 @@ app:columnCount="2"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/careportal_stats_fragment.xml b/app/src/main/res/layout/careportal_stats_fragment.xml index 0e82a5345e..13725255d8 100644 --- a/app/src/main/res/layout/careportal_stats_fragment.xml +++ b/app/src/main/res/layout/careportal_stats_fragment.xml @@ -192,6 +192,7 @@ android:textSize="14sp" /> Date: Sun, 13 Mar 2022 13:36:55 +0100 Subject: [PATCH 2/2] chore: fix typo --- .../general/actions/ActionsFragment.kt | 28 +++++++++---------- .../nightscout/androidaps/skins/SkinLowRes.kt | 2 +- app/src/main/res/layout/actions_fragment.xml | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt index 60500b3f04..9ef905195d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt @@ -19,7 +19,6 @@ import info.nightscout.androidaps.database.ValueWrapper import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Sources import info.nightscout.androidaps.databinding.ActionsFragmentBinding -import info.nightscout.androidaps.diaconn.DiaconnG8Plugin import info.nightscout.androidaps.dialogs.* import info.nightscout.androidaps.events.EventCustomActionsChanged import info.nightscout.androidaps.events.EventExtendedBolusChange @@ -35,7 +34,6 @@ import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction import info.nightscout.androidaps.plugins.general.overview.StatusLightHandler -import info.nightscout.androidaps.plugins.pump.omnipod.eros.OmnipodErosPumpPlugin import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.skins.SkinProvider import info.nightscout.androidaps.utils.DateUtil @@ -283,19 +281,21 @@ class ActionsFragment : DaggerFragment() { binding.tempTarget.visibility = (profile != null && !loop.isDisconnected).toVisibility() binding.tddStats.visibility = pump.pumpDescription.supportsTDDs.toVisibility() val isPatchPump = pump.pumpDescription.isPatchPump - binding.cannulaOrPatch.text = if (isPatchPump) rh.gs(R.string.patch_pump) else rh.gs(R.string.cannula) - val imageResource = if (isPatchPump) R.drawable.ic_patch_pump_outline else R.drawable.ic_cp_age_cannula - binding.cannulaOrPatch.setCompoundDrawablesWithIntrinsicBounds(imageResource, 0, 0, 0) - binding.batteryLayout.visibility = (!isPatchPump || pump.pumpDescription.useHardwareLink).toVisibility() + binding.status.apply { + cannulaOrPatch.text = if (isPatchPump) rh.gs(R.string.patch_pump) else rh.gs(R.string.cannula) + val imageResource = if (isPatchPump) 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() - if (!config.NSCLIENT) { - statusLightHandler.updateStatusLights(stats.cannulaAge, stats.insulinAge, stats.reservoirLevel, stats.sensorAge, stats.sensorLevel, stats.pbAge, stats.batteryLevel) - stats.sensorLevelLabel.text = if (activeBgSource.sensorBatteryLevel == -1) "" else rh.gs(R.string.careportal_level_label) - } else { - statusLightHandler.updateStatusLights(stats.cannulaAge, stats.insulinAge, null, stats.sensorAge, null, stats.pbAge, null) - stats.sensorLevelLabel.text = "" - stats.insulinLevelLabel.text = "" - stats.pbLevelLabel.text = "" + if (!config.NSCLIENT) { + statusLightHandler.updateStatusLights(cannulaAge, insulinAge, reservoirLevel, sensorAge, sensorLevel, pbAge, batteryLevel) + sensorLevelLabel.text = if (activeBgSource.sensorBatteryLevel == -1) "" else rh.gs(R.string.careportal_level_label) + } else { + statusLightHandler.updateStatusLights(cannulaAge, insulinAge, null, sensorAge, null, pbAge, null) + sensorLevelLabel.text = "" + insulinLevelLabel.text = "" + pbLevelLabel.text = "" + } } checkPumpCustomActions() diff --git a/app/src/main/java/info/nightscout/androidaps/skins/SkinLowRes.kt b/app/src/main/java/info/nightscout/androidaps/skins/SkinLowRes.kt index a875f9c812..45ba680275 100644 --- a/app/src/main/java/info/nightscout/androidaps/skins/SkinLowRes.kt +++ b/app/src/main/java/info/nightscout/androidaps/skins/SkinLowRes.kt @@ -22,7 +22,7 @@ class SkinLowRes @Inject constructor(private val config: Config) : SkinInterface val isLandscape = screenHeight < screenWidth if (!isLandscape) { - binding.stats.apply { + binding.status.apply { sensorAgeLabel.visibility = GONE sensorAgeLabel.visibility = GONE sensorLevelLabel.visibility = GONE diff --git a/app/src/main/res/layout/actions_fragment.xml b/app/src/main/res/layout/actions_fragment.xml index 3272362088..e8362b0524 100644 --- a/app/src/main/res/layout/actions_fragment.xml +++ b/app/src/main/res/layout/actions_fragment.xml @@ -127,7 +127,7 @@ android:text="@string/careportal" />