Skip to content

Commit

Permalink
Lists: confirm deletion, rename from remove to delete
Browse files Browse the repository at this point in the history
Removal sounds like it's just removed from the list of lists, but it is
actually deleted.
  • Loading branch information
UweTrottmann committed Dec 6, 2024
1 parent bbbe754 commit fc8ad9b
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Releases marked with 🧪 (or previously with the "beta" suffix) were released o
### Unreleased

* 🔧 Shows: revert to search symbol for primary button on discover screen.
* 🔧 Lists: ask for confirmation before deleting a list, actually call it delete instead of "just"
remove.

### 2024.5.2 - 2024-12-04 🧪

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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("list_id must be supplied")
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val listTitle = SgRoomDatabase.getInstance(requireContext()).sgListHelper()
.getList(listId)
?.name ?: getString(R.string.unknown)

return MaterialAlertDialogBuilder(requireContext())
.setTitle(requireContext().getString(R.string.confirm_delete, listTitle))
.setPositiveButton(android.R.string.cancel) { _, _ ->
// just dismiss
}
.setNegativeButton(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)
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ class ListManageDialogFragment : AppCompatDialogFragment() {
binding.buttonNegative.isEnabled = false
binding.buttonNegative.setText(R.string.list_remove)
binding.buttonNegative.setOnClickListener {
// remove list and items
ListsTools.removeList(requireContext(), listId)
// ask about removing list
DeleteListDialogFragment.create(listId)
.safeShow(parentFragmentManager, "confirm-delete-list")
dismiss()
}
binding.buttonPositive.setText(android.R.string.ok)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.battlelancer.seriesguide.util.tasks.AddListTask;
import com.battlelancer.seriesguide.util.tasks.ChangeListItemListsTask;
import com.battlelancer.seriesguide.util.tasks.RemoveListItemTask;
import com.battlelancer.seriesguide.util.tasks.RemoveListTask;
import com.battlelancer.seriesguide.util.tasks.DeleteListTask;
import com.battlelancer.seriesguide.util.tasks.RenameListTask;
import com.battlelancer.seriesguide.util.tasks.ReorderListsTask;
import com.uwetrottmann.seriesguide.backend.lists.model.SgListItem;
Expand Down Expand Up @@ -60,8 +60,8 @@ static void renameList(@NonNull Context context, @NonNull String listId,
AsyncTask.THREAD_POOL_EXECUTOR);
}

static void removeList(@NonNull Context context, @NonNull String listId) {
new RemoveListTask(context, listId).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
static void deleteList(@NonNull Context context, @NonNull String listId) {
new DeleteListTask(context, listId).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

static void reorderLists(@NonNull Context context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
import java.io.IOException;

/**
* Task to remove a list.
* Task to delete a list and its items.
*/
public class RemoveListTask extends BaseActionTask {
public class DeleteListTask extends BaseActionTask {

@NonNull protected final String listId;

public RemoveListTask(@NonNull Context context, @NonNull String listId) {
public DeleteListTask(@NonNull Context context, @NonNull String listId) {
super(context);
this.listId = listId;
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
<string name="list_add">Liste hinzufügen</string>
<string name="ack_list_added">Liste hinzugefügt</string>
<string name="list_title_hint">Liste benennen</string>
<string name="list_remove">Liste entfernen</string>
<string name="list_remove">Liste löschen</string>
<string name="list_manage">Liste verwalten</string>
<string name="ack_list_renamed">Liste umbenannt</string>
<string name="ack_list_removed">Liste entfernt</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@
<string name="list_add">Add list</string>
<string name="ack_list_added">List added</string>
<string name="list_title_hint">Name your list</string>
<string name="list_remove">Remove list</string>
<string name="list_remove">Delete list</string>
<string name="list_manage">Manage list</string>
<string name="ack_list_renamed">List renamed</string>
<string name="ack_list_removed">List removed</string>
Expand Down

0 comments on commit fc8ad9b

Please sign in to comment.