mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
simplify AccountSelectionListItem.bind()
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package org.thoughtcrime.securesms.accounts;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -12,7 +10,6 @@ import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.b44t.messenger.DcAccounts;
|
||||
import com.b44t.messenger.DcContact;
|
||||
import com.b44t.messenger.DcContext;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
@@ -41,7 +38,7 @@ public class AccountSelectionListAdapter extends RecyclerView.Adapter
|
||||
super(itemView);
|
||||
}
|
||||
|
||||
public abstract void bind(@NonNull GlideRequests glideRequests, int accountId, DcContact self, String name, String addr, int unreadCount, boolean selected, boolean isMuted, AccountSelectionListFragment fragment);
|
||||
public abstract void bind(@NonNull GlideRequests glideRequests, int accountId, DcContext dcContext, boolean selected, AccountSelectionListFragment fragment);
|
||||
public abstract void unbind(@NonNull GlideRequests glideRequests);
|
||||
}
|
||||
|
||||
@@ -61,8 +58,8 @@ public class AccountSelectionListAdapter extends RecyclerView.Adapter
|
||||
return (AccountSelectionListItem) itemView;
|
||||
}
|
||||
|
||||
public void bind(@NonNull GlideRequests glideRequests, int accountId, DcContact self, String name, String addr, int unreadCount, boolean selected, boolean isMuted, AccountSelectionListFragment fragment) {
|
||||
getView().bind(glideRequests, accountId, self, name, addr, unreadCount, selected, isMuted, fragment);
|
||||
public void bind(@NonNull GlideRequests glideRequests, int accountId, DcContext dcContext, boolean selected, AccountSelectionListFragment fragment) {
|
||||
getView().bind(glideRequests, accountId, dcContext, selected, fragment);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -92,31 +89,12 @@ public class AccountSelectionListAdapter extends RecyclerView.Adapter
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
|
||||
|
||||
int id = accountList[i];
|
||||
DcContact dcContact = null;
|
||||
String name;
|
||||
String addr = null;
|
||||
int unreadCount = 0;
|
||||
DcContext dcContext = accounts.getAccount(id);
|
||||
|
||||
if (id == DcContact.DC_CONTACT_ID_ADD_ACCOUNT) {
|
||||
name = context.getString(R.string.add_account);
|
||||
} else {
|
||||
dcContact = dcContext.getContact(DcContact.DC_CONTACT_ID_SELF);
|
||||
name = dcContext.getConfig("displayname");
|
||||
if (TextUtils.isEmpty(name)) {
|
||||
name = dcContact.getAddr();
|
||||
}
|
||||
if (!dcContext.isChatmail()) {
|
||||
addr = dcContact.getAddr();
|
||||
}
|
||||
unreadCount = dcContext.getFreshMsgs().length;
|
||||
}
|
||||
|
||||
ViewHolder holder = (ViewHolder) viewHolder;
|
||||
holder.unbind(glideRequests);
|
||||
holder.bind(glideRequests, id, dcContact, name, addr, unreadCount, id == selectedAccountId, dcContext.isMuted(), fragment);
|
||||
holder.bind(glideRequests, id, dcContext, id == selectedAccountId, fragment);
|
||||
}
|
||||
|
||||
public interface ItemClickListener {
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.accounts;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
@@ -13,6 +14,7 @@ import androidx.annotation.NonNull;
|
||||
|
||||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
import com.b44t.messenger.DcContact;
|
||||
import com.b44t.messenger.DcContext;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.components.AvatarImageView;
|
||||
@@ -53,8 +55,27 @@ public class AccountSelectionListItem extends LinearLayout {
|
||||
ViewUtil.setTextViewGravityStart(this.nameView, getContext());
|
||||
}
|
||||
|
||||
public void bind(@NonNull GlideRequests glideRequests, int accountId, DcContact self, String name, String addr, int unreadCount, boolean selected, boolean isMuted, AccountSelectionListFragment fragment) {
|
||||
public void bind(@NonNull GlideRequests glideRequests, int accountId, DcContext dcContext, boolean selected, AccountSelectionListFragment fragment) {
|
||||
this.accountId = accountId;
|
||||
DcContact self = null;
|
||||
String name;
|
||||
String addr = null;
|
||||
int unreadCount = 0;
|
||||
boolean isMuted = dcContext.isMuted();
|
||||
|
||||
if (accountId == DcContact.DC_CONTACT_ID_ADD_ACCOUNT) {
|
||||
name = getContext().getString(R.string.add_account);
|
||||
} else {
|
||||
self = dcContext.getContact(DcContact.DC_CONTACT_ID_SELF);
|
||||
name = dcContext.getConfig("displayname");
|
||||
if (TextUtils.isEmpty(name)) {
|
||||
name = self.getAddr();
|
||||
}
|
||||
if (!dcContext.isChatmail()) {
|
||||
addr = self.getAddr();
|
||||
}
|
||||
unreadCount = dcContext.getFreshMsgs().length;
|
||||
}
|
||||
|
||||
Recipient recipient;
|
||||
if (accountId != DcContact.DC_CONTACT_ID_ADD_ACCOUNT) {
|
||||
|
||||
Reference in New Issue
Block a user