fix single contact selection for contacts with multiple phones

// FREEBIE
This commit is contained in:
Jake McGinty 2014-02-21 17:11:52 -08:00
parent 7beab36c6a
commit b855f8a163
2 changed files with 18 additions and 31 deletions

View file

@ -40,6 +40,7 @@ import org.thoughtcrime.securesms.contacts.ContactAccessor;
import org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData;
import org.thoughtcrime.securesms.contacts.ContactAccessor.NumberData;
import java.util.Collections;
import java.util.HashMap;
/**
@ -93,8 +94,8 @@ public class SingleContactSelectionListFragment extends SherlockListFragment
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.ContactSelectionlistFragment_select_for + " " + contactData.name);
builder.setMultiChoiceItems(options, null, new DiscriminatorClickedListener(contactData));
builder.setPositiveButton(android.R.string.ok, new DiscriminatorFinishedListener(contactData, textView));
builder.setSingleChoiceItems(options, -1, new DiscriminatorClickedListener(contactData));
//builder.setPositiveButton(android.R.string.ok, new DiscriminatorFinishedListener(contactData, textView));
builder.setOnCancelListener(new DiscriminatorFinishedListener(contactData, textView));
builder.show();
}
@ -212,47 +213,26 @@ public class SingleContactSelectionListFragment extends SherlockListFragment
}
public void onClick(DialogInterface dialog, int which) {
ContactData selected = selectedContacts.get(contactData.id);
if (selected.numbers.size() == 0) {
selectedContacts.remove(selected.id);
}
if (textView == null)
((CursorAdapter) getListView().getAdapter()).notifyDataSetChanged();
// ignore
}
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;
public DiscriminatorClickedListener(ContactData contactData) {
this.contactData = contactData;
}
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
Log.w(TAG, "Got checked: " + isChecked);
ContactData existing = selectedContacts.get(contactData.id);
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);
public void onClick(DialogInterface dialog, int which) {
ContactData singlePhoneContact = new ContactData(contactData.id,
contactData.name,
Collections.singletonList(contactData.numbers.get(which)));
addSingleNumberContact(singlePhoneContact);
}
}

View file

@ -367,6 +367,13 @@ public class ContactAccessor {
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) {
id = in.readLong();
name = in.readString();