From 0da98f4f6743b03f02ca7d33d48b5b87730c6027 Mon Sep 17 00:00:00 2001 From: Vavassor Date: Fri, 21 Apr 2017 20:58:44 -0400 Subject: [PATCH] Adds ability to mute from an individual status. Also, all statuses from that user are removed from the timeline on the spot. --- .../keylesspalace/tusky/AccountFragment.java | 4 +-- .../tusky/AdapterItemRemover.java | 1 + .../tusky/NotificationsAdapter.java | 15 +++++++- .../com/keylesspalace/tusky/SFragment.java | 35 ++++++++++++------- .../keylesspalace/tusky/ThreadAdapter.java | 12 +++++++ .../keylesspalace/tusky/TimelineAdapter.java | 14 +++++++- app/src/main/res/menu/status_more.xml | 2 ++ 7 files changed, 67 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountFragment.java b/app/src/main/java/com/keylesspalace/tusky/AccountFragment.java index 6375bba7..ecc63a34 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/AccountFragment.java @@ -271,9 +271,9 @@ public class AccountFragment extends BaseFragment implements AccountActionListen Call call; if (!mute) { - call = api.unblockAccount(id); + call = api.unmuteAccount(id); } else { - call = api.blockAccount(id); + call = api.muteAccount(id); } callList.add(call); call.enqueue(callback); diff --git a/app/src/main/java/com/keylesspalace/tusky/AdapterItemRemover.java b/app/src/main/java/com/keylesspalace/tusky/AdapterItemRemover.java index 634935ff..aff7b033 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AdapterItemRemover.java +++ b/app/src/main/java/com/keylesspalace/tusky/AdapterItemRemover.java @@ -17,4 +17,5 @@ package com.keylesspalace.tusky; interface AdapterItemRemover { void removeItem(int position); + void removeAllByAccountId(String accountId); } diff --git a/app/src/main/java/com/keylesspalace/tusky/NotificationsAdapter.java b/app/src/main/java/com/keylesspalace/tusky/NotificationsAdapter.java index 64ecb722..2376469b 100644 --- a/app/src/main/java/com/keylesspalace/tusky/NotificationsAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/NotificationsAdapter.java @@ -34,6 +34,7 @@ import com.keylesspalace.tusky.entity.Status; import com.squareup.picasso.Picasso; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; class NotificationsAdapter extends RecyclerView.Adapter implements AdapterItemRemover { @@ -62,7 +63,7 @@ class NotificationsAdapter extends RecyclerView.Adapter implements AdapterItemRe } - public void setFooterState(FooterState newFooterState) { + void setFooterState(FooterState newFooterState) { FooterState oldValue = footerState; footerState = newFooterState; if (footerState != oldValue) { @@ -210,6 +211,18 @@ class NotificationsAdapter extends RecyclerView.Adapter implements AdapterItemRe notifyItemChanged(position); } + public void removeAllByAccountId(String id) { + for (int i = 0; i < notifications.size();) { + Notification notification = notifications.get(i); + if (id.equals(notification.account.id)) { + notifications.remove(i); + notifyItemRemoved(i); + } else { + i += 1; + } + } + } + interface NotificationActionListener { void onViewAccount(String id); } diff --git a/app/src/main/java/com/keylesspalace/tusky/SFragment.java b/app/src/main/java/com/keylesspalace/tusky/SFragment.java index b810468a..482d3a3b 100644 --- a/app/src/main/java/com/keylesspalace/tusky/SFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/SFragment.java @@ -37,6 +37,7 @@ import java.util.List; import okhttp3.ResponseBody; import retrofit2.Call; import retrofit2.Callback; +import retrofit2.Response; /* Note from Andrew on Jan. 22, 2017: This class is a design problem for me, so I left it with an * awkward name. TimelineFragment and NotificationFragment have significant overlap but the nature @@ -163,18 +164,26 @@ public abstract class SFragment extends BaseFragment { callList.add(call); } + private void mute(String id) { + Call call = getApi().muteAccount(id); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) {} + + @Override + public void onFailure(Call call, Throwable t) {} + }); + callList.add(call); + } + private void block(String id) { Call call = getApi().blockAccount(id); call.enqueue(new Callback() { @Override - public void onResponse(Call call, retrofit2.Response response) { - - } + public void onResponse(Call call, retrofit2.Response response) {} @Override - public void onFailure(Call call, Throwable t) { - - } + public void onFailure(Call call, Throwable t) {} }); callList.add(call); } @@ -183,14 +192,10 @@ public abstract class SFragment extends BaseFragment { Call call = getApi().deleteStatus(id); call.enqueue(new Callback() { @Override - public void onResponse(Call call, retrofit2.Response response) { - - } + public void onResponse(Call call, retrofit2.Response response) {} @Override - public void onFailure(Call call, Throwable t) { - - } + public void onFailure(Call call, Throwable t) {} }); callList.add(call); } @@ -235,8 +240,14 @@ public abstract class SFragment extends BaseFragment { startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_status_link_to))); return true; } + case R.id.status_mute: { + mute(accountId); + adapter.removeAllByAccountId(accountId); + return true; + } case R.id.status_block: { block(accountId); + adapter.removeAllByAccountId(accountId); return true; } case R.id.status_report: { diff --git a/app/src/main/java/com/keylesspalace/tusky/ThreadAdapter.java b/app/src/main/java/com/keylesspalace/tusky/ThreadAdapter.java index 7af6d13f..afa407f8 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ThreadAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/ThreadAdapter.java @@ -65,6 +65,18 @@ class ThreadAdapter extends RecyclerView.Adapter implements AdapterItemRemover { notifyItemRemoved(position); } + public void removeAllByAccountId(String accountId) { + for (int i = 0; i < statuses.size();) { + Status status = statuses.get(i); + if (accountId.equals(status.account.id)) { + statuses.remove(i); + notifyItemRemoved(i); + } else { + i += 1; + } + } + } + int setStatus(Status status) { if (statuses.size() > 0 && statuses.get(statusIndex).equals(status)) { // Do not add this status on refresh, it's already in there. diff --git a/app/src/main/java/com/keylesspalace/tusky/TimelineAdapter.java b/app/src/main/java/com/keylesspalace/tusky/TimelineAdapter.java index a6c1367e..d2dd0b09 100644 --- a/app/src/main/java/com/keylesspalace/tusky/TimelineAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/TimelineAdapter.java @@ -79,7 +79,7 @@ class TimelineAdapter extends RecyclerView.Adapter implements AdapterItemRemover } } - public void setFooterState(FooterState newFooterState) { + void setFooterState(FooterState newFooterState) { FooterState oldValue = footerState; footerState = newFooterState; if (footerState != oldValue) { @@ -142,6 +142,18 @@ class TimelineAdapter extends RecyclerView.Adapter implements AdapterItemRemover notifyItemRemoved(position); } + public void removeAllByAccountId(String accountId) { + for (int i = 0; i < statuses.size();) { + Status status = statuses.get(i); + if (accountId.equals(status.account.id)) { + statuses.remove(i); + notifyItemRemoved(i); + } else { + i += 1; + } + } + } + @Nullable Status getItem(int position) { if (position >= 0 && position < statuses.size()) { diff --git a/app/src/main/res/menu/status_more.xml b/app/src/main/res/menu/status_more.xml index 48159d7b..95581c8f 100644 --- a/app/src/main/res/menu/status_more.xml +++ b/app/src/main/res/menu/status_more.xml @@ -12,6 +12,8 @@ android:title="@string/status_share_content"/> +