Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.databinding.DataBindingUtil
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.jnj.vaccinetracker.R
import com.jnj.vaccinetracker.common.helpers.findParent
import com.jnj.vaccinetracker.common.ui.BaseDialogFragment
import com.jnj.vaccinetracker.databinding.DialogDosingOutOfWindowBinding

/**
* @author maartenvangiel
* @version 1
*/
class DosingOutOfWindowDialog : BaseDialogFragment() {
class DosingOutOfWindowDialog : BottomSheetDialogFragment() {

private lateinit var binding: DialogDosingOutOfWindowBinding

companion object {
fun newInstance(showConfirmButton: Boolean, descriptionResId: Int): DosingOutOfWindowDialog {
fun newInstance(showConfirmButton: Boolean, descriptionResId: Int, scheduledDate: String? = null): DosingOutOfWindowDialog {
val args = Bundle()
args.putBoolean("showConfirmButton", showConfirmButton)
args.putInt("descriptionResId", descriptionResId)
scheduledDate?.let { args.putString("scheduledDate", it) }
val dialog = DosingOutOfWindowDialog()
dialog.arguments = args
return dialog
Expand All @@ -35,10 +39,16 @@ class DosingOutOfWindowDialog : BaseDialogFragment() {

val showConfirm = arguments?.getBoolean("showConfirmButton") ?: true
val descriptionResId = arguments?.getInt("descriptionResId") ?: R.string.visit_dosing_warning_out_of_time_window_description
val scheduledDate = arguments?.getString("scheduledDate")

binding.btnConfirm.visibility = if (showConfirm) View.VISIBLE else View.GONE
binding.textViewDescription.setText(descriptionResId)

if (!scheduledDate.isNullOrEmpty()) {
binding.textViewScheduledDate.visibility = View.VISIBLE
binding.textViewScheduledDate.text = getString(R.string.visit_dosing_scheduled_date_label, scheduledDate)
}

binding.btnConfirm.setOnClickListener { dismissAllowingStateLoss() }
binding.btnCancel.setOnClickListener {
dismissAllowingStateLoss()
Expand All @@ -47,6 +57,19 @@ class DosingOutOfWindowDialog : BaseDialogFragment() {
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
dialog?.setOnShowListener { dialogInterface ->
val bottomSheetDialog = dialogInterface as? BottomSheetDialog
val bottomSheet = bottomSheetDialog?.findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet)
bottomSheet?.let {
val behavior = BottomSheetBehavior.from(it)
behavior.state = BottomSheetBehavior.STATE_EXPANDED
behavior.skipCollapsed = true
}
}
}

interface DosingOutOfWindowDialogListener {
fun onOutOfWindowDosingCanceled()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import com.jnj.vaccinetracker.visit.VisitActivity
import com.jnj.vaccinetracker.visit.VisitViewModel
import com.jnj.vaccinetracker.visit.dialog.DosingOutOfWindowDialog
import com.jnj.vaccinetracker.visit.dialog.RescheduleVisitDialog
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Locale
import kotlin.math.ceil

@RequiresApi(Build.VERSION_CODES.O)
Expand Down Expand Up @@ -118,10 +120,17 @@ class ContraindicationsFragment : BaseFragment() {
.commit()
}

private fun formatScheduledDate(): String? {
val visitDate = viewModel.dosingVisit.value?.visitDate ?: return null
val dateFormat = SimpleDateFormat("EEE, d MMM yyyy", Locale.ENGLISH)
return dateFormat.format(visitDate)
}

private fun showOutsideTimeWindowConfirmationDialog() {
val dialog = DosingOutOfWindowDialog.newInstance(
true,
R.string.visit_dosing_warning_out_of_time_window_description
R.string.visit_dosing_warning_out_of_time_window_description,
formatScheduledDate()
)
dialog.isCancelable = false
dialog.show(requireActivity().supportFragmentManager, VisitActivity.TAG_DIALOG_DOSING_OUT_OF_WINDOW)
Expand All @@ -130,7 +139,8 @@ class ContraindicationsFragment : BaseFragment() {
private fun showFarFromWindowDialog() {
val dialog = DosingOutOfWindowDialog.newInstance(
false,
R.string.visit_dosing_warning_far_from_time_window_description
R.string.visit_dosing_warning_far_from_time_window_description,
formatScheduledDate()
)
dialog.isCancelable = false
dialog.show(requireActivity().supportFragmentManager, "TAG_DOSING_OUT_OF_WINDOW")
Expand Down
167 changes: 95 additions & 72 deletions app/src/main/res/layout/dialog_dosing_out_of_window.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,85 +2,108 @@
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout"
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
android:fillViewport="true">

<ImageView
android:id="@+id/img_header"
android:layout_width="0dp"
android:layout_height="120dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:background="@color/alertLight"
android:src="@drawable/ic_checkmark_alert"
app:tint="@color/colorTextOnPrimary"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<TextView
android:id="@+id/textView_title"
android:layout_width="wrap_content"
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center_horizontal"
android:text="@string/visit_dosing_warning_out_of_time_window_title"
android:textAppearance="@style/PopupTitle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/img_header" />
android:padding="16dp">

<TextView
android:id="@+id/textView_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="@string/visit_dosing_warning_out_of_time_window_description"
android:textAppearance="@style/GeneralText"
android:textAlignment="center"
android:textColor="@color/colorTextOnLight"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView_title" />
<ImageView
android:id="@+id/img_header"
android:layout_width="0dp"
android:layout_height="80dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:background="@color/alertLight"
android:src="@drawable/ic_checkmark_alert"
app:tint="@color/colorTextOnPrimary"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/btn_confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="16dp"
android:backgroundTint="@color/alertLight"
android:textAppearance="@style/ButtonTextStyling"
android:text="@string/general_label_confirm"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/btn_cancel"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/btn_cancel"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/textView_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:gravity="center_horizontal"
android:text="@string/visit_dosing_warning_out_of_time_window_title"
android:textAppearance="@style/PopupTitle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/img_header" />

<Button
android:id="@+id/btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:backgroundTint="@color/colorPrimary"
android:textAppearance="@style/ButtonTextStyling"
android:text="@string/general_label_cancel"
android:textColor="@color/colorTextOnSecondary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/btn_confirm"
app:layout_constraintTop_toBottomOf="@+id/textView_description" />
<TextView
android:id="@+id/textView_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_16"
android:layout_marginTop="12dp"
android:layout_marginEnd="@dimen/margin_16"
android:text="@string/visit_dosing_warning_out_of_time_window_description"
android:textAppearance="@style/GeneralText"
android:textAlignment="center"
android:textColor="@color/colorTextOnLight"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView_title" />

<TextView
android:id="@+id/textView_scheduled_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_16"
android:layout_marginTop="8dp"
android:layout_marginEnd="@dimen/margin_16"
android:textAppearance="@style/GeneralText"
android:textAlignment="center"
android:textStyle="bold"
android:textColor="@color/colorTextOnLight"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView_description" />

<Button
android:id="@+id/btn_confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="16dp"
android:backgroundTint="@color/alertLight"
android:textAppearance="@style/ButtonTextStyling"
android:text="@string/general_label_confirm"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/btn_cancel"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/btn_cancel"
app:layout_constraintVertical_bias="0.0" />

<Button
android:id="@+id/btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:backgroundTint="@color/colorPrimary"
android:textAppearance="@style/ButtonTextStyling"
android:text="@string/general_label_cancel"
android:textColor="@color/colorTextOnSecondary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/btn_confirm"
app:layout_constraintTop_toBottomOf="@+id/textView_scheduled_date" />

</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

</layout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
<string name="visit_dosing_warning_out_of_time_window_description">Please confirm that this child is receiving a dosage before the scheduled date.</string>
<string name="visit_dosing_warning_far_from_time_window_description">Please note that this child is not due for the next visit.</string>
<string name="visit_dosing_warning_out_of_time_window_title">Dosing outside of window</string>
<string name="visit_dosing_scheduled_date_label">Scheduled date: %s</string>
<string name="visit_dosing_error_different_manufacturer_description">The manufacturer selected is different from the one indicated in the regimen and should not be administered.</string>
<string name="visit_dosing_warning_different_manufacturer_description">The manufacturer selected is different from the one indicated in the regimen. Please confirm you will administer a different vaccine.</string>
<string name="visit_dosing_warning_different_manufacturer_title">Different Manufacturer Expected</string>
Expand Down