Adds a list of muted users.

This commit is contained in:
Vavassor 2017-04-21 19:02:04 -04:00
parent 5e155badf5
commit 852c484d68
9 changed files with 310 additions and 10 deletions

View File

@ -17,5 +17,6 @@ package com.keylesspalace.tusky;
interface AccountActionListener { interface AccountActionListener {
void onViewAccount(String id); void onViewAccount(String id);
void onMute(final boolean mute, final String id, final int position);
void onBlock(final boolean block, final String id, final int position); void onBlock(final boolean block, final String id, final int position);
} }

View File

@ -61,7 +61,7 @@ public class AccountFragment extends BaseFragment implements AccountActionListen
public static AccountFragment newInstance(Type type) { public static AccountFragment newInstance(Type type) {
Bundle arguments = new Bundle(); Bundle arguments = new Bundle();
AccountFragment fragment = new AccountFragment(); AccountFragment fragment = new AccountFragment();
arguments.putString("type", type.name()); arguments.putSerializable("type", type);
fragment.setArguments(arguments); fragment.setArguments(arguments);
return fragment; return fragment;
} }
@ -69,7 +69,7 @@ public class AccountFragment extends BaseFragment implements AccountActionListen
public static AccountFragment newInstance(Type type, String accountId) { public static AccountFragment newInstance(Type type, String accountId) {
Bundle arguments = new Bundle(); Bundle arguments = new Bundle();
AccountFragment fragment = new AccountFragment(); AccountFragment fragment = new AccountFragment();
arguments.putString("type", type.name()); arguments.putSerializable("type", type);
arguments.putString("accountId", accountId); arguments.putString("accountId", accountId);
fragment.setArguments(arguments); fragment.setArguments(arguments);
return fragment; return fragment;
@ -79,7 +79,7 @@ public class AccountFragment extends BaseFragment implements AccountActionListen
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Bundle arguments = getArguments(); Bundle arguments = getArguments();
type = Type.valueOf(arguments.getString("type")); type = (Type) arguments.getSerializable("type");
accountId = arguments.getString("accountId"); accountId = arguments.getString("accountId");
api = null; api = null;
} }
@ -105,6 +105,8 @@ public class AccountFragment extends BaseFragment implements AccountActionListen
scrollListener = null; scrollListener = null;
if (type == Type.BLOCKS) { if (type == Type.BLOCKS) {
adapter = new BlocksAdapter(this); adapter = new BlocksAdapter(this);
} else if (type == Type.MUTES) {
adapter = new MutesAdapter(this);
} else { } else {
adapter = new FollowAdapter(this); adapter = new FollowAdapter(this);
} }
@ -242,6 +244,56 @@ public class AccountFragment extends BaseFragment implements AccountActionListen
startActivity(intent); startActivity(intent);
} }
public void onMute(final boolean mute, final String id, final int position) {
if (api == null) {
/* If somehow an unmute button is clicked after onCreateView but before
* onActivityCreated, then this would get called with a null api object, so this eats
* that input. */
Log.d(TAG, "MastodonAPI isn't initialised so this mute can't occur.");
return;
}
Callback<Relationship> callback = new Callback<Relationship>() {
@Override
public void onResponse(Call<Relationship> call, Response<Relationship> response) {
if (response.isSuccessful()) {
onMuteSuccess(mute, position);
} else {
onMuteFailure(mute, id);
}
}
@Override
public void onFailure(Call<Relationship> call, Throwable t) {
onMuteFailure(mute, id);
}
};
Call<Relationship> call;
if (!mute) {
call = api.unblockAccount(id);
} else {
call = api.blockAccount(id);
}
callList.add(call);
call.enqueue(callback);
}
private void onMuteSuccess(boolean muted, int position) {
MutesAdapter mutesAdapter = (MutesAdapter) adapter;
mutesAdapter.setMuted(muted, position);
}
private void onMuteFailure(boolean mute, String id) {
String verb;
if (mute) {
verb = "mute";
} else {
verb = "unmute";
}
Log.e(TAG, String.format("Failed to %s account id %s", verb, id));
}
public void onBlock(final boolean block, final String id, final int position) { public void onBlock(final boolean block, final String id, final int position) {
if (api == null) { if (api == null) {
/* If somehow an unblock button is clicked after onCreateView but before /* If somehow an unblock button is clicked after onCreateView but before
@ -293,7 +345,7 @@ public class AccountFragment extends BaseFragment implements AccountActionListen
} }
private boolean jumpToTopAllowed() { private boolean jumpToTopAllowed() {
return type != Type.BLOCKS; return type == Type.FOLLOWS || type == Type.FOLLOWERS;
} }
private void jumpToTop() { private void jumpToTop() {

View File

@ -15,6 +15,7 @@
package com.keylesspalace.tusky; package com.keylesspalace.tusky;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
@ -24,22 +25,44 @@ import android.support.v7.widget.Toolbar;
import android.view.MenuItem; import android.view.MenuItem;
public class BlocksActivity extends BaseActivity { public class BlocksActivity extends BaseActivity {
enum Type {
BLOCKS,
MUTES
}
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_blocks); setContentView(R.layout.activity_blocks);
Type type;
Intent intent = getIntent();
if (intent != null) {
type = (Type) intent.getSerializableExtra("type");
} else {
type = Type.BLOCKS;
}
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
ActionBar bar = getSupportActionBar(); ActionBar bar = getSupportActionBar();
if (bar != null) { if (bar != null) {
bar.setTitle(getString(R.string.title_blocks)); switch (type) {
case MUTES: { bar.setTitle(getString(R.string.title_mutes)); break; }
case BLOCKS: { bar.setTitle(getString(R.string.title_blocks)); break; }
}
bar.setDisplayHomeAsUpEnabled(true); bar.setDisplayHomeAsUpEnabled(true);
bar.setDisplayShowHomeEnabled(true); bar.setDisplayShowHomeEnabled(true);
} }
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
Fragment fragment = AccountFragment.newInstance(AccountFragment.Type.BLOCKS); AccountFragment.Type fragmentType;
switch (type) {
case MUTES: { fragmentType = AccountFragment.Type.MUTES; break; }
default:
case BLOCKS: { fragmentType = AccountFragment.Type.BLOCKS; break; }
}
Fragment fragment = AccountFragment.newInstance(fragmentType);
fragmentTransaction.add(R.id.fragment_container, fragment); fragmentTransaction.add(R.id.fragment_container, fragment);
fragmentTransaction.commit(); fragmentTransaction.commit();
} }

View File

@ -20,6 +20,7 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.PersistableBundle; import android.os.PersistableBundle;
@ -27,6 +28,7 @@ import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.TabLayout; import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.Spanned; import android.text.Spanned;
@ -41,10 +43,12 @@ import com.arlib.floatingsearchview.suggestions.SearchSuggestionsAdapter;
import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion; import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion;
import com.keylesspalace.tusky.entity.Account; import com.keylesspalace.tusky.entity.Account;
import com.mikepenz.google_material_typeface_library.GoogleMaterial; import com.mikepenz.google_material_typeface_library.GoogleMaterial;
import com.mikepenz.iconics.typeface.GenericFont;
import com.mikepenz.materialdrawer.AccountHeader; import com.mikepenz.materialdrawer.AccountHeader;
import com.mikepenz.materialdrawer.AccountHeaderBuilder; import com.mikepenz.materialdrawer.AccountHeaderBuilder;
import com.mikepenz.materialdrawer.Drawer; import com.mikepenz.materialdrawer.Drawer;
import com.mikepenz.materialdrawer.DrawerBuilder; import com.mikepenz.materialdrawer.DrawerBuilder;
import com.mikepenz.materialdrawer.icons.MaterialDrawerFont;
import com.mikepenz.materialdrawer.model.DividerDrawerItem; import com.mikepenz.materialdrawer.model.DividerDrawerItem;
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem; import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
import com.mikepenz.materialdrawer.model.ProfileDrawerItem; import com.mikepenz.materialdrawer.model.ProfileDrawerItem;
@ -268,6 +272,9 @@ public class MainActivity extends BaseActivity {
} }
}); });
Drawable muteDrawable = ContextCompat.getDrawable(this, R.drawable.ic_mute_24dp);
ThemeUtils.setDrawableTint(this, muteDrawable, R.attr.toolbar_icon_tint);
drawer = new DrawerBuilder() drawer = new DrawerBuilder()
.withActivity(this) .withActivity(this)
//.withToolbar(toolbar) //.withToolbar(toolbar)
@ -277,10 +284,11 @@ public class MainActivity extends BaseActivity {
.addDrawerItems( .addDrawerItems(
new PrimaryDrawerItem().withIdentifier(0).withName(getString(R.string.action_edit_profile)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_person), new PrimaryDrawerItem().withIdentifier(0).withName(getString(R.string.action_edit_profile)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_person),
new PrimaryDrawerItem().withIdentifier(1).withName(getString(R.string.action_view_favourites)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_star), new PrimaryDrawerItem().withIdentifier(1).withName(getString(R.string.action_view_favourites)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_star),
new PrimaryDrawerItem().withIdentifier(2).withName(getString(R.string.action_view_blocks)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_block), new PrimaryDrawerItem().withIdentifier(2).withName(getString(R.string.action_view_mutes)).withSelectable(false).withIcon(muteDrawable),
new PrimaryDrawerItem().withIdentifier(3).withName(getString(R.string.action_view_blocks)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_block),
new DividerDrawerItem(), new DividerDrawerItem(),
new SecondaryDrawerItem().withIdentifier(3).withName(getString(R.string.action_view_preferences)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_settings), new SecondaryDrawerItem().withIdentifier(4).withName(getString(R.string.action_view_preferences)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_settings),
new SecondaryDrawerItem().withIdentifier(4).withName(getString(R.string.action_logout)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_exit_to_app) new SecondaryDrawerItem().withIdentifier(5).withName(getString(R.string.action_logout)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_exit_to_app)
) )
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override @Override
@ -296,11 +304,16 @@ public class MainActivity extends BaseActivity {
startActivity(intent); startActivity(intent);
} else if (drawerItemIdentifier == 2) { } else if (drawerItemIdentifier == 2) {
Intent intent = new Intent(MainActivity.this, BlocksActivity.class); Intent intent = new Intent(MainActivity.this, BlocksActivity.class);
intent.putExtra("type", BlocksActivity.Type.MUTES);
startActivity(intent); startActivity(intent);
} else if (drawerItemIdentifier == 3) { } else if (drawerItemIdentifier == 3) {
Intent intent = new Intent(MainActivity.this, PreferencesActivity.class); Intent intent = new Intent(MainActivity.this, BlocksActivity.class);
intent.putExtra("type", BlocksActivity.Type.BLOCKS);
startActivity(intent); startActivity(intent);
} else if (drawerItemIdentifier == 4) { } else if (drawerItemIdentifier == 4) {
Intent intent = new Intent(MainActivity.this, PreferencesActivity.class);
startActivity(intent);
} else if (drawerItemIdentifier == 5) {
logout(); logout();
} }
} }

View File

@ -0,0 +1,118 @@
package com.keylesspalace.tusky;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;
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;
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
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
switch (viewType) {
default:
case VIEW_TYPE_MUTED_USER: {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_muted_user, parent, false);
return new MutesAdapter.MutedUserViewHolder(view);
}
case VIEW_TYPE_FOOTER: {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_footer, parent, false);
return new FooterViewHolder(view);
}
}
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
if (position < accountList.size()) {
MutedUserViewHolder holder = (MutedUserViewHolder) viewHolder;
holder.setupWithAccount(accountList.get(position));
boolean muted = !unmutedAccountPositions.contains(position);
holder.setupActionListener(accountActionListener, muted, position);
}
}
@Override
public int getItemViewType(int position) {
if (position == accountList.size()) {
return VIEW_TYPE_FOOTER;
} else {
return VIEW_TYPE_MUTED_USER;
}
}
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;
@BindView(R.id.muted_user_display_name) TextView displayName;
@BindView(R.id.muted_user_unmute) ImageButton unmute;
private String id;
MutedUserViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
void setupWithAccount(Account account) {
id = account.id;
displayName.setText(account.getDisplayName());
String format = username.getContext().getString(R.string.status_username_format);
String formattedUsername = String.format(format, account.username);
username.setText(formattedUsername);
Picasso.with(avatar.getContext())
.load(account.avatar)
.error(R.drawable.avatar_error)
.placeholder(R.drawable.avatar_default)
.into(avatar);
}
void setupActionListener(final AccountActionListener listener, final boolean muted,
final int position) {
unmute.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onMute(!muted, id, position);
}
});
avatar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onViewAccount(id);
}
});
}
}
}

View File

@ -0,0 +1,11 @@
<vector android:height="24dp" android:viewportHeight="35.43307"
android:viewportWidth="35.43307" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillAlpha="1" android:fillColor="#ffffff"
android:pathData="m17.72,3.54 l-8.86,8.86 -7.09,0 0,10.63 7.09,0 8.86,8.86z"
android:strokeAlpha="1" android:strokeColor="#00000000"
android:strokeLineCap="square" android:strokeLineJoin="miter" android:strokeWidth="1.54400003"/>
<path android:fillAlpha="1" android:fillColor="#ffffff"
android:pathData="m22.86,11.45 l-2.51,2.51 3.76,3.76 -3.76,3.76 2.51,2.51 3.76,-3.76 3.76,3.76 2.5,-2.51 -3.76,-3.76 3.76,-3.76 -2.5,-2.51 -3.76,3.76 -3.76,-3.76z"
android:strokeAlpha="1" android:strokeColor="#00000000"
android:strokeLineCap="square" android:strokeLineJoin="miter" android:strokeWidth="1.54400003"/>
</vector>

View File

@ -0,0 +1,19 @@
<vector android:height="24dp" android:viewportHeight="35.43307"
android:viewportWidth="35.43307" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillAlpha="1" android:fillColor="#ffffff"
android:pathData="m17.72,3.54 l-8.86,8.86 -7.09,0 0,10.63 7.09,0 8.86,8.86z"
android:strokeAlpha="1" android:strokeColor="#00000000"
android:strokeLineCap="square" android:strokeLineJoin="miter" android:strokeWidth="1.54400003"/>
<path android:fillAlpha="1" android:fillColor="#00000000"
android:pathData="m21.47,13.96a5.31,5.31 0,0 1,1.56 3.76,5.31 5.31,0 0,1 -1.56,3.76"
android:strokeAlpha="1" android:strokeColor="#ffffff"
android:strokeLineCap="square" android:strokeLineJoin="miter" android:strokeWidth="2.65748031"/>
<path android:fillAlpha="1" android:fillColor="#00000000"
android:pathData="m28.99,6.44a15.94,15.94 0,0 1,4.67 11.27,15.94 15.94,0 0,1 -4.67,11.27"
android:strokeAlpha="1" android:strokeColor="#ffffff"
android:strokeLineCap="square" android:strokeLineJoin="miter" android:strokeWidth="2.65748031"/>
<path android:fillAlpha="1" android:fillColor="#00000000"
android:pathData="m25.23,10.2a10.63,10.63 0,0 1,3.11 7.52,10.63 10.63,0 0,1 -3.11,7.52"
android:strokeAlpha="1" android:strokeColor="#ffffff"
android:strokeLineCap="square" android:strokeLineJoin="miter" android:strokeWidth="2.65748031"/>
</vector>

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="72dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:gravity="center_vertical">
<com.pkmmte.view.CircularImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:id="@+id/muted_user_avatar"
android:layout_alignParentLeft="true"
android:layout_marginRight="24dp"
android:layout_centerVertical="true"/>
<ImageButton
app:srcCompat="@drawable/ic_unmute_24dp"
android:layout_width="24dp"
android:layout_height="24dp"
android:id="@+id/muted_user_unmute"
android:layout_gravity="center_vertical"
style="?attr/image_button_style"
android:layout_alignParentRight="true"
android:layout_marginLeft="16dp"
android:layout_centerVertical="true"
android:contentDescription="@string/action_unmute" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical"
android:layout_toRightOf="@id/muted_user_avatar"
android:layout_toLeftOf="@id/muted_user_unmute">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/muted_user_display_name"
android:text="Display name"
android:maxLines="1"
android:ellipsize="end"
android:textSize="16sp"
android:textColor="?android:textColorPrimary"
android:textStyle="normal|bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="\@username"
android:maxLines="1"
android:ellipsize="end"
android:textSize="14sp"
android:id="@+id/muted_user_username"
android:textColor="?android:textColorSecondary" />
</LinearLayout>
</RelativeLayout>

View File

@ -29,6 +29,7 @@
<string name="title_follows">Follows</string> <string name="title_follows">Follows</string>
<string name="title_followers">Followers</string> <string name="title_followers">Followers</string>
<string name="title_favourites">Favourites</string> <string name="title_favourites">Favourites</string>
<string name="title_mutes">Muted users</string>
<string name="title_blocks">Blocked users</string> <string name="title_blocks">Blocked users</string>
<string name="status_username_format">\@%s</string> <string name="status_username_format">\@%s</string>
@ -75,6 +76,7 @@
<string name="action_view_profile">Profile</string> <string name="action_view_profile">Profile</string>
<string name="action_view_preferences">Preferences</string> <string name="action_view_preferences">Preferences</string>
<string name="action_view_favourites">Favourites</string> <string name="action_view_favourites">Favourites</string>
<string name="action_view_mutes">Muted users</string>
<string name="action_view_blocks">Blocked users</string> <string name="action_view_blocks">Blocked users</string>
<string name="action_view_thread">Thread</string> <string name="action_view_thread">Thread</string>
<string name="action_view_media">Media</string> <string name="action_view_media">Media</string>