Block and mute lists now remove the entries when you unmute/unblock a user, with a short popup to undo if it's unintentional. Just for clearer feedback.

main
Vavassor 8 years ago
parent c6cf2d034a
commit a299473dba
  1. 19
      app/src/main/java/com/keylesspalace/tusky/AccountAdapter.java
  2. 43
      app/src/main/java/com/keylesspalace/tusky/AccountFragment.java
  3. 27
      app/src/main/java/com/keylesspalace/tusky/BlocksAdapter.java
  4. 15
      app/src/main/java/com/keylesspalace/tusky/MutesAdapter.java
  5. 3
      app/src/main/res/values/strings.xml

@ -15,6 +15,7 @@
package com.keylesspalace.tusky;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import com.keylesspalace.tusky.entity.Account;
@ -64,6 +65,24 @@ abstract class AccountAdapter extends RecyclerView.Adapter {
notifyItemRangeInserted(end, newAccounts.size());
}
@Nullable
Account removeItem(int position) {
if (position < 0 || position >= accountList.size()) {
return null;
}
Account account = accountList.remove(position);
notifyItemRemoved(position);
return account;
}
void addItem(Account account, int position) {
if (position < 0 || position > accountList.size()) {
return;
}
accountList.add(position, account);
notifyItemInserted(position);
}
public Account getItem(int position) {
if (position >= 0 && position < accountList.size()) {
return accountList.get(position);

@ -20,6 +20,7 @@ import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
@ -257,7 +258,7 @@ public class AccountFragment extends BaseFragment implements AccountActionListen
@Override
public void onResponse(Call<Relationship> call, Response<Relationship> response) {
if (response.isSuccessful()) {
onMuteSuccess(mute, position);
onMuteSuccess(mute, id, position);
} else {
onMuteFailure(mute, id);
}
@ -279,9 +280,22 @@ public class AccountFragment extends BaseFragment implements AccountActionListen
call.enqueue(callback);
}
private void onMuteSuccess(boolean muted, int position) {
MutesAdapter mutesAdapter = (MutesAdapter) adapter;
mutesAdapter.setMuted(muted, position);
private void onMuteSuccess(boolean muted, final String id, final int position) {
if (muted) {
return;
}
final MutesAdapter mutesAdapter = (MutesAdapter) adapter;
final Account unmutedUser = mutesAdapter.removeItem(position);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
mutesAdapter.addItem(unmutedUser, position);
onMute(true, id, position);
}
};
Snackbar.make(recyclerView, R.string.confirmation_unmuted, Snackbar.LENGTH_LONG)
.setAction(R.string.action_undo, listener)
.show();
}
private void onMuteFailure(boolean mute, String id) {
@ -307,7 +321,7 @@ public class AccountFragment extends BaseFragment implements AccountActionListen
@Override
public void onResponse(Call<Relationship> call, Response<Relationship> response) {
if (response.isSuccessful()) {
onBlockSuccess(block, position);
onBlockSuccess(block, id, position);
} else {
onBlockFailure(block, id);
}
@ -329,9 +343,22 @@ public class AccountFragment extends BaseFragment implements AccountActionListen
call.enqueue(cb);
}
private void onBlockSuccess(boolean blocked, int position) {
BlocksAdapter blocksAdapter = (BlocksAdapter) adapter;
blocksAdapter.setBlocked(blocked, position);
private void onBlockSuccess(boolean blocked, final String id, final int position) {
if (blocked) {
return;
}
final BlocksAdapter blocksAdapter = (BlocksAdapter) adapter;
final Account unblockedUser = blocksAdapter.removeItem(position);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
blocksAdapter.addItem(unblockedUser, position);
onBlock(true, id, position);
}
};
Snackbar.make(recyclerView, R.string.confirmation_unblocked, Snackbar.LENGTH_LONG)
.setAction(R.string.action_undo, listener)
.show();
}
private void onBlockFailure(boolean block, String id) {

@ -15,6 +15,7 @@
package com.keylesspalace.tusky;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
@ -26,9 +27,6 @@ import com.keylesspalace.tusky.entity.Account;
import com.pkmmte.view.CircularImageView;
import com.squareup.picasso.Picasso;
import java.util.HashSet;
import java.util.Set;
import butterknife.BindView;
import butterknife.ButterKnife;
@ -36,11 +34,8 @@ class BlocksAdapter extends AccountAdapter {
private static final int VIEW_TYPE_BLOCKED_USER = 0;
private static final int VIEW_TYPE_FOOTER = 1;
private Set<Integer> unblockedAccountPositions;
BlocksAdapter(AccountActionListener accountActionListener) {
super(accountActionListener);
unblockedAccountPositions = new HashSet<>();
}
@Override
@ -65,8 +60,7 @@ class BlocksAdapter extends AccountAdapter {
if (position < accountList.size()) {
BlockedUserViewHolder holder = (BlockedUserViewHolder) viewHolder;
holder.setupWithAccount(accountList.get(position));
boolean blocked = !unblockedAccountPositions.contains(position);
holder.setupActionListener(accountActionListener, blocked, position);
holder.setupActionListener(accountActionListener, true);
}
}
@ -79,15 +73,6 @@ class BlocksAdapter extends AccountAdapter {
}
}
void setBlocked(boolean blocked, int position) {
if (blocked) {
unblockedAccountPositions.remove(position);
} else {
unblockedAccountPositions.add(position);
}
notifyItemChanged(position);
}
static class BlockedUserViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.blocked_user_avatar) CircularImageView avatar;
@BindView(R.id.blocked_user_username) TextView username;
@ -114,12 +99,14 @@ class BlocksAdapter extends AccountAdapter {
.into(avatar);
}
void setupActionListener(final AccountActionListener listener, final boolean blocked,
final int position) {
void setupActionListener(final AccountActionListener listener, final boolean blocked) {
unblock.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onBlock(!blocked, id, position);
int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION) {
listener.onBlock(!blocked, id, position);
}
}
});
avatar.setOnClickListener(new View.OnClickListener() {

@ -21,11 +21,8 @@ class MutesAdapter extends AccountAdapter {
private static final int VIEW_TYPE_MUTED_USER = 0;
private static final int VIEW_TYPE_FOOTER = 1;
private Set<Integer> unmutedAccountPositions;
MutesAdapter(AccountActionListener accountActionListener) {
super(accountActionListener);
unmutedAccountPositions = new HashSet<>();
}
@Override
@ -50,8 +47,7 @@ class MutesAdapter extends AccountAdapter {
if (position < accountList.size()) {
MutedUserViewHolder holder = (MutedUserViewHolder) viewHolder;
holder.setupWithAccount(accountList.get(position));
boolean muted = !unmutedAccountPositions.contains(position);
holder.setupActionListener(accountActionListener, muted, position);
holder.setupActionListener(accountActionListener, true, position);
}
}
@ -64,15 +60,6 @@ class MutesAdapter extends AccountAdapter {
}
}
void setMuted(boolean muted, int position) {
if (muted) {
unmutedAccountPositions.remove(position);
} else {
unmutedAccountPositions.add(position);
}
notifyItemChanged(position);
}
static class MutedUserViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.muted_user_avatar) CircularImageView avatar;
@BindView(R.id.muted_user_username) TextView username;

@ -94,6 +94,7 @@
<string name="action_clear">Clear</string>
<string name="action_save">Save</string>
<string name="action_edit_profile">Edit profile</string>
<string name="action_undo">Undo</string>
<string name="send_status_link_to">Share toot URL to…</string>
<string name="send_status_content_to">Share toot to…</string>
@ -102,6 +103,8 @@
<string name="confirmation_send">Toot!</string>
<string name="confirmation_reported">Sent!</string>
<string name="confirmation_unblocked">User unblocked</string>
<string name="confirmation_unmuted">User unmuted</string>
<string name="hint_domain">Which instance?</string>
<string name="hint_compose">What\'s happening?</string>

Loading…
Cancel
Save