Skip to content

Commit

Permalink
Use checkbox for show/hide error state (#2563)
Browse files Browse the repository at this point in the history
* Use checkbox to toggle error state

* Tune position of close bt and size of checkbox

* Remove close button and unused string in strings.xml

---------

Co-authored-by: Jing Tang <[email protected]>
  • Loading branch information
chungwwei and jingtang10 committed Jun 7, 2024
1 parent df463c7 commit 735fd0f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2023 Google LLC
* Copyright 2021-2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,10 +20,9 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.CheckBox
import androidx.core.os.bundleOf
import androidx.fragment.app.setFragmentResult
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.fragment.navArgs
import com.google.android.material.bottomsheet.BottomSheetDialogFragment

Expand All @@ -40,25 +39,16 @@ class ModalBottomSheetFragment : BottomSheetDialogFragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val showHideErrorButton = view.findViewById<Button>(R.id.errorToggleButton)
showHideErrorButton.text =
requireContext()
.getString(
if (args.errorState) {
R.string.hide_error_state
} else {
R.string.show_error_state
},
)
showHideErrorButton.setOnClickListener {

val showHideErrorCheckBox = view.findViewById<CheckBox>(R.id.errorToggleCheckBox)
showHideErrorCheckBox.isChecked = args.errorState
showHideErrorCheckBox.setOnCheckedChangeListener { _, isChecked ->
setFragmentResult(
REQUEST_ERROR_KEY,
bundleOf(
BUNDLE_ERROR_KEY to
(showHideErrorButton.text == requireContext().getString(R.string.show_error_state)),
BUNDLE_ERROR_KEY to isChecked,
),
)
NavHostFragment.findNavController(this).navigateUp()
}
(activity as? MainActivity)?.showOpenQuestionnaireMenu(false)
}
Expand Down
15 changes: 6 additions & 9 deletions catalog/src/main/res/layout/fragment_modal_bottom_sheet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
android:layout_height="match_parent"
tools:context=".ModalBottomSheetFragment"
>

<TextView
android:id="@+id/optionsTextView"
android:layout_width="wrap_content"
Expand All @@ -19,13 +18,12 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>

<Button
style="@style/Widget.App.MaterialComponents.Button"
android:id="@+id/errorToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
<CheckBox
android:id="@+id/errorToggleCheckBox"
style="@style/Questionnaire.CheckBoxStyle"
android:layout_width="280dp"
android:layout_height="68dp"
android:layout_marginTop="24dp"
android:layout_marginBottom="116dp"
android:text="@string/show_error_state"
android:textAllCaps="false"
Expand All @@ -34,5 +32,4 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/optionsTextView"
/>

</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 0 additions & 1 deletion catalog/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
>Below is the JSON code</string>
<string name="submit">Submit</string>
<string name="show_error_state">Show error state</string>
<string name="hide_error_state">Hide error state</string>
<string name="options">Options</string>
<string name="error">Error</string>
<string name="widgets">Widgets</string>
Expand Down

0 comments on commit 735fd0f

Please sign in to comment.