Adds ability to mute from an individual status. Also, all statuses from that user are removed from the timeline on the spot.
This commit is contained in:
parent
852c484d68
commit
fcebbc2bdb
|
@ -271,9 +271,9 @@ public class AccountFragment extends BaseFragment implements AccountActionListen
|
||||||
|
|
||||||
Call<Relationship> call;
|
Call<Relationship> call;
|
||||||
if (!mute) {
|
if (!mute) {
|
||||||
call = api.unblockAccount(id);
|
call = api.unmuteAccount(id);
|
||||||
} else {
|
} else {
|
||||||
call = api.blockAccount(id);
|
call = api.muteAccount(id);
|
||||||
}
|
}
|
||||||
callList.add(call);
|
callList.add(call);
|
||||||
call.enqueue(callback);
|
call.enqueue(callback);
|
||||||
|
|
|
@ -17,4 +17,5 @@ package com.keylesspalace.tusky;
|
||||||
|
|
||||||
interface AdapterItemRemover {
|
interface AdapterItemRemover {
|
||||||
void removeItem(int position);
|
void removeItem(int position);
|
||||||
|
void removeAllByAccountId(String accountId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ import com.keylesspalace.tusky.entity.Status;
|
||||||
import com.squareup.picasso.Picasso;
|
import com.squareup.picasso.Picasso;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
class NotificationsAdapter extends RecyclerView.Adapter implements AdapterItemRemover {
|
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 oldValue = footerState;
|
||||||
footerState = newFooterState;
|
footerState = newFooterState;
|
||||||
if (footerState != oldValue) {
|
if (footerState != oldValue) {
|
||||||
|
@ -210,6 +211,18 @@ class NotificationsAdapter extends RecyclerView.Adapter implements AdapterItemRe
|
||||||
notifyItemChanged(position);
|
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 {
|
interface NotificationActionListener {
|
||||||
void onViewAccount(String id);
|
void onViewAccount(String id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ import java.util.List;
|
||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
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
|
/* 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
|
* awkward name. TimelineFragment and NotificationFragment have significant overlap but the nature
|
||||||
|
@ -163,18 +164,26 @@ public abstract class SFragment extends BaseFragment {
|
||||||
callList.add(call);
|
callList.add(call);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void mute(String id) {
|
||||||
|
Call<Relationship> call = getApi().muteAccount(id);
|
||||||
|
call.enqueue(new Callback<Relationship>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<Relationship> call, Response<Relationship> response) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<Relationship> call, Throwable t) {}
|
||||||
|
});
|
||||||
|
callList.add(call);
|
||||||
|
}
|
||||||
|
|
||||||
private void block(String id) {
|
private void block(String id) {
|
||||||
Call<Relationship> call = getApi().blockAccount(id);
|
Call<Relationship> call = getApi().blockAccount(id);
|
||||||
call.enqueue(new Callback<Relationship>() {
|
call.enqueue(new Callback<Relationship>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<Relationship> call, retrofit2.Response<Relationship> response) {
|
public void onResponse(Call<Relationship> call, retrofit2.Response<Relationship> response) {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Call<Relationship> call, Throwable t) {
|
public void onFailure(Call<Relationship> call, Throwable t) {}
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
callList.add(call);
|
callList.add(call);
|
||||||
}
|
}
|
||||||
|
@ -183,14 +192,10 @@ public abstract class SFragment extends BaseFragment {
|
||||||
Call<ResponseBody> call = getApi().deleteStatus(id);
|
Call<ResponseBody> call = getApi().deleteStatus(id);
|
||||||
call.enqueue(new Callback<ResponseBody>() {
|
call.enqueue(new Callback<ResponseBody>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) {
|
public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Call<ResponseBody> call, Throwable t) {
|
public void onFailure(Call<ResponseBody> call, Throwable t) {}
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
callList.add(call);
|
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)));
|
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_status_link_to)));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
case R.id.status_mute: {
|
||||||
|
mute(accountId);
|
||||||
|
adapter.removeAllByAccountId(accountId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
case R.id.status_block: {
|
case R.id.status_block: {
|
||||||
block(accountId);
|
block(accountId);
|
||||||
|
adapter.removeAllByAccountId(accountId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case R.id.status_report: {
|
case R.id.status_report: {
|
||||||
|
|
|
@ -65,6 +65,18 @@ class ThreadAdapter extends RecyclerView.Adapter implements AdapterItemRemover {
|
||||||
notifyItemRemoved(position);
|
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) {
|
int setStatus(Status status) {
|
||||||
if (statuses.size() > 0 && statuses.get(statusIndex).equals(status)) {
|
if (statuses.size() > 0 && statuses.get(statusIndex).equals(status)) {
|
||||||
// Do not add this status on refresh, it's already in there.
|
// Do not add this status on refresh, it's already in there.
|
||||||
|
|
|
@ -79,7 +79,7 @@ class TimelineAdapter extends RecyclerView.Adapter implements AdapterItemRemover
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFooterState(FooterState newFooterState) {
|
void setFooterState(FooterState newFooterState) {
|
||||||
FooterState oldValue = footerState;
|
FooterState oldValue = footerState;
|
||||||
footerState = newFooterState;
|
footerState = newFooterState;
|
||||||
if (footerState != oldValue) {
|
if (footerState != oldValue) {
|
||||||
|
@ -142,6 +142,18 @@ class TimelineAdapter extends RecyclerView.Adapter implements AdapterItemRemover
|
||||||
notifyItemRemoved(position);
|
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
|
@Nullable
|
||||||
Status getItem(int position) {
|
Status getItem(int position) {
|
||||||
if (position >= 0 && position < statuses.size()) {
|
if (position >= 0 && position < statuses.size()) {
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
android:title="@string/status_share_content"/>
|
android:title="@string/status_share_content"/>
|
||||||
</menu>
|
</menu>
|
||||||
</item>
|
</item>
|
||||||
|
<item android:title="@string/action_mute"
|
||||||
|
android:id="@+id/status_mute" />
|
||||||
<item android:title="@string/action_block"
|
<item android:title="@string/action_block"
|
||||||
android:id="@+id/status_block" />
|
android:id="@+id/status_block" />
|
||||||
<item android:title="@string/action_report"
|
<item android:title="@string/action_report"
|
||||||
|
|
Loading…
Reference in New Issue