Skip to content

Commit

Permalink
Lists: move delete list button to the edge, use save action string
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Dec 11, 2024
1 parent 7da1b27 commit a612ecb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,29 @@ class ListManageDialogFragment : AppCompatDialogFragment() {
this.binding = binding

// buttons
binding.buttonNegative.isEnabled = false
binding.buttonNegative.setText(R.string.list_remove)
binding.buttonNegative.setOnClickListener {
// ask about removing list
DeleteListDialogFragment.create(listId)
.safeShow(parentFragmentManager, "confirm-delete-list")
dismiss()
binding.buttonListManageDelete.apply {
isEnabled = false
setText(R.string.list_remove)
setOnClickListener {
// ask about removing list
DeleteListDialogFragment.create(listId)
.safeShow(parentFragmentManager, "confirm-delete-list")
dismiss()
}
}
binding.buttonPositive.setText(android.R.string.ok)
binding.buttonPositive.setOnClickListener {
val editText = this.binding?.textInputLayoutListManageListName?.editText
?: return@setOnClickListener

// update title
val listName = editText.text.toString().trim()
ListsTools.renameList(requireContext(), listId, listName)

dismiss()
binding.buttonListManageConfirm.apply {
setText(R.string.action_save)
setOnClickListener {
val editText =
this@ListManageDialogFragment.binding?.textInputLayoutListManageListName?.editText
?: return@setOnClickListener

// update title
val listName = editText.text.toString().trim()
ListsTools.renameList(requireContext(), listId, listName)

dismiss()
}
}

// Delay loading data for views to after this function
Expand Down Expand Up @@ -95,14 +100,14 @@ class ListManageDialogFragment : AppCompatDialogFragment() {
editTextName.addTextChangedListener(
AddListDialogFragment.ListNameTextWatcher(
requireContext(), textInputLayoutName,
binding.buttonPositive, listName
binding.buttonListManageConfirm, listName
)
)

// do only allow removing if this is NOT the last list
val listsCount = listHelper.getListsCount()
if (listsCount > 1) {
binding.buttonNegative.isEnabled = true
binding.buttonListManageDelete.isEnabled = true
}
}

Expand Down
12 changes: 7 additions & 5 deletions app/src/main/res/layout/dialog_list_manage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayoutListManageListName"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
app:endIconMode="clear_text">

<!-- Set inputType as it does not default to (single-line) text like EditText. -->
<!-- Set minWidth on EditText so FrameLayout sizes correctly. -->
Expand All @@ -38,27 +39,28 @@
android:paddingRight="@dimen/large_padding"
android:paddingBottom="@dimen/inline_padding">

<!-- Use spread_inside so delete button is far away from OK button -->
<androidx.constraintlayout.helper.widget.Flow
android:layout_width="0dp"
android:layout_height="wrap_content"
app:constraint_referenced_ids="buttonNegative,buttonPositive"
app:constraint_referenced_ids="buttonListManageDelete,buttonListManageConfirm"
app:flow_horizontalBias="1"
app:flow_horizontalStyle="packed"
app:flow_horizontalStyle="spread_inside"
app:flow_wrapMode="chain"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/buttonNegative"
android:id="@+id/buttonListManageDelete"
style="?attr/buttonBarNegativeButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Button Negative With Long Text" />

<Button
android:id="@+id/buttonPositive"
android:id="@+id/buttonListManageConfirm"
style="?attr/buttonBarPositiveButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down

0 comments on commit a612ecb

Please sign in to comment.