mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-25 13:27:21 +00:00
fix single contact selection for contacts with multiple phones
// FREEBIE
This commit is contained in:
parent
7beab36c6a
commit
b855f8a163
@ -40,6 +40,7 @@ import org.thoughtcrime.securesms.contacts.ContactAccessor;
|
|||||||
import org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData;
|
import org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData;
|
||||||
import org.thoughtcrime.securesms.contacts.ContactAccessor.NumberData;
|
import org.thoughtcrime.securesms.contacts.ContactAccessor.NumberData;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,8 +94,8 @@ public class SingleContactSelectionListFragment extends SherlockListFragment
|
|||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
builder.setTitle(R.string.ContactSelectionlistFragment_select_for + " " + contactData.name);
|
builder.setTitle(R.string.ContactSelectionlistFragment_select_for + " " + contactData.name);
|
||||||
builder.setMultiChoiceItems(options, null, new DiscriminatorClickedListener(contactData));
|
builder.setSingleChoiceItems(options, -1, new DiscriminatorClickedListener(contactData));
|
||||||
builder.setPositiveButton(android.R.string.ok, new DiscriminatorFinishedListener(contactData, textView));
|
//builder.setPositiveButton(android.R.string.ok, new DiscriminatorFinishedListener(contactData, textView));
|
||||||
builder.setOnCancelListener(new DiscriminatorFinishedListener(contactData, textView));
|
builder.setOnCancelListener(new DiscriminatorFinishedListener(contactData, textView));
|
||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
@ -212,47 +213,26 @@ public class SingleContactSelectionListFragment extends SherlockListFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
ContactData selected = selectedContacts.get(contactData.id);
|
// ignore
|
||||||
|
|
||||||
if (selected.numbers.size() == 0) {
|
|
||||||
selectedContacts.remove(selected.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (textView == null)
|
|
||||||
((CursorAdapter) getListView().getAdapter()).notifyDataSetChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onCancel(DialogInterface dialog) {
|
public void onCancel(DialogInterface dialog) {
|
||||||
onClick(dialog, 0);
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DiscriminatorClickedListener implements DialogInterface.OnMultiChoiceClickListener {
|
private class DiscriminatorClickedListener implements DialogInterface.OnClickListener {
|
||||||
private final ContactData contactData;
|
private final ContactData contactData;
|
||||||
|
|
||||||
public DiscriminatorClickedListener(ContactData contactData) {
|
public DiscriminatorClickedListener(ContactData contactData) {
|
||||||
this.contactData = contactData;
|
this.contactData = contactData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
Log.w(TAG, "Got checked: " + isChecked);
|
ContactData singlePhoneContact = new ContactData(contactData.id,
|
||||||
|
contactData.name,
|
||||||
ContactData existing = selectedContacts.get(contactData.id);
|
Collections.singletonList(contactData.numbers.get(which)));
|
||||||
|
addSingleNumberContact(singlePhoneContact);
|
||||||
if (existing == null) {
|
|
||||||
Log.w(TAG, "No existing contact data, creating...");
|
|
||||||
|
|
||||||
if (!isChecked)
|
|
||||||
throw new AssertionError("We shouldn't be unchecking data that doesn't exist.");
|
|
||||||
|
|
||||||
existing = new ContactData(contactData.id, contactData.name);
|
|
||||||
selectedContacts.put(existing.id, existing);
|
|
||||||
}
|
|
||||||
|
|
||||||
NumberData selectedData = contactData.numbers.get(which);
|
|
||||||
|
|
||||||
if (!isChecked) existing.numbers.remove(selectedData);
|
|
||||||
else existing.numbers.add(selectedData);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,6 +367,13 @@ public class ContactAccessor {
|
|||||||
this.numbers = new LinkedList<NumberData>();
|
this.numbers = new LinkedList<NumberData>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ContactData(long id, String name, List<NumberData> numbers) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.numbers = numbers;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public ContactData(Parcel in) {
|
public ContactData(Parcel in) {
|
||||||
id = in.readLong();
|
id = in.readLong();
|
||||||
name = in.readString();
|
name = in.readString();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user