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 3622e6ed2b..acc33ba130 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 @@ -158,7 +158,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList private val secondaryGraphs = ArrayList() private val secondaryGraphsLabel = ArrayList() - private lateinit var carbAnimation: AnimationDrawable + private var carbAnimation: AnimationDrawable? = null override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -190,9 +190,9 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList overview_bggraph?.gridLabelRenderer?.labelVerticalWidth = axisWidth overview_bggraph?.layoutParams?.height = resourceHelper.dpToPx(skinProvider.activeSkin().mainGraphHeight) - carbAnimation = overview_carbs_icon.background as AnimationDrawable - carbAnimation.setEnterFadeDuration(1200) - carbAnimation.setExitFadeDuration(1200) + carbAnimation = overview_carbs_icon?.background as AnimationDrawable? + carbAnimation?.setEnterFadeDuration(1200) + carbAnimation?.setExitFadeDuration(1200) rangeToDisplay = sp.getInt(R.string.key_rangetodisplay, 6) @@ -643,6 +643,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList overview_apsmode_text?.visibility = View.GONE } val lastRun = loopPlugin.lastRun + val predictionsAvailable = if (config.APS) lastRun?.request?.hasPredictions == true else config.NSCLIENT // temp target val tempTarget = treatmentsPlugin.tempTargetFromHistory @@ -682,9 +683,9 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList ?: resourceHelper.gc(R.color.defaulttextcolor)) if (activeTemp != null) - overview_basebasal_icon.setImageResource(if (activeTemp.tempBasalConvertedToPercent(System.currentTimeMillis(), profile) > 100) R.drawable.ic_cp_basal_tbr_high else R.drawable.ic_cp_basal_tbr_low) + overview_basebasal_icon?.setImageResource(if (activeTemp.tempBasalConvertedToPercent(System.currentTimeMillis(), profile) > 100) R.drawable.ic_cp_basal_tbr_high else R.drawable.ic_cp_basal_tbr_low) else - overview_basebasal_icon.setImageResource(R.drawable.ic_cp_basal_no_tbr) + overview_basebasal_icon?.setImageResource(R.drawable.ic_cp_basal_no_tbr) // Extended bolus val extendedBolus = treatmentsPlugin.getExtendedBolusFromHistory(System.currentTimeMillis()) @@ -750,21 +751,19 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList if (config.APS && lastRun?.constraintsProcessed != null) { if (lastRun.constraintsProcessed!!.carbsReq > 0) { //only display carbsreq when carbs havnt been entered recently - if (treatmentsPlugin.lastCarbTime < lastRun.lastAPSRun){ + if (treatmentsPlugin.lastCarbTime < lastRun.lastAPSRun) { cobText = cobText + " | " + lastRun.constraintsProcessed!!.carbsReq + " " + resourceHelper.gs(R.string.required) } overview_cob?.text = cobText - if (!carbAnimation.isRunning) - carbAnimation.start() + if (carbAnimation?.isRunning == false) + carbAnimation?.start() } else { overview_cob?.text = cobText - carbAnimation.stop() - carbAnimation.selectDrawable(0); + carbAnimation?.stop() + carbAnimation?.selectDrawable(0) } } else overview_cob?.text = cobText - val predictionsAvailable = if (config.APS) lastRun?.request?.hasPredictions == true else config.NSCLIENT - // pump status from ns overview_pump?.text = nsDeviceStatus.pumpStatus overview_pump?.setOnClickListener { activity?.let { OKDialog.show(it, resourceHelper.gs(R.string.pump), nsDeviceStatus.extendedPumpStatus) } } @@ -779,9 +778,9 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList // Sensitivity if (sp.getBoolean(R.string.key_openapsama_useautosens, false) && constraintChecker.isAutosensModeEnabled().value()) { - overview_sensitivity_icon.setImageResource(R.drawable.ic_swap_vert_black_48dp_green) + overview_sensitivity_icon?.setImageResource(R.drawable.ic_swap_vert_black_48dp_green) } else { - overview_sensitivity_icon.setImageResource(R.drawable.ic_x_swap_vert) + overview_sensitivity_icon?.setImageResource(R.drawable.ic_x_swap_vert) } overview_sensitivity?.text = 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 05dbba234c..56faab3e57 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 @@ -109,7 +109,7 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() { danar_history_spinner.adapter = ArrayAdapter(this, R.layout.spinner_centered, typeList) danar_history_reload.setOnClickListener { - val selected = danar_history_spinner.selectedItem as TypeList + val selected = danar_history_spinner.selectedItem as TypeList? ?: return@setOnClickListener runOnUiThread { danar_history_reload?.visibility = View.GONE danar_history_status?.visibility = View.VISIBLE @@ -127,7 +127,7 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() { } danar_history_spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { override fun onItemSelected(parent: AdapterView<*>?, view: View, position: Int, id: Long) { - val selected = danar_history_spinner?.selectedItem as TypeList? ?: return + val selected = typeList[position] loadDataFromDB(selected.type) showingType = selected.type }