From 45dd86e7f82434f23f6056f8e6bb57a6dc4fd716 Mon Sep 17 00:00:00 2001 From: fikrimilano Date: Mon, 13 Feb 2023 19:13:55 +0700 Subject: [PATCH 01/11] Add onScrollListener that can be overridden --- .../fhir/datacapture/QuestionnaireFragment.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireFragment.kt b/datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireFragment.kt index 70a9c48a17..a8b5815c1b 100644 --- a/datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireFragment.kt +++ b/datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireFragment.kt @@ -22,6 +22,7 @@ import android.view.View import android.view.ViewGroup import android.widget.Button import androidx.appcompat.view.ContextThemeWrapper +import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.res.use import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels @@ -30,8 +31,10 @@ import androidx.fragment.app.viewModels import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView +import androidx.recyclerview.widget.RecyclerView.OnScrollListener import com.google.android.fhir.datacapture.validation.Invalid import com.google.android.fhir.datacapture.views.QuestionnaireItemViewHolderFactory +import com.google.android.material.divider.MaterialDivider import com.google.android.material.progressindicator.LinearProgressIndicator import org.hl7.fhir.r4.model.Questionnaire import timber.log.Timber @@ -69,6 +72,8 @@ open class QuestionnaireFragment : Fragment() { /** @suppress */ override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + val bottomContainer = view.findViewById(R.id.bottom_container) + val bottomContainerDivider = view.findViewById(R.id.container_divider) val questionnaireEditRecyclerView = view.findViewById(R.id.questionnaire_edit_recycler_view) val questionnaireReviewRecyclerView = @@ -113,11 +118,17 @@ open class QuestionnaireFragment : Fragment() { questionnaireEditRecyclerView.adapter = questionnaireItemEditAdapter val linearLayoutManager = LinearLayoutManager(view.context) questionnaireEditRecyclerView.layoutManager = linearLayoutManager + questionnaireEditRecyclerView.addOnScrollListener( + onScrollListener(bottomContainer, bottomContainerDivider) + ) // Animation does work well with views that could gain focus questionnaireEditRecyclerView.itemAnimator = null questionnaireReviewRecyclerView.adapter = questionnaireItemReviewAdapter questionnaireReviewRecyclerView.layoutManager = LinearLayoutManager(view.context) + questionnaireReviewRecyclerView.addOnScrollListener( + onScrollListener(bottomContainer, bottomContainerDivider) + ) // Listen to updates from the view model. viewLifecycleOwner.lifecycleScope.launchWhenCreated { @@ -248,6 +259,14 @@ open class QuestionnaireFragment : Fragment() { */ fun getQuestionnaireResponse() = viewModel.getQuestionnaireResponse() + /** Override this method to add a custom behavior to Bottom Container on scrolling. */ + open fun onScrollListener( + bottomContainer: ConstraintLayout, + bottomContainerDivider: MaterialDivider + ): OnScrollListener { + return object : OnScrollListener() {} + } + /** * Extras that can be passed to [QuestionnaireFragment] to define its behavior. When you create a * QuestionnaireFragment, one of [EXTRA_QUESTIONNAIRE_JSON_URI] or From 0534d59b9541fa639b3d0a87d08f9295859de8d9 Mon Sep 17 00:00:00 2001 From: fikrimilano Date: Mon, 13 Feb 2023 19:15:45 +0700 Subject: [PATCH 02/11] Add divider above bottom container Gone by default. --- .../main/res/layout/questionnaire_fragment.xml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/datacapture/src/main/res/layout/questionnaire_fragment.xml b/datacapture/src/main/res/layout/questionnaire_fragment.xml index 9d1ea76228..1d285cd342 100644 --- a/datacapture/src/main/res/layout/questionnaire_fragment.xml +++ b/datacapture/src/main/res/layout/questionnaire_fragment.xml @@ -51,7 +51,7 @@ android:layout_width="match_parent" android:layout_height="0dp" android:scrollbars="vertical" - app:layout_constraintBottom_toTopOf="@+id/bottom_buttons" + app:layout_constraintBottom_toTopOf="@+id/container_divider" app:layout_constraintTop_toBottomOf="@+id/questionnaire_progress_indicator" /> @@ -60,12 +60,21 @@ android:layout_width="match_parent" android:layout_height="0dp" android:scrollbars="vertical" - app:layout_constraintBottom_toTopOf="@+id/bottom_buttons" + app:layout_constraintBottom_toTopOf="@+id/container_divider" app:layout_constraintTop_toBottomOf="@+id/review_mode_edit_button" /> + + Date: Mon, 13 Feb 2023 19:16:23 +0700 Subject: [PATCH 03/11] Add styling to bottom container and the divider above it --- datacapture/src/main/res/values/attrs.xml | 4 ++++ datacapture/src/main/res/values/styles.xml | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/datacapture/src/main/res/values/attrs.xml b/datacapture/src/main/res/values/attrs.xml index 38a5d1ca20..a8dc7f5c97 100644 --- a/datacapture/src/main/res/values/attrs.xml +++ b/datacapture/src/main/res/values/attrs.xml @@ -32,6 +32,10 @@ + + + + diff --git a/datacapture/src/main/res/values/styles.xml b/datacapture/src/main/res/values/styles.xml index 827a682476..e19be5d96b 100644 --- a/datacapture/src/main/res/values/styles.xml +++ b/datacapture/src/main/res/values/styles.xml @@ -55,6 +55,12 @@ @style/Widget.MaterialComponents.Button.TextButton.Icon + @style/Questionnaire.BottomContainerStyle + @style/Questionnaire.BottomContainerDividerStyle @style/Questionnaire.AnswerStyle @@ -158,6 +164,21 @@ ?attr/colorOnSurfaceVariant + + + + From 569ddc4e60e1bca4be210f93aa64dbd02dfa5bba Mon Sep 17 00:00:00 2001 From: fikrimilano Date: Mon, 20 Feb 2023 19:34:16 +0700 Subject: [PATCH 06/11] Remove bottom container parent style --- datacapture/src/main/res/values/styles.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datacapture/src/main/res/values/styles.xml b/datacapture/src/main/res/values/styles.xml index b5eeb7be35..048e75c185 100644 --- a/datacapture/src/main/res/values/styles.xml +++ b/datacapture/src/main/res/values/styles.xml @@ -175,7 +175,7 @@ - -