mirror of https://github.com/tuskyapp/Tusky.git
9 changed files with 310 additions and 10 deletions
@ -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); |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
} |
||||
@ -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> |
||||
@ -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> |
||||
@ -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> |
||||
Loading…
Reference in new issue