2017-05-05 00:55:34 +02:00
|
|
|
package com.keylesspalace.tusky.adapter;
|
2017-04-22 01:02:04 +02:00
|
|
|
|
2018-12-17 15:25:35 +01:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
2019-05-26 08:46:08 +02:00
|
|
|
|
|
|
|
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;
|
2018-07-30 15:36:22 +02:00
|
|
|
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;
|
2019-05-26 08:46:08 +02:00
|
|
|
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:
|
2018-08-31 21:52:09 +02:00
|
|
|
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);
|
2018-08-31 21:52:09 +02:00
|
|
|
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) {
|
2018-08-31 21:52:09 +02:00
|
|
|
if (getItemViewType(position) == VIEW_TYPE_ACCOUNT) {
|
2017-04-22 01:02:04 +02:00
|
|
|
MutedUserViewHolder holder = (MutedUserViewHolder) viewHolder;
|
|
|
|
holder.setupWithAccount(accountList.get(position));
|
2018-08-12 20:19:44 +02:00
|
|
|
holder.setupActionListener(accountActionListener);
|
2017-04-22 01:02:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static class MutedUserViewHolder extends RecyclerView.ViewHolder {
|
2018-07-30 15:36:22 +02:00
|
|
|
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;
|
2019-05-26 08:46:08 +02:00
|
|
|
private boolean animateAvatar;
|
2017-04-22 01:02:04 +02:00
|
|
|
|
|
|
|
MutedUserViewHolder(View itemView) {
|
|
|
|
super(itemView);
|
2017-10-18 00:20:26 +02:00
|
|
|
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);
|
2019-05-26 08:46:08 +02:00
|
|
|
animateAvatar = PreferenceManager.getDefaultSharedPreferences(itemView.getContext())
|
|
|
|
.getBoolean("animateGifAvatars", false);
|
2017-04-22 01:02:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void setupWithAccount(Account account) {
|
2018-03-03 13:24:03 +01:00
|
|
|
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);
|
2018-03-03 13:24:03 +01:00
|
|
|
String formattedUsername = String.format(format, account.getUsername());
|
2017-04-22 01:02:04 +02:00
|
|
|
username.setText(formattedUsername);
|
2019-05-26 08:46:08 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-08-12 20:19:44 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|