CareDialog -> jetpack
This commit is contained in:
parent
bcc573202c
commit
d376ee2229
4 changed files with 69 additions and 52 deletions
|
@ -13,6 +13,7 @@ import info.nightscout.androidaps.Constants
|
||||||
import info.nightscout.androidaps.MainApp
|
import info.nightscout.androidaps.MainApp
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.data.Profile
|
import info.nightscout.androidaps.data.Profile
|
||||||
|
import info.nightscout.androidaps.databinding.DialogCareBinding
|
||||||
import info.nightscout.androidaps.db.CareportalEvent
|
import info.nightscout.androidaps.db.CareportalEvent
|
||||||
import info.nightscout.androidaps.db.Source
|
import info.nightscout.androidaps.db.Source
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
|
@ -23,15 +24,13 @@ import info.nightscout.androidaps.utils.HtmlHelper
|
||||||
import info.nightscout.androidaps.utils.Translator
|
import info.nightscout.androidaps.utils.Translator
|
||||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import kotlinx.android.synthetic.main.dialog_care.*
|
|
||||||
import kotlinx.android.synthetic.main.notes.*
|
|
||||||
import kotlinx.android.synthetic.main.okcancel.*
|
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class CareDialog : DialogFragmentWithDate() {
|
class CareDialog : DialogFragmentWithDate() {
|
||||||
|
|
||||||
@Inject lateinit var injector: HasAndroidInjector
|
@Inject lateinit var injector: HasAndroidInjector
|
||||||
@Inject lateinit var mainApp: MainApp
|
@Inject lateinit var mainApp: MainApp
|
||||||
@Inject lateinit var resourceHelper: ResourceHelper
|
@Inject lateinit var resourceHelper: ResourceHelper
|
||||||
|
@ -60,18 +59,25 @@ class CareDialog : DialogFragmentWithDate() {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var _binding: DialogCareBinding? = null
|
||||||
|
|
||||||
|
// This property is only valid between onCreateView and
|
||||||
|
// onDestroyView.
|
||||||
|
private val binding get() = _binding!!
|
||||||
|
|
||||||
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
||||||
super.onSaveInstanceState(savedInstanceState)
|
super.onSaveInstanceState(savedInstanceState)
|
||||||
savedInstanceState.putDouble("actions_care_bg", actions_care_bg.value)
|
savedInstanceState.putDouble("bg", binding.bg.value)
|
||||||
savedInstanceState.putDouble("actions_care_duration", actions_care_duration.value)
|
savedInstanceState.putDouble("duration", binding.duration.value)
|
||||||
savedInstanceState.putInt("event", event)
|
savedInstanceState.putInt("event", event)
|
||||||
savedInstanceState.putInt("options", options.ordinal)
|
savedInstanceState.putInt("options", options.ordinal)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?): View? {
|
savedInstanceState: Bundle?): View {
|
||||||
onCreateViewGeneral()
|
onCreateViewGeneral()
|
||||||
return inflater.inflate(R.layout.dialog_care, container, false)
|
_binding = DialogCareBinding.inflate(inflater, container, false)
|
||||||
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
@ -82,7 +88,7 @@ class CareDialog : DialogFragmentWithDate() {
|
||||||
options = EventType.values()[savedInstanceState.getInt("options", 0)]
|
options = EventType.values()[savedInstanceState.getInt("options", 0)]
|
||||||
}
|
}
|
||||||
|
|
||||||
actions_care_icon.setImageResource(when (options) {
|
binding.icon.setImageResource(when (options) {
|
||||||
EventType.BGCHECK -> R.drawable.ic_cp_bgcheck
|
EventType.BGCHECK -> R.drawable.ic_cp_bgcheck
|
||||||
EventType.SENSOR_INSERT -> R.drawable.ic_cp_cgm_insert
|
EventType.SENSOR_INSERT -> R.drawable.ic_cp_cgm_insert
|
||||||
EventType.BATTERY_CHANGE -> R.drawable.ic_cp_pump_battery
|
EventType.BATTERY_CHANGE -> R.drawable.ic_cp_pump_battery
|
||||||
|
@ -91,7 +97,7 @@ class CareDialog : DialogFragmentWithDate() {
|
||||||
EventType.QUESTION -> R.drawable.ic_cp_question
|
EventType.QUESTION -> R.drawable.ic_cp_question
|
||||||
EventType.ANNOUNCEMENT -> R.drawable.ic_cp_announcement
|
EventType.ANNOUNCEMENT -> R.drawable.ic_cp_announcement
|
||||||
})
|
})
|
||||||
actions_care_title.text = resourceHelper.gs(when (options) {
|
binding.title.text = resourceHelper.gs(when (options) {
|
||||||
EventType.BGCHECK -> R.string.careportal_bgcheck
|
EventType.BGCHECK -> R.string.careportal_bgcheck
|
||||||
EventType.SENSOR_INSERT -> R.string.careportal_cgmsensorinsert
|
EventType.SENSOR_INSERT -> R.string.careportal_cgmsensorinsert
|
||||||
EventType.BATTERY_CHANGE -> R.string.careportal_pumpbatterychange
|
EventType.BATTERY_CHANGE -> R.string.careportal_pumpbatterychange
|
||||||
|
@ -104,21 +110,21 @@ class CareDialog : DialogFragmentWithDate() {
|
||||||
when (options) {
|
when (options) {
|
||||||
EventType.QUESTION,
|
EventType.QUESTION,
|
||||||
EventType.ANNOUNCEMENT,
|
EventType.ANNOUNCEMENT,
|
||||||
EventType.BGCHECK -> {
|
EventType.BGCHECK -> {
|
||||||
action_care_duration_layout.visibility = View.GONE
|
binding.durationLayout.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
EventType.SENSOR_INSERT,
|
EventType.SENSOR_INSERT,
|
||||||
EventType.BATTERY_CHANGE -> {
|
EventType.BATTERY_CHANGE -> {
|
||||||
action_care_bg_layout.visibility = View.GONE
|
binding.bgLayout.visibility = View.GONE
|
||||||
actions_care_bgsource.visibility = View.GONE
|
binding.bgsource.visibility = View.GONE
|
||||||
action_care_duration_layout.visibility = View.GONE
|
binding.durationLayout.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
EventType.NOTE,
|
EventType.NOTE,
|
||||||
EventType.EXERCISE -> {
|
EventType.EXERCISE -> {
|
||||||
action_care_bg_layout.visibility = View.GONE
|
binding.bgLayout.visibility = View.GONE
|
||||||
actions_care_bgsource.visibility = View.GONE
|
binding.bgsource.visibility = View.GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,23 +134,28 @@ class CareDialog : DialogFragmentWithDate() {
|
||||||
override fun afterTextChanged(s: Editable) {}
|
override fun afterTextChanged(s: Editable) {}
|
||||||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
|
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
|
||||||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
||||||
if (actions_care_sensor.isChecked) actions_care_meter.isChecked = true
|
if (binding.sensor.isChecked) binding.meter.isChecked = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (profileFunction.getUnits() == Constants.MMOL) {
|
if (profileFunction.getUnits() == Constants.MMOL) {
|
||||||
actions_care_bgunits.text = resourceHelper.gs(R.string.mmol)
|
binding.bgunits.text = resourceHelper.gs(R.string.mmol)
|
||||||
actions_care_bg.setParams(savedInstanceState?.getDouble("actions_care_bg")
|
binding.bg.setParams(savedInstanceState?.getDouble("bg")
|
||||||
?: bg, 2.0, 30.0, 0.1, DecimalFormat("0.0"), false, ok, bgTextWatcher)
|
?: bg, 2.0, 30.0, 0.1, DecimalFormat("0.0"), false, binding.okcancel.ok, bgTextWatcher)
|
||||||
} else {
|
} else {
|
||||||
actions_care_bgunits.text = resourceHelper.gs(R.string.mgdl)
|
binding.bgunits.text = resourceHelper.gs(R.string.mgdl)
|
||||||
actions_care_bg.setParams(savedInstanceState?.getDouble("actions_care_bg")
|
binding.bg.setParams(savedInstanceState?.getDouble("bg")
|
||||||
?: bg, 36.0, 500.0, 1.0, DecimalFormat("0"), false, ok, bgTextWatcher)
|
?: bg, 36.0, 500.0, 1.0, DecimalFormat("0"), false, binding.okcancel.ok, bgTextWatcher)
|
||||||
}
|
}
|
||||||
actions_care_duration.setParams(savedInstanceState?.getDouble("actions_care_duration")
|
binding.duration.setParams(savedInstanceState?.getDouble("duration")
|
||||||
?: 0.0, 0.0, Constants.MAX_PROFILE_SWITCH_DURATION, 10.0, DecimalFormat("0"), false, ok)
|
?: 0.0, 0.0, Constants.MAX_PROFILE_SWITCH_DURATION, 10.0, DecimalFormat("0"), false, binding.okcancel.ok)
|
||||||
if (options == EventType.NOTE || options == EventType.QUESTION || options == EventType.ANNOUNCEMENT)
|
if (options == EventType.NOTE || options == EventType.QUESTION || options == EventType.ANNOUNCEMENT)
|
||||||
notes_layout?.visibility = View.VISIBLE // independent to preferences
|
binding.notesLayout.root.visibility = View.VISIBLE // independent to preferences
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroyView() {
|
||||||
|
super.onDestroyView()
|
||||||
|
_binding = null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun submit(): Boolean {
|
override fun submit(): Boolean {
|
||||||
|
@ -156,20 +167,20 @@ class CareDialog : DialogFragmentWithDate() {
|
||||||
if (options == EventType.BGCHECK || options == EventType.QUESTION || options == EventType.ANNOUNCEMENT) {
|
if (options == EventType.BGCHECK || options == EventType.QUESTION || options == EventType.ANNOUNCEMENT) {
|
||||||
val type =
|
val type =
|
||||||
when {
|
when {
|
||||||
actions_care_meter.isChecked -> CareportalEvent.FINGER
|
binding.meter.isChecked -> CareportalEvent.FINGER
|
||||||
actions_care_sensor.isChecked -> CareportalEvent.SENSOR
|
binding.sensor.isChecked -> CareportalEvent.SENSOR
|
||||||
else -> CareportalEvent.MANUAL
|
else -> CareportalEvent.MANUAL
|
||||||
}
|
}
|
||||||
actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_glucosetype) + ": " + translator.translate(type))
|
actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_glucosetype) + ": " + translator.translate(type))
|
||||||
actions.add(resourceHelper.gs(R.string.treatments_wizard_bg_label) + ": " + Profile.toCurrentUnitsString(profileFunction, actions_care_bg.value) + " " + resourceHelper.gs(unitResId))
|
actions.add(resourceHelper.gs(R.string.treatments_wizard_bg_label) + ": " + Profile.toCurrentUnitsString(profileFunction, binding.bg.value) + " " + resourceHelper.gs(unitResId))
|
||||||
json.put("glucose", actions_care_bg.value)
|
json.put("glucose", binding.bg.value)
|
||||||
json.put("glucoseType", type)
|
json.put("glucoseType", type)
|
||||||
}
|
}
|
||||||
if (options == EventType.NOTE || options == EventType.EXERCISE) {
|
if (options == EventType.NOTE || options == EventType.EXERCISE) {
|
||||||
actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_duration_label) + ": " + resourceHelper.gs(R.string.format_mins, actions_care_duration.value.toInt()))
|
actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_duration_label) + ": " + resourceHelper.gs(R.string.format_mins, binding.duration.value.toInt()))
|
||||||
json.put("duration", actions_care_duration.value.toInt())
|
json.put("duration", binding.duration.value.toInt())
|
||||||
}
|
}
|
||||||
val notes = notes.text.toString()
|
val notes = binding.notesLayout.notes.text.toString()
|
||||||
if (notes.isNotEmpty()) {
|
if (notes.isNotEmpty()) {
|
||||||
actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_notes_label) + ": " + notes)
|
actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_notes_label) + ": " + notes)
|
||||||
json.put("notes", notes)
|
json.put("notes", notes)
|
||||||
|
@ -195,7 +206,7 @@ class CareDialog : DialogFragmentWithDate() {
|
||||||
json.put("enteredBy", enteredBy)
|
json.put("enteredBy", enteredBy)
|
||||||
|
|
||||||
activity?.let { activity ->
|
activity?.let { activity ->
|
||||||
OKDialog.showConfirmation(activity, resourceHelper.gs(event), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
|
OKDialog.showConfirmation(activity, resourceHelper.gs(event), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
|
||||||
val careportalEvent = CareportalEvent(injector)
|
val careportalEvent = CareportalEvent(injector)
|
||||||
careportalEvent.date = eventTime
|
careportalEvent.date = eventTime
|
||||||
careportalEvent.source = Source.USER
|
careportalEvent.source = Source.USER
|
||||||
|
|
|
@ -23,14 +23,14 @@
|
||||||
android:padding="5dp">
|
android:padding="5dp">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/actions_care_icon"
|
android:id="@+id/icon"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:contentDescription="@string/careportal_profileswitch"
|
android:contentDescription="@string/careportal_profileswitch"
|
||||||
app:srcCompat="@drawable/ic_actions_profileswitch" />
|
app:srcCompat="@drawable/ic_actions_profileswitch" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/actions_care_title"
|
android:id="@+id/title"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerInParent="true"
|
android:layout_centerInParent="true"
|
||||||
|
@ -50,7 +50,7 @@
|
||||||
android:padding="5dp" />
|
android:padding="5dp" />
|
||||||
|
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
android:id="@+id/actions_care_bgsource"
|
android:id="@+id/bgsource"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
|
@ -58,21 +58,21 @@
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<RadioButton
|
<RadioButton
|
||||||
android:id="@+id/actions_care_meter"
|
android:id="@+id/meter"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:checked="false"
|
android:checked="false"
|
||||||
android:text="@string/careportal_newnstreatment_meter" />
|
android:text="@string/careportal_newnstreatment_meter" />
|
||||||
|
|
||||||
<RadioButton
|
<RadioButton
|
||||||
android:id="@+id/actions_care_sensor"
|
android:id="@+id/sensor"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:checked="true"
|
android:checked="true"
|
||||||
android:text="@string/careportal_newnstreatment_sensor" />
|
android:text="@string/careportal_newnstreatment_sensor" />
|
||||||
|
|
||||||
<RadioButton
|
<RadioButton
|
||||||
android:id="@+id/actions_care_other"
|
android:id="@+id/other"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/careportal_newnstreatment_other" />
|
android:text="@string/careportal_newnstreatment_other" />
|
||||||
|
@ -80,7 +80,7 @@
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/action_care_bg_layout"
|
android:id="@+id/bg_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
@ -96,12 +96,12 @@
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<info.nightscout.androidaps.utils.ui.NumberPicker
|
<info.nightscout.androidaps.utils.ui.NumberPicker
|
||||||
android:id="@+id/actions_care_bg"
|
android:id="@+id/bg"
|
||||||
android:layout_width="130dp"
|
android:layout_width="130dp"
|
||||||
android:layout_height="40dp" />
|
android:layout_height="40dp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/actions_care_bgunits"
|
android:id="@+id/bgunits"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
|
@ -115,7 +115,7 @@
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/action_care_duration_layout"
|
android:id="@+id/duration_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
@ -131,7 +131,7 @@
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<info.nightscout.androidaps.utils.ui.MinutesNumberPicker
|
<info.nightscout.androidaps.utils.ui.MinutesNumberPicker
|
||||||
android:id="@+id/actions_care_duration"
|
android:id="@+id/duration"
|
||||||
android:layout_width="130dp"
|
android:layout_width="130dp"
|
||||||
android:layout_height="40dp" />
|
android:layout_height="40dp" />
|
||||||
|
|
||||||
|
@ -148,11 +148,17 @@
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<include layout="@layout/notes" />
|
<include
|
||||||
|
android:id="@+id/notes_layout"
|
||||||
|
layout="@layout/notes" />
|
||||||
|
|
||||||
<include layout="@layout/datetime" />
|
<include
|
||||||
|
android:id="@+id/datetime"
|
||||||
|
layout="@layout/datetime" />
|
||||||
|
|
||||||
<include layout="@layout/okcancel" />
|
<include
|
||||||
|
android:id="@+id/okcancel"
|
||||||
|
layout="@layout/okcancel" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
android:width="120dp"
|
android:width="120dp"
|
||||||
android:padding="10dp"
|
android:padding="10dp"
|
||||||
android:text="@string/overview_carbs_label"
|
android:text="@string/treatments_wizard_carbs_label"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
android:layout_marginEnd="-4dp"
|
android:layout_marginEnd="-4dp"
|
||||||
android:layout_weight="0.5"
|
android:layout_weight="0.5"
|
||||||
android:drawableTop="@drawable/ic_cp_bolus_carbs"
|
android:drawableTop="@drawable/ic_cp_bolus_carbs"
|
||||||
android:text="@string/overview_carbs_label"
|
android:text="@string/treatments_wizard_carbs_label"
|
||||||
android:textColor="@color/colorCarbsButton"
|
android:textColor="@color/colorCarbsButton"
|
||||||
android:textSize="10sp" />
|
android:textSize="10sp" />
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue