mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-03 02:05:36 +00:00
Refactored adapters to use bindTo method
This commit is contained in:
parent
9b148eefb9
commit
048660d24f
4 changed files with 65 additions and 51 deletions
|
@ -73,6 +73,14 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
|
|||
itemView.setOnClickListener(null);
|
||||
}
|
||||
|
||||
private void bindTo(EntityAccount account) {
|
||||
ivPrimary.setVisibility(account.primary ? View.VISIBLE : View.GONE);
|
||||
tvName.setText(account.name);
|
||||
ivSync.setVisibility(account.synchronize ? View.VISIBLE : View.INVISIBLE);
|
||||
tvHost.setText(String.format("%s:%d", account.host, account.port));
|
||||
tvUser.setText(account.user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int pos = getAdapterPosition();
|
||||
|
@ -192,12 +200,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
|
|||
holder.unwire();
|
||||
|
||||
EntityAccount account = filtered.get(position);
|
||||
|
||||
holder.ivPrimary.setVisibility(account.primary ? View.VISIBLE : View.GONE);
|
||||
holder.tvName.setText(account.name);
|
||||
holder.ivSync.setVisibility(account.synchronize ? View.VISIBLE : View.INVISIBLE);
|
||||
holder.tvHost.setText(String.format("%s:%d", account.host, account.port));
|
||||
holder.tvUser.setText(account.user);
|
||||
holder.bindTo(account);
|
||||
|
||||
holder.wire();
|
||||
}
|
||||
|
|
|
@ -80,6 +80,30 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
|
|||
itemView.setOnClickListener(null);
|
||||
}
|
||||
|
||||
private void bindTo(TupleAttachment attachment) {
|
||||
tvName.setText(attachment.name);
|
||||
|
||||
if (attachment.size != null)
|
||||
tvSize.setText(Helper.humanReadableByteCount(attachment.size, false));
|
||||
tvSize.setVisibility(attachment.size == null ? View.GONE : View.VISIBLE);
|
||||
|
||||
if (attachment.progress != null)
|
||||
progressbar.setProgress(attachment.progress);
|
||||
progressbar.setVisibility(
|
||||
attachment.progress == null || attachment.content ? View.GONE : View.VISIBLE);
|
||||
|
||||
if (attachment.content) {
|
||||
ivStatus.setImageResource(R.drawable.baseline_visibility_24);
|
||||
ivStatus.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
if (attachment.progress == null) {
|
||||
ivStatus.setImageResource(R.drawable.baseline_get_app_24);
|
||||
ivStatus.setVisibility(View.VISIBLE);
|
||||
} else
|
||||
ivStatus.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int pos = getAdapterPosition();
|
||||
|
@ -265,27 +289,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
|
|||
holder.unwire();
|
||||
|
||||
TupleAttachment attachment = filtered.get(position);
|
||||
holder.tvName.setText(attachment.name);
|
||||
|
||||
if (attachment.size != null)
|
||||
holder.tvSize.setText(Helper.humanReadableByteCount(attachment.size, false));
|
||||
holder.tvSize.setVisibility(attachment.size == null ? View.GONE : View.VISIBLE);
|
||||
|
||||
if (attachment.progress != null)
|
||||
holder.progressbar.setProgress(attachment.progress);
|
||||
holder.progressbar.setVisibility(
|
||||
attachment.progress == null || attachment.content ? View.GONE : View.VISIBLE);
|
||||
|
||||
if (attachment.content) {
|
||||
holder.ivStatus.setImageResource(R.drawable.baseline_visibility_24);
|
||||
holder.ivStatus.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
if (attachment.progress == null) {
|
||||
holder.ivStatus.setImageResource(R.drawable.baseline_get_app_24);
|
||||
holder.ivStatus.setVisibility(View.VISIBLE);
|
||||
} else
|
||||
holder.ivStatus.setVisibility(View.GONE);
|
||||
}
|
||||
holder.bindTo(attachment);
|
||||
|
||||
holder.wire();
|
||||
}
|
||||
|
|
|
@ -77,6 +77,27 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
|||
itemView.setOnLongClickListener(null);
|
||||
}
|
||||
|
||||
private void bindTo(TupleFolderEx folder) {
|
||||
String name = Helper.localizeFolderName(context, folder.name);
|
||||
tvName.setText(context.getString(R.string.title_folder_unseen, name, folder.unseen, folder.messages));
|
||||
tvName.setTypeface(null, folder.unseen > 0 ? Typeface.BOLD : Typeface.NORMAL);
|
||||
tvName.setTextColor(Helper.resolveColor(context, folder.unseen > 0 ? R.attr.colorUnread : android.R.attr.textColorSecondary));
|
||||
|
||||
tvAfter.setText(Integer.toString(folder.after));
|
||||
tvAfter.setVisibility(folder.synchronize ? View.VISIBLE : View.INVISIBLE);
|
||||
|
||||
ivSync.setVisibility(folder.synchronize ? View.VISIBLE : View.INVISIBLE);
|
||||
|
||||
tvAccount.setText(folder.accountName);
|
||||
tvAccount.setVisibility(EntityFolder.TYPE_OUTBOX.equals(folder.type) ? View.GONE : View.VISIBLE);
|
||||
|
||||
int resid = context.getResources().getIdentifier(
|
||||
"title_folder_" + folder.type.toLowerCase(),
|
||||
"string",
|
||||
context.getPackageName());
|
||||
tvType.setText(resid > 0 ? context.getString(resid) : folder.type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int pos = getAdapterPosition();
|
||||
|
@ -225,25 +246,8 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
|||
holder.unwire();
|
||||
|
||||
TupleFolderEx folder = filtered.get(position);
|
||||
holder.bindTo(folder);
|
||||
|
||||
String name = Helper.localizeFolderName(context, folder.name);
|
||||
holder.tvName.setText(context.getString(R.string.title_folder_unseen, name, folder.unseen, folder.messages));
|
||||
holder.tvName.setTypeface(null, folder.unseen > 0 ? Typeface.BOLD : Typeface.NORMAL);
|
||||
holder.tvName.setTextColor(Helper.resolveColor(context, folder.unseen > 0 ? R.attr.colorUnread : android.R.attr.textColorSecondary));
|
||||
|
||||
holder.tvAfter.setText(Integer.toString(folder.after));
|
||||
holder.tvAfter.setVisibility(folder.synchronize ? View.VISIBLE : View.INVISIBLE);
|
||||
|
||||
holder.ivSync.setVisibility(folder.synchronize ? View.VISIBLE : View.INVISIBLE);
|
||||
|
||||
holder.tvAccount.setText(folder.accountName);
|
||||
holder.tvAccount.setVisibility(EntityFolder.TYPE_OUTBOX.equals(folder.type) ? View.GONE : View.VISIBLE);
|
||||
|
||||
int resid = context.getResources().getIdentifier(
|
||||
"title_folder_" + folder.type.toLowerCase(),
|
||||
"string",
|
||||
context.getPackageName());
|
||||
holder.tvType.setText(resid > 0 ? context.getString(resid) : folder.type);
|
||||
|
||||
holder.wire();
|
||||
}
|
||||
|
|
|
@ -73,6 +73,14 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
|
|||
itemView.setOnClickListener(null);
|
||||
}
|
||||
|
||||
private void bindTo(EntityIdentity identity) {
|
||||
ivPrimary.setVisibility(identity.primary ? View.VISIBLE : View.GONE);
|
||||
tvName.setText(identity.name);
|
||||
ivSync.setVisibility(identity.synchronize ? View.VISIBLE : View.INVISIBLE);
|
||||
tvHost.setText(String.format("%s:%d", identity.host, identity.port));
|
||||
tvEmail.setText(identity.email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int pos = getAdapterPosition();
|
||||
|
@ -192,12 +200,7 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
|
|||
holder.unwire();
|
||||
|
||||
EntityIdentity identity = filtered.get(position);
|
||||
|
||||
holder.ivPrimary.setVisibility(identity.primary ? View.VISIBLE : View.GONE);
|
||||
holder.tvName.setText(identity.name);
|
||||
holder.ivSync.setVisibility(identity.synchronize ? View.VISIBLE : View.INVISIBLE);
|
||||
holder.tvHost.setText(String.format("%s:%d", identity.host, identity.port));
|
||||
holder.tvEmail.setText(identity.email);
|
||||
holder.bindTo(identity);
|
||||
|
||||
holder.wire();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue