mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
don't allow to remove yourself from the multiselect contact list, fixes #833
This commit is contained in:
@@ -19,6 +19,7 @@ import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.b44t.messenger.DcContact;
|
||||
import com.b44t.messenger.DcContext;
|
||||
import com.b44t.messenger.DcEventCenter;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
@@ -48,6 +49,8 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.b44t.messenger.DcContact.DC_CONTACT_ID_SELF;
|
||||
|
||||
public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
implements OnRecipientDeletedListener, DcEventCenter.DcEventDelegate
|
||||
{
|
||||
@@ -190,7 +193,10 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
lv = ViewUtil.findById(this, R.id.selected_contacts_list);
|
||||
avatar = ViewUtil.findById(this, R.id.avatar);
|
||||
groupName = ViewUtil.findById(this, R.id.group_name);
|
||||
SelectedRecipientsAdapter adapter = new SelectedRecipientsAdapter(this);
|
||||
List<Recipient> initList = new LinkedList<>();
|
||||
DcContact self = dcContext.getContact(DC_CONTACT_ID_SELF);
|
||||
initList.add(dcContext.getRecipient(self));
|
||||
SelectedRecipientsAdapter adapter = new SelectedRecipientsAdapter(this, initList);
|
||||
adapter.setOnRecipientDeletedListener(this);
|
||||
lv.setAdapter(adapter);
|
||||
|
||||
|
||||
@@ -314,6 +314,7 @@ public class ContactSelectionListAdapter extends RecyclerView.Adapter
|
||||
} else {
|
||||
boolean selected = actionModeSelection.indexOfValue(id) > -1;
|
||||
holder.setSelected(selected);
|
||||
enabled = !(dcContact.getId() == DcContact.DC_CONTACT_ID_SELF && itemMultiSelect);
|
||||
}
|
||||
holder.bind(glideRequests, id, dcContact, name, addr, label, itemMultiSelect, enabled);
|
||||
holder.setChecked(selectedContacts.contains(addr));
|
||||
|
||||
@@ -13,7 +13,6 @@ import com.b44t.messenger.DcContact;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.components.AvatarImageView;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
|
||||
@@ -62,7 +61,7 @@ public class ContactSelectionListItem extends LinearLayout implements RecipientM
|
||||
public void set(@NonNull GlideRequests glideRequests, int specialId, DcContact contact, String name, String number, String label, boolean multiSelect, boolean enabled) {
|
||||
this.glideRequests = glideRequests;
|
||||
this.specialId = specialId;
|
||||
this.name = name;
|
||||
this.name = name;
|
||||
this.number = number;
|
||||
|
||||
if (specialId==DcContact.DC_CONTACT_ID_NEW_CONTACT || specialId==DcContact.DC_CONTACT_ID_NEW_GROUP || specialId==DcContact.DC_CONTACT_ID_NEW_VERIFIED_GROUP
|
||||
@@ -79,6 +78,7 @@ public class ContactSelectionListItem extends LinearLayout implements RecipientM
|
||||
this.contactPhotoImage.setAvatar(glideRequests, recipient, false);
|
||||
|
||||
setText(name, number, label, contact);
|
||||
setEnabled(enabled);
|
||||
|
||||
if (multiSelect) this.checkBox.setVisibility(View.VISIBLE);
|
||||
else this.checkBox.setVisibility(View.GONE);
|
||||
|
||||
@@ -26,6 +26,8 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.b44t.messenger.DcContact.DC_CONTACT_ID_SELF;
|
||||
|
||||
public class SelectedRecipientsAdapter extends BaseAdapter {
|
||||
@NonNull private Context context;
|
||||
@Nullable private OnRecipientDeletedListener onRecipientDeletedListener;
|
||||
@@ -46,7 +48,11 @@ public class SelectedRecipientsAdapter extends BaseAdapter {
|
||||
|
||||
public void add(@NonNull Recipient recipient, boolean isPush) {
|
||||
if (!find(recipient).isPresent()) {
|
||||
RecipientWrapper wrapper = new RecipientWrapper(recipient, true, isPush);
|
||||
boolean isModifiable = true;
|
||||
if (recipient.getAddress().getDcContactId() == DC_CONTACT_ID_SELF) {
|
||||
isModifiable = false;
|
||||
}
|
||||
RecipientWrapper wrapper = new RecipientWrapper(recipient, isModifiable, isPush);
|
||||
this.recipients.add(0, wrapper);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
@@ -111,20 +117,17 @@ public class SelectedRecipientsAdapter extends BaseAdapter {
|
||||
dcContact = dcContext.getContact(p.getAddress().getDcContactId());
|
||||
}
|
||||
|
||||
TextView name = (TextView) v.findViewById(R.id.name);
|
||||
TextView phone = (TextView) v.findViewById(R.id.phone);
|
||||
ImageButton delete = (ImageButton) v.findViewById(R.id.delete);
|
||||
TextView name = v.findViewById(R.id.name);
|
||||
TextView phone = v.findViewById(R.id.phone);
|
||||
ImageButton delete = v.findViewById(R.id.delete);
|
||||
|
||||
name.setText(dcContact.getDisplayName());
|
||||
phone.setText(dcContact.getAddr());
|
||||
delete.setVisibility(modifiable ? View.VISIBLE : View.GONE);
|
||||
delete.setColorFilter(DynamicTheme.isDarkTheme(context)? Color.WHITE : Color.BLACK);
|
||||
delete.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (onRecipientDeletedListener != null) {
|
||||
onRecipientDeletedListener.onRecipientDeleted(recipients.get(position).getRecipient());
|
||||
}
|
||||
delete.setOnClickListener(view -> {
|
||||
if (onRecipientDeletedListener != null) {
|
||||
onRecipientDeletedListener.onRecipientDeleted(recipients.get(position).getRecipient());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -134,7 +137,11 @@ public class SelectedRecipientsAdapter extends BaseAdapter {
|
||||
private static List<RecipientWrapper> wrapExistingMembers(Collection<Recipient> recipients) {
|
||||
final LinkedList<RecipientWrapper> wrapperList = new LinkedList<>();
|
||||
for (Recipient recipient : recipients) {
|
||||
wrapperList.add(new RecipientWrapper(recipient, true, true));
|
||||
boolean isModifiable = true;
|
||||
if (recipient.getAddress().getDcContactId() == DC_CONTACT_ID_SELF) {
|
||||
isModifiable = false;
|
||||
}
|
||||
wrapperList.add(new RecipientWrapper(recipient, isModifiable, true));
|
||||
}
|
||||
return wrapperList;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user