mirror of
https://codeberg.org/Mercury-IM/Mercury-IM
synced 2024-11-15 04:12:04 +01:00
Small refactoring
This commit is contained in:
parent
7e2fe55b56
commit
ff04832614
1 changed files with 18 additions and 9 deletions
|
@ -7,9 +7,11 @@ import android.widget.ImageView;
|
|||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.DiffUtil;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.mercury_im.messenger.R;
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
import org.mercury_im.messenger.ui.avatar.AvatarDrawable;
|
||||
|
@ -30,6 +32,7 @@ public class AccountsRecyclerViewAdapter extends RecyclerView.Adapter<AccountsRe
|
|||
this.viewModel = viewModel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
|
@ -38,7 +41,8 @@ public class AccountsRecyclerViewAdapter extends RecyclerView.Adapter<AccountsRe
|
|||
}
|
||||
|
||||
public void setValues(List<Account> values) {
|
||||
DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new AccountsDiffCallback(values, accounts), true);
|
||||
DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(
|
||||
new AccountsDiffCallback(values, accounts), true);
|
||||
accounts.clear();
|
||||
accounts.addAll(values);
|
||||
diffResult.dispatchUpdatesTo(this);
|
||||
|
@ -57,8 +61,13 @@ public class AccountsRecyclerViewAdapter extends RecyclerView.Adapter<AccountsRe
|
|||
holder.jid.setText(account.getAddress());
|
||||
holder.avatar.setImageDrawable(new AvatarDrawable(account.getAddress(), account.getAddress()));
|
||||
holder.enabled.setChecked(account.isEnabled());
|
||||
holder.enabled.setOnCheckedChangeListener((compoundButton, checked) -> viewModel.setAccountEnabled(account, checked));
|
||||
holder.enabled.setOnCheckedChangeListener((compoundButton, checked) ->
|
||||
viewModel.setAccountEnabled(account, checked));
|
||||
|
||||
setClickListenersOnViewHolder(holder);
|
||||
}
|
||||
|
||||
private void setClickListenersOnViewHolder(ViewHolder holder) {
|
||||
holder.mView.setOnClickListener(v -> {
|
||||
if (null != onAccountClickListener) {
|
||||
onAccountClickListener.onAccountListItemClick(holder.account);
|
||||
|
@ -73,13 +82,13 @@ public class AccountsRecyclerViewAdapter extends RecyclerView.Adapter<AccountsRe
|
|||
});
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
public Account account;
|
||||
public final View mView;
|
||||
public final ImageView avatar;
|
||||
public final TextView jid;
|
||||
public final Switch enabled;
|
||||
public final TextView status;
|
||||
class ViewHolder extends RecyclerView.ViewHolder {
|
||||
private Account account;
|
||||
final View mView;
|
||||
final ImageView avatar;
|
||||
final TextView jid;
|
||||
final Switch enabled;
|
||||
final TextView status;
|
||||
|
||||
public ViewHolder(View view) {
|
||||
super(view);
|
||||
|
|
Loading…
Reference in a new issue