-
-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1083 from UweTrottmann/confirm-list-deletion
Confirm list deletion
- Loading branch information
Showing
27 changed files
with
210 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
app/src/main/java/com/battlelancer/seriesguide/lists/DeleteListDialogFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2024 Uwe Trottmann | ||
|
||
package com.battlelancer.seriesguide.lists | ||
|
||
import android.app.Dialog | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatDialogFragment | ||
import androidx.core.os.bundleOf | ||
import com.battlelancer.seriesguide.R | ||
import com.battlelancer.seriesguide.provider.SgRoomDatabase | ||
import com.google.android.material.dialog.MaterialAlertDialogBuilder | ||
|
||
/** | ||
* Dialog to confirm deletion of a list and its items. | ||
*/ | ||
class DeleteListDialogFragment : AppCompatDialogFragment() { | ||
|
||
private lateinit var listId: String | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
listId = requireArguments().getString(ARG_LIST_ID) | ||
?: throw IllegalArgumentException("$ARG_LIST_ID must be supplied") | ||
} | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
val listTitle = SgRoomDatabase.getInstance(requireContext()).sgListHelper() | ||
.getList(listId) | ||
?.name ?: getString(R.string.unknown) | ||
|
||
// Explicitly make negative button cancel (non-destructive action) as the delete list button | ||
// is the negative action in the originating dialog; so accidentally pressing again in the | ||
// same region does not do the destructive action. | ||
return MaterialAlertDialogBuilder(requireContext()) | ||
.setTitle(requireContext().getString(R.string.confirm_delete, listTitle)) | ||
.setNegativeButton(android.R.string.cancel) { _, _ -> | ||
// just dismiss | ||
} | ||
.setPositiveButton(R.string.list_remove) { _, _ -> | ||
ListsTools.deleteList(requireContext(), listId) | ||
} | ||
.create() | ||
} | ||
|
||
companion object { | ||
|
||
private const val ARG_LIST_ID = "list_id" | ||
|
||
fun create(listId: String): DeleteListDialogFragment { | ||
return DeleteListDialogFragment().apply { | ||
arguments = bundleOf(ARG_LIST_ID to listId) | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout 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/root" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
|
||
<FrameLayout | ||
style="@style/DefaultPadding.DialogContent" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<com.google.android.material.textfield.TextInputLayout | ||
android:id="@+id/textInputLayoutListManageListName" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<!-- Set inputType as it does not default to (single-line) text like EditText. --> | ||
<!-- Set minWidth on EditText so FrameLayout sizes correctly. --> | ||
<com.google.android.material.textfield.TextInputEditText | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:hint="@string/list_title_hint" | ||
android:inputType="text" | ||
android:minWidth="@dimen/dialog_min_width" /> | ||
|
||
</com.google.android.material.textfield.TextInputLayout> | ||
|
||
</FrameLayout> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:paddingLeft="@dimen/large_padding" | ||
android:paddingTop="@dimen/inline_padding" | ||
android:paddingRight="@dimen/large_padding" | ||
android:paddingBottom="@dimen/inline_padding"> | ||
|
||
<androidx.constraintlayout.helper.widget.Flow | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
app:constraint_referenced_ids="buttonNegative,buttonPositive" | ||
app:flow_horizontalBias="1" | ||
app:flow_horizontalStyle="packed" | ||
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" | ||
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" | ||
style="?attr/buttonBarPositiveButtonStyle" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
tools:text="Button Positive With Long Text" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.