diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/requests/lists/DeleteList.java b/mastodon/src/main/java/org/joinmastodon/android/api/requests/lists/DeleteList.java new file mode 100644 index 000000000..64620adac --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/api/requests/lists/DeleteList.java @@ -0,0 +1,10 @@ +package org.joinmastodon.android.api.requests.lists; + +import org.joinmastodon.android.api.MastodonAPIRequest; +import org.joinmastodon.android.model.ListTimeline; + +public class DeleteList extends MastodonAPIRequest { + public DeleteList(String id) { + super(HttpMethod.DELETE, "/lists/" + id, Object.class); + } +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelineFragment.java index 0c1c4a0cc..83a16f300 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelineFragment.java @@ -4,6 +4,7 @@ import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ImageButton; @@ -41,8 +42,22 @@ public class ListTimelineFragment extends StatusListFragment { @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); - // TODO: implement edit, delete - // inflater.inflate(R.menu.list, menu); + inflater.inflate(R.menu.list, menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == R.id.edit) { + + } else if (item.getItemId() == R.id.delete) { + UiUtils.confirmDeleteList(getActivity(), accountID, listID, () -> { + Bundle args = new Bundle(); + args.putString("listID", listID); + setResult(true, args); + Nav.finish(this); + }); + } + return true; } @Override diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelinesFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelinesFragment.java index 2cfd826bf..8c9a18470 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelinesFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelinesFragment.java @@ -20,7 +20,6 @@ import org.joinmastodon.android.api.requests.lists.GetLists; import org.joinmastodon.android.api.requests.lists.RemoveAccountsFromList; import org.joinmastodon.android.model.ListTimeline; import org.joinmastodon.android.ui.M3AlertDialogBuilder; -import org.joinmastodon.android.ui.utils.UiUtils; import org.joinmastodon.android.ui.views.ListTimelineEditor; import java.util.ArrayList; @@ -28,6 +27,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; +import me.grishka.appkit.Nav; import me.grishka.appkit.api.Callback; import me.grishka.appkit.api.ErrorResponse; import me.grishka.appkit.api.SimpleCallback; @@ -36,6 +36,8 @@ import me.grishka.appkit.utils.BindableViewHolder; import me.grishka.appkit.views.UsableRecyclerView; public class ListTimelinesFragment extends BaseRecyclerFragment implements ScrollableToTop { + private static final int LIST_DELETED_RESULT = 987; + private String accountId; private String profileAccountId; private String profileDisplayUsername; @@ -145,7 +147,22 @@ public class ListTimelinesFragment extends BaseRecyclerFragment im } @Override - protected RecyclerView.Adapter getAdapter() { + public void onFragmentResult(int reqCode, boolean listDeleted, Bundle result){ + if (reqCode == LIST_DELETED_RESULT && listDeleted) { + String listID = result.getString("listID"); + + for (int i = 0; i < data.size(); i++) { + if (data.get(i).id.equals(listID)) { + data.remove(i); + adapter.notifyItemRemoved(i); + break; + } + } + } + } + + @Override + protected RecyclerView.Adapter getAdapter() { return adapter = new ListsAdapter(); } @@ -202,7 +219,11 @@ public class ListTimelinesFragment extends BaseRecyclerFragment im @Override public void onClick() { - UiUtils.openListTimeline(getActivity(), accountId, item); + Bundle args=new Bundle(); + args.putString("account", accountId); + args.putString("listID", item.id); + args.putString("listTitle", item.title); + Nav.goForResult(getActivity(), ListTimelineFragment.class, args, LIST_DELETED_RESULT, ListTimelinesFragment.this); } } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java index 39098367f..f2b8c0206 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java @@ -52,6 +52,7 @@ import org.joinmastodon.android.api.requests.accounts.SetAccountMuted; import org.joinmastodon.android.api.requests.accounts.SetDomainBlocked; import org.joinmastodon.android.api.requests.accounts.AuthorizeFollowRequest; import org.joinmastodon.android.api.requests.accounts.RejectFollowRequest; +import org.joinmastodon.android.api.requests.lists.DeleteList; import org.joinmastodon.android.api.requests.notifications.DismissNotification; import org.joinmastodon.android.api.requests.search.GetSearchResults; import org.joinmastodon.android.api.requests.statuses.CreateStatus; @@ -339,14 +340,6 @@ public class UiUtils{ Nav.go((Activity)context, HashtagTimelineFragment.class, args); } - public static void openListTimeline(Context context, String accountID, ListTimeline list){ - Bundle args=new Bundle(); - args.putString("account", accountID); - args.putString("listID", list.id); - args.putString("listTitle", list.title); - Nav.go((Activity)context, ListTimelineFragment.class, args); - } - public static void showConfirmationAlert(Context context, @StringRes int title, @StringRes int message, @StringRes int confirmButton, Runnable onConfirmed){ showConfirmationAlert(context, title, message, confirmButton, 0, onConfirmed); } @@ -541,6 +534,21 @@ public class UiUtils{ ); } + public static void confirmDeleteList(Activity activity, String accountID, String listID, Runnable callback) { + showConfirmationAlert(activity, R.string.sk_delete_list, R.string.sk_delete_list_confirm, R.string.delete, R.drawable.ic_fluent_delete_28_regular, + () -> new DeleteList(listID).setCallback(new Callback<>() { + @Override + public void onSuccess(Object o) { + callback.run(); + } + + @Override + public void onError(ErrorResponse error) { + error.showToast(activity); + } + }).exec(accountID)); + } + public static void setRelationshipToActionButton(Relationship relationship, Button button){ setRelationshipToActionButton(relationship, button, false); } diff --git a/mastodon/src/main/res/values/strings_sk.xml b/mastodon/src/main/res/values/strings_sk.xml index 4a61fbf13..efca7e814 100644 --- a/mastodon/src/main/res/values/strings_sk.xml +++ b/mastodon/src/main/res/values/strings_sk.xml @@ -136,4 +136,6 @@ List members Any followed user No one + Delete list + Are you sure you want to delete this list? \ No newline at end of file