Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
implement deleting lists
Browse files Browse the repository at this point in the history
re: #30
  • Loading branch information
sk22 committed Jan 10, 2023
1 parent 2945955 commit cbf426b
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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<Object> {
public DeleteList(String id) {
super(HttpMethod.DELETE, "/lists/" + id, Object.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand Down Expand Up @@ -41,8 +42,22 @@ public void onAttach(Activity activity){
@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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.joinmastodon.android.fragments;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
Expand Down Expand Up @@ -28,14 +29,18 @@
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;
import me.grishka.appkit.fragments.AppKitFragment;
import me.grishka.appkit.fragments.BaseRecyclerFragment;
import me.grishka.appkit.utils.BindableViewHolder;
import me.grishka.appkit.views.UsableRecyclerView;

public class ListTimelinesFragment extends BaseRecyclerFragment<ListTimeline> implements ScrollableToTop {
private static final int LIST_DELETED_RESULT = 987;

private String accountId;
private String profileAccountId;
private String profileDisplayUsername;
Expand Down Expand Up @@ -145,7 +150,22 @@ public void onSuccess(List<ListTimeline> allLists) {
}

@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<ListViewHolder> getAdapter() {
return adapter = new ListsAdapter();
}

Expand Down Expand Up @@ -202,7 +222,11 @@ private void onClickToggle(View view) {

@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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
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;
Expand Down Expand Up @@ -339,14 +340,6 @@ public static void openHashtagTimeline(Context context, String accountID, String
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);
}
Expand Down Expand Up @@ -541,6 +534,21 @@ public void onError(ErrorResponse error) {
);
}

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);
}
Expand Down
2 changes: 2 additions & 0 deletions mastodon/src/main/res/values/strings_sk.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,6 @@
<string name="sk_list_replies_policy_list">List members</string>
<string name="sk_list_replies_policy_followed">Any followed user</string>
<string name="sk_list_replies_policy_none">No one</string>
<string name="sk_delete_list">Delete list</string>
<string name="sk_delete_list_confirm">Are you sure you want to delete this list?</string>
</resources>

0 comments on commit cbf426b

Please sign in to comment.