include selected account in list

This commit is contained in:
adbenitez
2021-10-12 15:38:09 -04:00
parent e55f1a9c20
commit 584f2648e6
3 changed files with 22 additions and 14 deletions
@@ -26,6 +26,7 @@ public class AccountSelectionListAdapter extends RecyclerView.Adapter
private final @NonNull Context context;
private final @NonNull DcAccounts accounts;
private @NonNull int[] accountList = new int[0];
private int selectedAccountId;
private final LayoutInflater li;
private final ItemClickListener clickListener;
private final GlideRequests glideRequests;
@@ -41,7 +42,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);
public abstract void bind(@NonNull GlideRequests glideRequests, int accountId, DcContact self, String name, String addr, int unreadCount, boolean selected);
public abstract void unbind(@NonNull GlideRequests glideRequests);
}
@@ -66,8 +67,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) {
getView().bind(glideRequests, accountId, self, name, addr, unreadCount);
public void bind(@NonNull GlideRequests glideRequests, int accountId, DcContact self, String name, String addr, int unreadCount, boolean selected) {
getView().bind(glideRequests, accountId, self, name, addr, unreadCount, selected);
}
@Override
@@ -118,7 +119,7 @@ public class AccountSelectionListAdapter extends RecyclerView.Adapter
ViewHolder holder = (ViewHolder) viewHolder;
holder.unbind(glideRequests);
holder.bind(glideRequests, id, dcContact, name, addr, unreadCount);
holder.bind(glideRequests, id, dcContact, name, addr, unreadCount, id == selectedAccountId);
}
public interface ItemClickListener {
@@ -126,8 +127,9 @@ public class AccountSelectionListAdapter extends RecyclerView.Adapter
void onDeleteButtonClick(int accountId);
}
public void changeData(int[] ids) {
public void changeData(int[] ids, int selectedAccountId) {
this.accountList = ids==null? new int[0] : ids;
this.selectedAccountId = selectedAccountId;
notifyDataSetChanged();
}
}
@@ -40,17 +40,14 @@ public class AccountSelectionListFragment extends DialogFragment
DcAccounts accounts = DcHelper.getAccounts(getActivity());
int[] accountIds = accounts.getAll();
int selectedAccountId = accounts.getSelectedAccount().getAccountId();
int[] ids = new int[accountIds.length];
int[] ids = new int[accountIds.length + 1];
ids[0] = DC_CONTACT_ID_ADD_ACCOUNT;
int j = 0;
for (int accountId : accountIds) {
if (accountId != selectedAccountId) {
ids[++j] = accountId;
}
ids[++j] = accountId;
}
adapter.changeData(ids);
adapter.changeData(ids, accounts.getSelectedAccount().getAccountId());
}
@NonNull
@@ -78,7 +75,7 @@ public class AccountSelectionListFragment extends DialogFragment
int accountId = contact.getAccountId();
if (accountId == DC_CONTACT_ID_ADD_ACCOUNT) {
new SwitchAccountAsyncTask(activity, R.string.one_moment, 0, null).execute();
} else {
} else if (accountId != DcHelper.getAccounts(activity).getSelectedAccount().getAccountId()) {
new SwitchAccountAsyncTask(activity, R.string.switching_account, accountId, null).execute();
}
}
@@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.accounts;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageButton;
@@ -57,12 +58,12 @@ 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) {
public void bind(@NonNull GlideRequests glideRequests, int accountId, DcContact self, String name, String addr, int unreadCount, boolean selected) {
this.accountId = accountId;
Recipient recipient;
if (accountId != DcContact.DC_CONTACT_ID_ADD_ACCOUNT) {
deleteBtn.setVisibility(View.VISIBLE);
deleteBtn.setVisibility(selected? View.INVISIBLE : View.VISIBLE);
recipient = new Recipient(getContext(), self, name);
} else {
deleteBtn.setVisibility(View.GONE);
@@ -70,6 +71,14 @@ public class AccountSelectionListItem extends LinearLayout {
}
this.contactPhotoImage.setAvatar(glideRequests, recipient, false);
if (selected) {
addrView.setTypeface(null, Typeface.BOLD);
nameView.setTypeface(null, Typeface.BOLD);
} else {
addrView.setTypeface(null, 0);
nameView.setTypeface(null, 0);
}
updateUnreadIndicator(unreadCount);
setText(name, addr);
}