Commit cfb9f415 authored by Joey's avatar Joey

glucose: insulin dialog: add empty state

Signed-off-by: Joey's avatarJoey <bevilacquajoey@gmail.com>
Change-Id: I2f27914732161a81b556549b4f663cf38e7f0db8
parent d7df8932
Pipeline #65369831 passed with stage
in 12 minutes and 26 seconds
......@@ -16,7 +16,10 @@ import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.EditText
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.widget.AppCompatSpinner
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet
import androidx.lifecycle.ViewModelProviders
import com.google.android.material.button.MaterialButton
import it.diab.core.util.Activities
......@@ -28,14 +31,17 @@ import it.diab.glucose.ui.models.InsulinDialogUiModel
import it.diab.glucose.util.InsulinSelector
import it.diab.glucose.viewmodels.InsulinDialogViewModel
import it.diab.glucose.viewmodels.InsulinDialogViewModelFactory
import it.diab.ui.util.UIUtils
import it.diab.ui.widgets.BottomSheetDialogFragmentExt
class InsulinDialogFragment : BottomSheetDialogFragmentExt() {
private lateinit var constraint: ConstraintLayout
private lateinit var nameSpinner: AppCompatSpinner
private lateinit var valueEditText: EditText
private lateinit var addButton: MaterialButton
private lateinit var removeButton: MaterialButton
private lateinit var emptyText: TextView
private lateinit var positiveButton: MaterialButton
private lateinit var negativeButton: MaterialButton
private lateinit var editorIcon: ImageView
......@@ -62,12 +68,16 @@ class InsulinDialogFragment : BottomSheetDialogFragmentExt() {
): View {
val view = inflater.inflate(R.layout.fragment_add_insulin, container, false)
constraint = view.findViewById(R.id.glucose_editor_insulin_root)
nameSpinner = view.findViewById(R.id.glucose_editor_insulin_spinner)
valueEditText = view.findViewById(R.id.glucose_editor_insulin_value)
addButton = view.findViewById(R.id.glucose_editor_insulin_add)
removeButton = view.findViewById(R.id.glucose_editor_insulin_remove)
emptyText = view.findViewById(R.id.glucose_editor_insulin_empty)
positiveButton = view.findViewById(R.id.glucose_editor_insulin_positive)
negativeButton = view.findViewById(R.id.glucose_editor_insulin_negative)
editorIcon = view.findViewById(R.id.glucose_editor_insulin_editor)
UIUtils.setWhiteNavBarIfNeeded(requireContext(), dialog)
return view
}
......@@ -81,6 +91,53 @@ class InsulinDialogFragment : BottomSheetDialogFragmentExt() {
}
private fun setup(model: InsulinDialogUiModel) {
if (viewModel.hasNothing()) {
setupEmpty()
} else {
setupWithContent(model)
}
}
private fun setupEmpty() {
ConstraintSet().apply {
clone(constraint)
connect(
R.id.glucose_editor_insulin_positive,
ConstraintSet.TOP,
R.id.glucose_editor_insulin_empty,
ConstraintSet.BOTTOM
)
connect(
R.id.glucose_editor_insulin_positive,
ConstraintSet.START,
ConstraintSet.PARENT_ID,
ConstraintSet.START
)
connect(
R.id.glucose_editor_insulin_positive,
ConstraintSet.END,
ConstraintSet.PARENT_ID,
ConstraintSet.END
)
constrainPercentWidth(
R.id.glucose_editor_insulin_positive,
0.8f
)
applyTo(constraint)
}
emptyText.visibility = View.VISIBLE
valueEditText.visibility = View.GONE
nameSpinner.visibility = View.GONE
negativeButton.visibility = View.GONE
editorIcon.setOnClickListener { startActivity(intentTo(Activities.Insulin)) }
positiveButton.setOnClickListener { startActivity(intentTo(Activities.Insulin)) }
positiveButton.setText(R.string.glucose_editor_insulin_none_btn)
}
private fun setupWithContent(model: InsulinDialogUiModel) {
val context = context ?: return
if (model.insulinValue > 0f) {
......@@ -101,11 +158,12 @@ class InsulinDialogFragment : BottomSheetDialogFragmentExt() {
nameSpinner.setSelection(spinnerIndex)
editorIcon.setOnClickListener { startActivity(intentTo(Activities.Insulin)) }
addButton.setOnClickListener { onSave() }
removeButton.setOnClickListener { onRemove() }
positiveButton.setOnClickListener { onSave() }
positiveButton.setText(R.string.glucose_editor_insulin_apply)
negativeButton.setOnClickListener { onRemove() }
if (model.currentInsulinId < 1L) {
removeButton.visibility = View.GONE
negativeButton.visibility = View.GONE
}
}
......
......@@ -64,6 +64,8 @@ class InsulinDialogViewModel internal constructor(
}
}
fun hasNothing() = insulins.isEmpty()
@VisibleForTesting
suspend fun runPrepare(uid: Long, wantBasal: Boolean) {
glucose = glucoseRepository.getById(uid)
......
<!--
Copyright (c) 2019 Bevilacqua Joey
Licensed under the GNU GPLv3 license
The text of the license can be found in the LICENSE file
or at https://www.gnu.org/licenses/gpl.txt
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M19.28,8.6L18.58,7.39L17.31,7.9L16.25,8.33L15.34,7.63C14.95,7.33 14.54,7.09 14.11,6.92L13.05,6.49L12.89,5.36L12.7,4H11.3L11.11,5.35L10.95,6.48L9.89,6.92C9.48,7.09 9.07,7.33 8.64,7.65L7.74,8.33L6.69,7.91L5.42,7.39L4.72,8.6L5.8,9.44L6.69,10.14L6.55,11.27C6.52,11.57 6.5,11.8 6.5,12C6.5,12.2 6.52,12.43 6.55,12.73L6.69,13.86L5.8,14.56L4.72,15.4L5.42,16.61L6.69,16.1L7.75,15.67L8.66,16.37C9.05,16.67 9.46,16.91 9.89,17.08L10.95,17.51L11.11,18.64L11.3,20H12.69L12.88,18.65L13.04,17.52L14.1,17.09C14.51,16.92 14.92,16.68 15.35,16.36L16.25,15.68L17.29,16.1L18.56,16.61L19.26,15.4L18.18,14.56L17.29,13.86L17.43,12.73C17.47,12.42 17.48,12.21 17.48,12C17.48,11.79 17.46,11.57 17.43,11.27L17.29,10.14L18.18,9.44L19.28,8.6ZM12,16C9.79,16 8,14.21 8,12C8,9.79 9.79,8 12,8C14.21,8 16,9.79 16,12C16,14.21 14.21,16 12,16Z"
android:strokeAlpha="0.3"
android:fillColor="?colorAccent"
android:fillAlpha="0.3"/>
<path
android:pathData="M19.4301,12.98C19.4701,12.66 19.5001,12.34 19.5001,12C19.5001,11.66 19.4701,11.34 19.4301,11.02L21.5401,9.37C21.7301,9.22 21.7801,8.95 21.6601,8.73L19.6601,5.27C19.5701,5.11 19.4001,5.02 19.2201,5.02C19.1601,5.02 19.1001,5.03 19.0501,5.05L16.5601,6.05C16.0401,5.65 15.4801,5.32 14.8701,5.07L14.4901,2.42C14.4601,2.18 14.2501,2 14.0001,2H10.0001C9.7501,2 9.5401,2.18 9.5101,2.42L9.1301,5.07C8.5201,5.32 7.9601,5.66 7.4401,6.05L4.9501,5.05C4.8901,5.03 4.8301,5.02 4.7701,5.02C4.6001,5.02 4.4301,5.11 4.3401,5.27L2.3401,8.73C2.2101,8.95 2.2701,9.22 2.4601,9.37L4.5701,11.02C4.5301,11.34 4.5001,11.67 4.5001,12C4.5001,12.33 4.5301,12.66 4.5701,12.98L2.4601,14.63C2.2701,14.78 2.2201,15.05 2.3401,15.27L4.3401,18.73C4.4301,18.89 4.6001,18.98 4.7801,18.98C4.8401,18.98 4.9001,18.97 4.9501,18.95L7.4401,17.95C7.9601,18.35 8.5201,18.68 9.1301,18.93L9.5101,21.58C9.5401,21.82 9.7501,22 10.0001,22H14.0001C14.2501,22 14.4601,21.82 14.4901,21.58L14.8701,18.93C15.4801,18.68 16.0401,18.34 16.5601,17.95L19.0501,18.95C19.1101,18.97 19.1701,18.98 19.2301,18.98C19.4001,18.98 19.5701,18.89 19.6601,18.73L21.6601,15.27C21.7801,15.05 21.7301,14.78 21.5401,14.63L19.4301,12.98ZM17.4501,11.27C17.4901,11.58 17.5001,11.79 17.5001,12C17.5001,12.21 17.4801,12.43 17.4501,12.73L17.3101,13.86L18.2001,14.56L19.2801,15.4L18.5801,16.61L17.3101,16.1L16.2701,15.68L15.3701,16.36C14.9401,16.68 14.5301,16.92 14.1201,17.09L13.0601,17.52L12.9001,18.65L12.7001,20H11.3001L11.1101,18.65L10.9501,17.52L9.8901,17.09C9.4601,16.91 9.0601,16.68 8.6601,16.38L7.7501,15.68L6.6901,16.11L5.4201,16.62L4.7201,15.41L5.8001,14.57L6.6901,13.87L6.5501,12.74C6.5201,12.43 6.5001,12.2 6.5001,12C6.5001,11.8 6.5201,11.57 6.5501,11.27L6.6901,10.14L5.8001,9.44L4.7201,8.6L5.4201,7.39L6.6901,7.9L7.7301,8.32L8.6301,7.64C9.0601,7.32 9.4701,7.08 9.8801,6.91L10.9401,6.48L11.1001,5.35L11.3001,4H12.6901L12.8801,5.35L13.0401,6.48L14.1001,6.91C14.5301,7.09 14.9301,7.32 15.3301,7.62L16.2401,8.32L17.3001,7.89L18.5701,7.38L19.2701,8.59L18.2001,9.44L17.3101,10.14L17.4501,11.27ZM12.0001,8C9.7901,8 8.0001,9.79 8.0001,12C8.0001,14.21 9.7901,16 12.0001,16C14.2101,16 16.0001,14.21 16.0001,12C16.0001,9.79 14.2101,8 12.0001,8ZM12.0001,14C10.9001,14 10.0001,13.1 10.0001,12C10.0001,10.9 10.9001,10 12.0001,10C13.1001,10 14.0001,10.9 14.0001,12C14.0001,13.1 13.1001,14 12.0001,14Z"
android:fillColor="?colorAccent"/>
</vector>
......@@ -9,10 +9,10 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/glucose_editor_insulin_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:orientation="horizontal"
android:padding="16dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
......@@ -22,7 +22,8 @@
android:layout_height="24dp"
android:layout_margin="8dp"
android:background="?selectableItemBackgroundBorderless"
android:src="@drawable/ic_editor_insulin"
android:src="@drawable/ic_insulin_settings"
android:contentDescription="@string/glucose_editor_insulin_edit"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
......@@ -61,26 +62,39 @@
app:layout_constraintWidth_percent="0.3"
tools:targetApi="O" />
<TextView
android:id="@+id/glucose_editor_insulin_empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textSize="18sp"
android:text="@string/glucose_editor_no_insulin"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/glucose_editor_insulin_title" />
<com.google.android.material.button.MaterialButton
android:id="@+id/glucose_editor_insulin_add"
android:id="@+id/glucose_editor_insulin_positive"
style="@style/Widget.MaterialComponents.Button.TextButton.Dialog"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/glucose_editor_insulin_apply"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/glucose_editor_insulin_spinner"
app:layout_constraintWidth_default="percent"
app:layout_constraintWidth_percent="0.3" />
app:layout_constraintWidth_percent="0.3"
tools:text="@string/glucose_editor_insulin_apply" />
<com.google.android.material.button.MaterialButton
android:id="@+id/glucose_editor_insulin_remove"
android:id="@+id/glucose_editor_insulin_negative"
style="@style/Widget.MaterialComponents.Button.TextButton.Dialog"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/remove"
app:layout_constraintEnd_toStartOf="@id/glucose_editor_insulin_add"
app:layout_constraintTop_toTopOf="@id/glucose_editor_insulin_add"
app:layout_constraintEnd_toStartOf="@id/glucose_editor_insulin_positive"
app:layout_constraintTop_toTopOf="@id/glucose_editor_insulin_positive"
app:layout_constraintWidth_default="percent"
app:layout_constraintWidth_percent="0.3" />
</androidx.constraintlayout.widget.ConstraintLayout>
......@@ -11,7 +11,6 @@
<!-- Glucose Editor -->
<string name="glucose_editor_time_dialog">समय चुने</string>
<string name="glucose_editor_insulin_add">इंसुलिन जोड़ें</string>
<string name="glucose_editor_insulin_apply">लागू करें</string>
<string name="glucose_editor_basal_add">बेसल जोड़ें</string>
<string name="glucose_editor_insulin_value">मात्रा</string>
<string name="glucose_editor_save_error">मूल्यों को फिर से जांचें</string>
......@@ -37,4 +36,10 @@
<!-- Time -->
<string name="time_today">आज</string>
<string name="time_yesterday">कल</string>
<!-- Insulin dialog -->
<string name="glucose_editor_insulin_apply">लागू करें</string>
<string name="glucose_editor_insulin_none">No insulin found</string>
<string name="glucose_editor_insulin_none_btn">Register a new insulin</string>
<string name="glucose_editor_insulin_edit">Edit insulins</string>
</resources>
......@@ -11,7 +11,6 @@
<!-- Glcuose Editor -->
<string name="glucose_editor_time_dialog">Seleziona la data</string>
<string name="glucose_editor_insulin_add">Aggiungi insulina</string>
<string name="glucose_editor_insulin_apply">Applica</string>
<string name="glucose_editor_basal_add">Aggiungi basale</string>
<string name="glucose_editor_insulin_value">Quantit\u00E0</string>
<string name="glucose_editor_save_error">Controlla di nuovo i valori</string>
......@@ -37,4 +36,10 @@
<!-- Time -->
<string name="time_today">Oggi</string>
<string name="time_yesterday">Ieri</string>
<!-- Insulin dialog -->
<string name="glucose_editor_insulin_apply">Applica</string>
<string name="glucose_editor_insulin_none">Nessuna insulina registrata</string>
<string name="glucose_editor_insulin_none_btn">Registra insuline</string>
<string name="glucose_editor_insulin_edit">Modifica insuline</string>
</resources>
\ No newline at end of file
......@@ -11,7 +11,6 @@
<!-- Glucose Editor -->
<string name="glucose_editor_time_dialog">Select the time</string>
<string name="glucose_editor_insulin_add">Add insulin</string>
<string name="glucose_editor_insulin_apply">Apply</string>
<string name="glucose_editor_basal_add">Add basal</string>
<string name="glucose_editor_insulin_value">Quantity</string>
<string name="glucose_editor_save_error">Check the values again</string>
......@@ -37,4 +36,10 @@
<!-- Time -->
<string name="time_today">Today</string>
<string name="time_yesterday">Yesterday</string>
<!-- Insulin dialog -->
<string name="glucose_editor_insulin_apply">Apply</string>
<string name="glucose_editor_insulin_none">No insulin found</string>
<string name="glucose_editor_insulin_none_btn">Register a new insulin</string>
<string name="glucose_editor_insulin_edit">Edit insulins</string>
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment