diff --git a/core/build.gradle b/core/build.gradle index 3a6c570b66..e5537cf13b 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -19,7 +19,9 @@ android { kotlinOptions { jvmTarget = '1.8' } - + buildFeatures { + viewBinding true + } buildTypes { release { minifyEnabled false diff --git a/dana/build.gradle b/dana/build.gradle index cdeb8d9bc3..7339a7d833 100644 --- a/dana/build.gradle +++ b/dana/build.gradle @@ -1,6 +1,5 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' android { @@ -19,7 +18,9 @@ android { kotlinOptions { jvmTarget = '1.8' } - + buildFeatures { + viewBinding true + } buildTypes { release { minifyEnabled false diff --git a/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt b/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt index ba0c110823..61e9658337 100644 --- a/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt +++ b/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt @@ -8,6 +8,7 @@ import android.view.View import android.view.ViewGroup import dagger.android.support.DaggerFragment import info.nightscout.androidaps.activities.TDDStatsActivity +import info.nightscout.androidaps.dana.databinding.DanarFragmentBinding import info.nightscout.androidaps.dialogs.ProfileViewerDialog import info.nightscout.androidaps.events.EventExtendedBolusChange import info.nightscout.androidaps.events.EventInitializationChanged @@ -32,7 +33,6 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable -import kotlinx.android.synthetic.main.danar_fragment.* import javax.inject.Inject class DanaFragment : DaggerFragment() { @@ -53,6 +53,12 @@ class DanaFragment : DaggerFragment() { private val loopHandler = Handler() private lateinit var refreshLoop: Runnable + private var _binding: DanarFragmentBinding? = null + + // This property is only valid between onCreateView and + // onDestroyView. + private val binding get() = _binding!! + init { refreshLoop = Runnable { activity?.runOnUiThread { updateGUI() } @@ -61,17 +67,18 @@ class DanaFragment : DaggerFragment() { } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { - return inflater.inflate(R.layout.danar_fragment, container, false) + savedInstanceState: Bundle?): View { + _binding = DanarFragmentBinding.inflate(inflater, container, false) + return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - dana_pumpstatus.setBackgroundColor(resourceHelper.gc(R.color.colorInitializingBorder)) + binding.danaPumpstatus.setBackgroundColor(resourceHelper.gc(R.color.colorInitializingBorder)) - danar_history.setOnClickListener { startActivity(Intent(context, info.nightscout.androidaps.dana.activities.DanaHistoryActivity::class.java)) } - danar_viewprofile.setOnClickListener { + binding.history.setOnClickListener { startActivity(Intent(context, info.nightscout.androidaps.dana.activities.DanaHistoryActivity::class.java)) } + binding.viewprofile.setOnClickListener { val profile = danaPump.createConvertedProfile()?.getDefaultProfile() ?: return@setOnClickListener val profileName = danaPump.createConvertedProfile()?.getDefaultProfileName() @@ -86,17 +93,17 @@ class DanaFragment : DaggerFragment() { pvd.arguments = args pvd.show(childFragmentManager, "ProfileViewDialog") } - danar_stats.setOnClickListener { startActivity(Intent(context, TDDStatsActivity::class.java)) } - danar_user_options.setOnClickListener { startActivity(Intent(context, info.nightscout.androidaps.dana.activities.DanaUserOptionsActivity::class.java)) } - danar_btconnection.setOnClickListener { + binding.stats.setOnClickListener { startActivity(Intent(context, TDDStatsActivity::class.java)) } + binding.userOptions.setOnClickListener { startActivity(Intent(context, info.nightscout.androidaps.dana.activities.DanaUserOptionsActivity::class.java)) } + binding.btconnection.setOnClickListener { aapsLogger.debug(LTag.PUMP, "Clicked connect to pump") danaPump.lastConnection = 0 commandQueue.readStatus("Clicked connect to pump", null) } if (activePlugin.activePump.pumpDescription.pumpType == PumpType.DanaRS) - danar_btconnection.setOnLongClickListener { + binding.btconnection.setOnLongClickListener { activity?.let { - OKDialog.showConfirmation(it, resourceHelper.gs(R.string.resetpairing), Runnable { + OKDialog.showConfirmation(it, resourceHelper.gs(R.string.resetpairing), { aapsLogger.error("USER ENTRY: Clearing pairing keys !!!") (activePlugin.activePump as DanaPumpInterface).clearPairing() }) @@ -136,19 +143,19 @@ class DanaFragment : DaggerFragment() { when { it.status == EventPumpStatusChanged.Status.CONNECTING -> @Suppress("SetTextI18n") - danar_btconnection?.text = "{fa-bluetooth-b spin} ${it.secondsElapsed}s" + binding.btconnection.text = "{fa-bluetooth-b spin} ${it.secondsElapsed}s" it.status == EventPumpStatusChanged.Status.CONNECTED -> @Suppress("SetTextI18n") - danar_btconnection?.text = "{fa-bluetooth}" + binding.btconnection.text = "{fa-bluetooth}" it.status == EventPumpStatusChanged.Status.DISCONNECTED -> @Suppress("SetTextI18n") - danar_btconnection?.text = "{fa-bluetooth-b}" + binding.btconnection.text = "{fa-bluetooth-b}" } if (it.getStatus(resourceHelper) != "") { - dana_pumpstatus?.text = it.getStatus(resourceHelper) - dana_pumpstatuslayout?.visibility = View.VISIBLE + binding.danaPumpstatus.text = it.getStatus(resourceHelper) + binding.danaPumpstatuslayout.visibility = View.VISIBLE } else { - dana_pumpstatuslayout?.visibility = View.GONE + binding.danaPumpstatuslayout.visibility = View.GONE } }, { fabricPrivacy.logException(it) }) updateGUI() @@ -164,57 +171,56 @@ class DanaFragment : DaggerFragment() { // GUI functions @Synchronized fun updateGUI() { - if (danar_dailyunits == null) return val pump = danaPump val plugin: PumpInterface = activePlugin.activePump if (pump.lastConnection != 0L) { val agoMsec = System.currentTimeMillis() - pump.lastConnection val agoMin = (agoMsec.toDouble() / 60.0 / 1000.0).toInt() - danar_lastconnection?.text = dateUtil.timeString(pump.lastConnection) + " (" + resourceHelper.gs(R.string.minago, agoMin) + ")" - warnColors.setColor(danar_lastconnection, agoMin.toDouble(), 16.0, 31.0) + binding.lastconnection.text = dateUtil.timeString(pump.lastConnection) + " (" + resourceHelper.gs(R.string.minago, agoMin) + ")" + warnColors.setColor(binding.lastconnection, agoMin.toDouble(), 16.0, 31.0) } if (pump.lastBolusTime != 0L) { val agoMsec = System.currentTimeMillis() - pump.lastBolusTime val agoHours = agoMsec.toDouble() / 60.0 / 60.0 / 1000.0 if (agoHours < 6) // max 6h back - danar_lastbolus?.text = dateUtil.timeString(pump.lastBolusTime) + " " + DateUtil.sinceString(pump.lastBolusTime, resourceHelper) + " " + resourceHelper.gs(R.string.formatinsulinunits, pump.lastBolusAmount) + binding.lastbolus.text = dateUtil.timeString(pump.lastBolusTime) + " " + DateUtil.sinceString(pump.lastBolusTime, resourceHelper) + " " + resourceHelper.gs(R.string.formatinsulinunits, pump.lastBolusAmount) else - danar_lastbolus?.text = "" + binding.lastbolus.text = "" } - danar_dailyunits?.text = resourceHelper.gs(R.string.reservoirvalue, pump.dailyTotalUnits, pump.maxDailyTotalUnits) - warnColors.setColor(danar_dailyunits, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75, pump.maxDailyTotalUnits * 0.9) - danar_basabasalrate?.text = "( " + (pump.activeProfile + 1) + " ) " + resourceHelper.gs(R.string.pump_basebasalrate, plugin.baseBasalRate) + binding.dailyunits.text = resourceHelper.gs(R.string.reservoirvalue, pump.dailyTotalUnits, pump.maxDailyTotalUnits) + warnColors.setColor(binding.dailyunits, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75, pump.maxDailyTotalUnits * 0.9) + binding.basabasalrate.text = "( " + (pump.activeProfile + 1) + " ) " + resourceHelper.gs(R.string.pump_basebasalrate, plugin.baseBasalRate) // DanaRPlugin, DanaRKoreanPlugin if (activePlugin.activePump.isFakingTempsByExtendedBoluses == true) { - danar_tempbasal?.text = activePlugin.activeTreatments.getRealTempBasalFromHistory(System.currentTimeMillis())?.toStringFull() + binding.tempbasal.text = activePlugin.activeTreatments.getRealTempBasalFromHistory(System.currentTimeMillis())?.toStringFull() ?: "" } else { // v2 plugin - danar_tempbasal?.text = activePlugin.activeTreatments.getTempBasalFromHistory(System.currentTimeMillis())?.toStringFull() + binding.tempbasal.text = activePlugin.activeTreatments.getTempBasalFromHistory(System.currentTimeMillis())?.toStringFull() ?: "" } - danar_extendedbolus?.text = activePlugin.activeTreatments.getExtendedBolusFromHistory(System.currentTimeMillis())?.toString() + binding.extendedbolus.text = activePlugin.activeTreatments.getExtendedBolusFromHistory(System.currentTimeMillis())?.toString() ?: "" - danar_reservoir?.text = resourceHelper.gs(R.string.reservoirvalue, pump.reservoirRemainingUnits, 300) - warnColors.setColorInverse(danar_reservoir, pump.reservoirRemainingUnits, 50.0, 20.0) - danar_battery?.text = "{fa-battery-" + pump.batteryRemaining / 25 + "}" - warnColors.setColorInverse(danar_battery, pump.batteryRemaining.toDouble(), 51.0, 26.0) - danar_iob?.text = resourceHelper.gs(R.string.formatinsulinunits, pump.iob) - danar_firmware?.text = resourceHelper.gs(R.string.dana_model, pump.modelFriendlyName(), pump.hwModel, pump.protocol, pump.productCode) - danar_basalstep?.text = pump.basalStep.toString() - danar_bolusstep?.text = pump.bolusStep.toString() - danar_serialnumber?.text = pump.serialNumber + binding.reservoir.text = resourceHelper.gs(R.string.reservoirvalue, pump.reservoirRemainingUnits, 300) + warnColors.setColorInverse(binding.reservoir, pump.reservoirRemainingUnits, 50.0, 20.0) + binding.battery.text = "{fa-battery-" + pump.batteryRemaining / 25 + "}" + warnColors.setColorInverse(binding.battery, pump.batteryRemaining.toDouble(), 51.0, 26.0) + binding.iob.text = resourceHelper.gs(R.string.formatinsulinunits, pump.iob) + binding.firmware.text = resourceHelper.gs(R.string.dana_model, pump.modelFriendlyName(), pump.hwModel, pump.protocol, pump.productCode) + binding.basalstep.text = pump.basalStep.toString() + binding.bolusstep.text = pump.bolusStep.toString() + binding.serialNumber.text = pump.serialNumber val status = commandQueue.spannedStatus() if (status.toString() == "") { - danar_queue?.visibility = View.GONE + binding.queue.visibility = View.GONE } else { - danar_queue?.visibility = View.VISIBLE - danar_queue?.text = status + binding.queue.visibility = View.VISIBLE + binding.queue.text = status } //hide user options button if not an RS pump or old firmware // also excludes pump with model 03 because of untested error - danar_user_options?.visibility = (pump.hwModel != 1 && pump.protocol != 0x00).toVisibility() + binding.userOptions.visibility = (pump.hwModel != 1 && pump.protocol != 0x00).toVisibility() } } diff --git a/dana/src/main/java/info/nightscout/androidaps/dana/activities/DanaHistoryActivity.kt b/dana/src/main/java/info/nightscout/androidaps/dana/activities/DanaHistoryActivity.kt index 78c2655dec..82cd99c1ab 100644 --- a/dana/src/main/java/info/nightscout/androidaps/dana/activities/DanaHistoryActivity.kt +++ b/dana/src/main/java/info/nightscout/androidaps/dana/activities/DanaHistoryActivity.kt @@ -13,8 +13,10 @@ import info.nightscout.androidaps.Constants import info.nightscout.androidaps.activities.NoSplashAppCompatActivity import info.nightscout.androidaps.dana.R import info.nightscout.androidaps.dana.comm.RecordTypes +import info.nightscout.androidaps.dana.databinding.DanarHistoryActivityBinding import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.db.DanaRHistoryRecord +import info.nightscout.androidaps.events.EventDanaRSyncStatus import info.nightscout.androidaps.events.EventPumpStatusChanged import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider @@ -24,7 +26,6 @@ import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.pump.common.defs.PumpType -import info.nightscout.androidaps.events.EventDanaRSyncStatus import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DecimalFormatter @@ -33,11 +34,11 @@ import info.nightscout.androidaps.utils.extensions.plusAssign import info.nightscout.androidaps.utils.resources.ResourceHelper import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable -import kotlinx.android.synthetic.main.danar_historyactivity.* import java.util.* import javax.inject.Inject class DanaHistoryActivity : NoSplashAppCompatActivity() { + @Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var resourceHelper: ResourceHelper @@ -54,21 +55,24 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() { private var historyList: List = ArrayList() class TypeList internal constructor(var type: Byte, var name: String) { + override fun toString(): String = name } + private lateinit var binding: DanarHistoryActivityBinding + override fun onResume() { super.onResume() disposable += rxBus .toObservable(EventPumpStatusChanged::class.java) .observeOn(AndroidSchedulers.mainThread()) - .subscribe({ danar_history_status.text = it.getStatus(resourceHelper) }) { fabricPrivacy.logException(it) } + .subscribe({ binding.status.text = it.getStatus(resourceHelper) }) { fabricPrivacy.logException(it) } disposable += rxBus .toObservable(EventDanaRSyncStatus::class.java) .observeOn(AndroidSchedulers.mainThread()) .subscribe({ aapsLogger.debug(LTag.PUMP, "EventDanaRSyncStatus: " + it.message) - danar_history_status.text = it.message + binding.status.text = it.message }) { fabricPrivacy.logException(it) } } @@ -79,12 +83,13 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.danar_historyactivity) + binding = DanarHistoryActivityBinding.inflate(layoutInflater) + setContentView(binding.root) - danar_history_recyclerview.setHasFixedSize(true) - danar_history_recyclerview.layoutManager = LinearLayoutManager(this) - danar_history_recyclerview.adapter = RecyclerViewAdapter(historyList) - danar_history_status.visibility = View.GONE + binding.recyclerview.setHasFixedSize(true) + binding.recyclerview.layoutManager = LinearLayoutManager(this) + binding.recyclerview.adapter = RecyclerViewAdapter(historyList) + binding.status.visibility = View.GONE val pump = activePlugin.activePump val isKorean = pump.pumpDescription.pumpType == PumpType.DanaRKorean @@ -106,26 +111,27 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() { typeList.add(TypeList(RecordTypes.RECORD_TYPE_REFILL, resourceHelper.gs(R.string.danar_history_refill))) typeList.add(TypeList(RecordTypes.RECORD_TYPE_SUSPEND, resourceHelper.gs(R.string.danar_history_syspend))) } - danar_history_spinner.adapter = ArrayAdapter(this, R.layout.spinner_centered, typeList) + binding.spinner.adapter = ArrayAdapter(this, R.layout.spinner_centered, typeList) - danar_history_reload.setOnClickListener { - val selected = danar_history_spinner.selectedItem as TypeList? ?: return@setOnClickListener + binding.reload.setOnClickListener { + val selected = binding.spinner.selectedItem as TypeList? + ?: return@setOnClickListener runOnUiThread { - danar_history_reload?.visibility = View.GONE - danar_history_status?.visibility = View.VISIBLE + binding.reload.visibility = View.GONE + binding.status.visibility = View.VISIBLE } clearCardView() commandQueue.loadHistory(selected.type, object : Callback() { override fun run() { loadDataFromDB(selected.type) runOnUiThread { - danar_history_reload?.visibility = View.VISIBLE - danar_history_status?.visibility = View.GONE + binding.reload.visibility = View.VISIBLE + binding.status.visibility = View.GONE } } }) } - danar_history_spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + binding.spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { val selected = typeList[position] loadDataFromDB(selected.type) @@ -139,6 +145,7 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() { } inner class RecyclerViewAdapter internal constructor(private var historyList: List) : RecyclerView.Adapter() { + override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): HistoryViewHolder = HistoryViewHolder(LayoutInflater.from(viewGroup.context).inflate(R.layout.danar_history_item, viewGroup, false)) @@ -151,7 +158,7 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() { holder.duration.text = DecimalFormatter.to0Decimal(record.recordDuration.toDouble()) holder.alarm.text = record.recordAlarm when (showingType) { - RecordTypes.RECORD_TYPE_ALARM -> { + RecordTypes.RECORD_TYPE_ALARM -> { holder.time.visibility = View.VISIBLE holder.value.visibility = View.VISIBLE holder.stringValue.visibility = View.GONE @@ -163,7 +170,7 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() { holder.alarm.visibility = View.VISIBLE } - RecordTypes.RECORD_TYPE_BOLUS -> { + RecordTypes.RECORD_TYPE_BOLUS -> { holder.time.visibility = View.VISIBLE holder.value.visibility = View.VISIBLE holder.stringValue.visibility = View.GONE @@ -175,7 +182,7 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() { holder.alarm.visibility = View.GONE } - RecordTypes.RECORD_TYPE_DAILY -> { + RecordTypes.RECORD_TYPE_DAILY -> { holder.dailyBasal.text = resourceHelper.gs(R.string.formatinsulinunits, record.recordDailyBasal) holder.dailyBolus.text = resourceHelper.gs(R.string.formatinsulinunits, record.recordDailyBolus) holder.dailyTotal.text = resourceHelper.gs(R.string.formatinsulinunits, record.recordDailyBolus + record.recordDailyBasal) @@ -191,7 +198,7 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() { holder.alarm.visibility = View.GONE } - RecordTypes.RECORD_TYPE_GLUCOSE -> { + RecordTypes.RECORD_TYPE_GLUCOSE -> { holder.value.text = Profile.toUnitsString(record.recordValue, record.recordValue * Constants.MGDL_TO_MMOLL, profileFunction.getUnits()) holder.time.visibility = View.VISIBLE holder.value.visibility = View.VISIBLE @@ -216,7 +223,7 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() { holder.alarm.visibility = View.GONE } - RecordTypes.RECORD_TYPE_SUSPEND -> { + RecordTypes.RECORD_TYPE_SUSPEND -> { holder.time.visibility = View.VISIBLE holder.value.visibility = View.GONE holder.stringValue.visibility = View.VISIBLE @@ -235,6 +242,7 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() { } inner class HistoryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + var time: TextView = itemView.findViewById(R.id.danar_history_time) var value: TextView = itemView.findViewById(R.id.danar_history_value) var bolusType: TextView = itemView.findViewById(R.id.danar_history_bolustype) @@ -249,11 +257,11 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() { private fun loadDataFromDB(type: Byte) { historyList = databaseHelper.getDanaRHistoryRecordsByType(type) - runOnUiThread { danar_history_recyclerview?.swapAdapter(RecyclerViewAdapter(historyList), false) } + runOnUiThread { binding.recyclerview.swapAdapter(RecyclerViewAdapter(historyList), false) } } private fun clearCardView() { historyList = ArrayList() - runOnUiThread { danar_history_recyclerview?.swapAdapter(RecyclerViewAdapter(historyList), false) } + runOnUiThread { binding.recyclerview.swapAdapter(RecyclerViewAdapter(historyList), false) } } } \ No newline at end of file diff --git a/dana/src/main/java/info/nightscout/androidaps/dana/activities/DanaUserOptionsActivity.kt b/dana/src/main/java/info/nightscout/androidaps/dana/activities/DanaUserOptionsActivity.kt index 03d51edf9b..ba1c16bab6 100644 --- a/dana/src/main/java/info/nightscout/androidaps/dana/activities/DanaUserOptionsActivity.kt +++ b/dana/src/main/java/info/nightscout/androidaps/dana/activities/DanaUserOptionsActivity.kt @@ -8,6 +8,7 @@ import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.activities.NoSplashAppCompatActivity import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.dana.R +import info.nightscout.androidaps.dana.databinding.DanarUserOptionsActivityBinding import info.nightscout.androidaps.events.EventInitializationChanged import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider @@ -21,7 +22,6 @@ import info.nightscout.androidaps.utils.extensions.plusAssign import info.nightscout.androidaps.utils.resources.ResourceHelper import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable -import kotlinx.android.synthetic.main.danar_user_options_activity.* import java.text.DecimalFormat import javax.inject.Inject import kotlin.math.max @@ -47,6 +47,8 @@ class DanaUserOptionsActivity : NoSplashAppCompatActivity() { var minBacklight = 1 + private lateinit var binding: DanarUserOptionsActivityBinding + @Synchronized override fun onResume() { super.onResume() @@ -64,9 +66,10 @@ class DanaUserOptionsActivity : NoSplashAppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.danar_user_options_activity) + binding = DanarUserOptionsActivityBinding.inflate(layoutInflater) + setContentView(binding.root) - save_user_options.setOnClickListener { onSaveClick() } + binding.saveUserOptions.setOnClickListener { onSaveClick() } minBacklight = if (danaPump.hwModel < 7) 1 else 0 // Dana-i allows zero @@ -80,28 +83,28 @@ class DanaUserOptionsActivity : NoSplashAppCompatActivity() { + "\npumpUnits:" + danaPump.units + "\nlowReservoir:" + danaPump.lowReservoirRate) - danar_screentimeout.setParams(danaPump.lcdOnTimeSec.toDouble(), 5.0, 240.0, 5.0, DecimalFormat("1"), false, save_user_options) - danar_backlight.setParams(danaPump.backlightOnTimeSec.toDouble(), minBacklight.toDouble(), 60.0, 1.0, DecimalFormat("1"), false, save_user_options) - danar_shutdown.setParams(danaPump.shutdownHour.toDouble(), 0.0, 24.0, 1.0, DecimalFormat("1"), true, save_user_options) - danar_lowreservoir.setParams(danaPump.lowReservoirRate.toDouble(), 10.0, 50.0, 10.0, DecimalFormat("10"), false, save_user_options) + binding.screentimeout.setParams(danaPump.lcdOnTimeSec.toDouble(), 5.0, 240.0, 5.0, DecimalFormat("1"), false, binding.saveUserOptions) + binding.backlight.setParams(danaPump.backlightOnTimeSec.toDouble(), minBacklight.toDouble(), 60.0, 1.0, DecimalFormat("1"), false, binding.saveUserOptions) + binding.shutdown.setParams(danaPump.shutdownHour.toDouble(), 0.0, 24.0, 1.0, DecimalFormat("1"), true, binding.saveUserOptions) + binding.lowreservoir.setParams(danaPump.lowReservoirRate.toDouble(), 10.0, 50.0, 10.0, DecimalFormat("10"), false, binding.saveUserOptions) when (danaPump.beepAndAlarm) { - 0b01 -> danar_pumpalarm_sound.isChecked = true - 0b10 -> danar_pumpalarm_vibrate.isChecked = true - 0b11 -> danar_pumpalarm_both.isChecked = true + 0b01 -> binding.pumpalarmSound.isChecked = true + 0b10 -> binding.pumpalarmVibrate.isChecked = true + 0b11 -> binding.pumpalarmBoth.isChecked = true 0b101 -> { - danar_pumpalarm_sound.isChecked = true - danar_beep.isChecked = true + binding.pumpalarmSound.isChecked = true + binding.beep.isChecked = true } 0b110 -> { - danar_pumpalarm_vibrate.isChecked = true - danar_beep.isChecked = true + binding.pumpalarmVibrate.isChecked = true + binding.beep.isChecked = true } 0b111 -> { - danar_pumpalarm_both.isChecked = true - danar_beep.isChecked = true + binding.pumpalarmBoth.isChecked = true + binding.beep.isChecked = true } } if (danaPump.lastSettingsRead == 0L && danaPump.hwModel < 0x05) // RS+ doesn't use lastSettingsRead @@ -112,42 +115,42 @@ class DanaUserOptionsActivity : NoSplashAppCompatActivity() { fun setData() { // in DanaRS timeDisplay values are reversed - danar_timeformat.isChecked = danaPump.timeDisplayType24 - danar_buttonscroll.isChecked = danaPump.buttonScrollOnOff - danar_beep.isChecked = danaPump.beepAndAlarm > 4 - danar_screentimeout.value = danaPump.lcdOnTimeSec.toDouble() - danar_backlight.value = danaPump.backlightOnTimeSec.toDouble() - danar_units.isChecked = danaPump.getUnits() == Constants.MMOL - danar_shutdown.value = danaPump.shutdownHour.toDouble() - danar_lowreservoir.value = danaPump.lowReservoirRate.toDouble() + binding.timeformat.isChecked = danaPump.timeDisplayType24 + binding.buttonscroll.isChecked = danaPump.buttonScrollOnOff + binding.beep.isChecked = danaPump.beepAndAlarm > 4 + binding.screentimeout.value = danaPump.lcdOnTimeSec.toDouble() + binding.backlight.value = danaPump.backlightOnTimeSec.toDouble() + binding.units.isChecked = danaPump.getUnits() == Constants.MMOL + binding.shutdown.value = danaPump.shutdownHour.toDouble() + binding.lowreservoir.value = danaPump.lowReservoirRate.toDouble() } private fun onSaveClick() { //exit if pump is not DanaRS, DanaR, or DanaR with upgraded firmware if (!isRS() && !isDanaR() && !isDanaRv2()) return - danaPump.timeDisplayType24 = danar_timeformat.isChecked + danaPump.timeDisplayType24 = binding.timeformat.isChecked - danaPump.buttonScrollOnOff = danar_buttonscroll.isChecked + danaPump.buttonScrollOnOff = binding.buttonscroll.isChecked danaPump.beepAndAlarm = when { - danar_pumpalarm_sound.isChecked -> 1 - danar_pumpalarm_vibrate.isChecked -> 2 - danar_pumpalarm_both.isChecked -> 3 - else -> 1 + binding.pumpalarmSound.isChecked -> 1 + binding.pumpalarmVibrate.isChecked -> 2 + binding.pumpalarmBoth.isChecked -> 3 + else -> 1 } - if (danar_beep.isChecked) danaPump.beepAndAlarm += 4 + if (binding.beep.isChecked) danaPump.beepAndAlarm += 4 // step is 5 seconds, 5 to 240 - danaPump.lcdOnTimeSec = min(max(danar_screentimeout.value.toInt() / 5 * 5, 5), 240) + danaPump.lcdOnTimeSec = min(max(binding.screentimeout.value.toInt() / 5 * 5, 5), 240) // 1 to 60 - danaPump.backlightOnTimeSec = min(max(danar_backlight.value.toInt(), minBacklight), 60) + danaPump.backlightOnTimeSec = min(max(binding.backlight.value.toInt(), minBacklight), 60) - danaPump.units = if (danar_units.isChecked) 1 else 0 + danaPump.units = if (binding.units.isChecked) 1 else 0 - danaPump.shutdownHour = min(danar_shutdown.value.toInt(), 24) + danaPump.shutdownHour = min(binding.shutdown.value.toInt(), 24) // 10 to 50 - danaPump.lowReservoirRate = min(max(danar_lowreservoir.value.toInt() * 10 / 10, 10), 50) + danaPump.lowReservoirRate = min(max(binding.lowreservoir.value.toInt() * 10 / 10, 10), 50) commandQueue.setUserOptions(object : Callback() { override fun run() { diff --git a/dana/src/main/res/layout/danar_fragment.xml b/dana/src/main/res/layout/danar_fragment.xml index 3eff537255..712c111c3f 100644 --- a/dana/src/main/res/layout/danar_fragment.xml +++ b/dana/src/main/res/layout/danar_fragment.xml @@ -13,7 +13,7 @@