Tusky-App-Android/app/src/main/java/com/keylesspalace/tusky/adapter/MutesAdapter.java

90 lines
3.6 KiB
Java
Raw Normal View History

2017-05-05 00:55:34 +02:00
package com.keylesspalace.tusky.adapter;
2017-04-22 01:02:04 +02:00
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.preference.PreferenceManager;
2017-04-22 01:02:04 +02:00
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
2017-04-22 01:02:04 +02:00
import android.widget.TextView;
2017-05-05 00:55:34 +02:00
import com.keylesspalace.tusky.R;
2017-04-22 01:02:04 +02:00
import com.keylesspalace.tusky.entity.Account;
2017-05-05 00:55:34 +02:00
import com.keylesspalace.tusky.interfaces.AccountActionListener;
2018-06-24 09:53:23 +02:00
import com.keylesspalace.tusky.util.CustomEmojiHelper;
import com.keylesspalace.tusky.util.ImageLoadingHelper;
2017-04-22 01:02:04 +02:00
2017-05-05 00:55:34 +02:00
public class MutesAdapter extends AccountAdapter {
2017-04-22 01:02:04 +02:00
2017-05-05 00:55:34 +02:00
public MutesAdapter(AccountActionListener accountActionListener) {
2017-04-22 01:02:04 +02:00
super(accountActionListener);
}
2018-06-24 09:53:23 +02:00
@NonNull
2017-04-22 01:02:04 +02:00
@Override
2018-06-24 09:53:23 +02:00
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
2017-04-22 01:02:04 +02:00
switch (viewType) {
default:
case VIEW_TYPE_ACCOUNT: {
2017-04-22 01:02:04 +02:00
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 LoadingFooterViewHolder(view);
2017-04-22 01:02:04 +02:00
}
}
}
@Override
2018-06-24 09:53:23 +02:00
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
if (getItemViewType(position) == VIEW_TYPE_ACCOUNT) {
2017-04-22 01:02:04 +02:00
MutedUserViewHolder holder = (MutedUserViewHolder) viewHolder;
holder.setupWithAccount(accountList.get(position));
holder.setupActionListener(accountActionListener);
2017-04-22 01:02:04 +02:00
}
}
static class MutedUserViewHolder extends RecyclerView.ViewHolder {
private ImageView avatar;
2017-06-22 20:59:12 +02:00
private TextView username;
private TextView displayName;
private ImageButton unmute;
2017-04-22 01:02:04 +02:00
private String id;
private boolean animateAvatar;
2017-04-22 01:02:04 +02:00
MutedUserViewHolder(View itemView) {
super(itemView);
avatar = itemView.findViewById(R.id.muted_user_avatar);
username = itemView.findViewById(R.id.muted_user_username);
displayName = itemView.findViewById(R.id.muted_user_display_name);
unmute = itemView.findViewById(R.id.muted_user_unmute);
animateAvatar = PreferenceManager.getDefaultSharedPreferences(itemView.getContext())
.getBoolean("animateGifAvatars", false);
2017-04-22 01:02:04 +02:00
}
void setupWithAccount(Account account) {
id = account.getId();
2018-06-24 09:53:23 +02:00
CharSequence emojifiedName = CustomEmojiHelper.emojifyString(account.getName(), account.getEmojis(), displayName);
displayName.setText(emojifiedName);
2017-04-22 01:02:04 +02:00
String format = username.getContext().getString(R.string.status_username_format);
String formattedUsername = String.format(format, account.getUsername());
2017-04-22 01:02:04 +02:00
username.setText(formattedUsername);
int avatarRadius = avatar.getContext().getResources()
.getDimensionPixelSize(R.dimen.avatar_radius_48dp);
ImageLoadingHelper.loadAvatar(account.getAvatar(), avatar, avatarRadius, animateAvatar);
2017-04-22 01:02:04 +02:00
}
void setupActionListener(final AccountActionListener listener) {
unmute.setOnClickListener(v -> listener.onMute(false, id, getAdapterPosition()));
2018-06-24 09:53:23 +02:00
avatar.setOnClickListener(v -> listener.onViewAccount(id));
2017-04-22 01:02:04 +02:00
}
}
}