mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 09:17:44 +00:00
Added QuickContact onclick in GroupMembersDialog
Fixes #2837 Closes #3033
This commit is contained in:
parent
41cad291f9
commit
417a4b86b6
@ -2,7 +2,11 @@ package org.thoughtcrime.securesms;
|
|||||||
|
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.graphics.Rect;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.provider.ContactsContract;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.afollestad.materialdialogs.AlertDialogWrapper;
|
import com.afollestad.materialdialogs.AlertDialogWrapper;
|
||||||
@ -45,7 +49,7 @@ public class GroupMembersDialog extends AsyncTask<Void, Void, Recipients> {
|
|||||||
return DatabaseFactory.getGroupDatabase(context)
|
return DatabaseFactory.getGroupDatabase(context)
|
||||||
.getGroupMembers(GroupUtil.getDecodedId(groupId), true);
|
.getGroupMembers(GroupUtil.getDecodedId(groupId), true);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.w("ConverstionActivity", e);
|
Log.w(TAG, e);
|
||||||
return new Recipients(new LinkedList<Recipient>());
|
return new Recipients(new LinkedList<Recipient>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,20 +60,12 @@ public class GroupMembersDialog extends AsyncTask<Void, Void, Recipients> {
|
|||||||
progress.dismiss();
|
progress.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> recipientStrings = new LinkedList<>();
|
GroupMembers groupMembers = new GroupMembers(members);
|
||||||
recipientStrings.add(context.getString(R.string.GroupMembersDialog_me));
|
|
||||||
|
|
||||||
for (Recipient recipient : members.getRecipientsList()) {
|
|
||||||
if (!isLocalNumber(recipient)) {
|
|
||||||
recipientStrings.add(recipient.toShortString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(context);
|
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(context);
|
||||||
builder.setTitle(R.string.ConversationActivity_group_members);
|
builder.setTitle(R.string.ConversationActivity_group_members);
|
||||||
builder.setIconAttribute(R.attr.group_members_dialog_icon);
|
builder.setIconAttribute(R.attr.group_members_dialog_icon);
|
||||||
builder.setCancelable(true);
|
builder.setCancelable(true);
|
||||||
builder.setItems(recipientStrings.toArray(new String[]{}), null);
|
builder.setItems(groupMembers.getRecipientStrings(), new GroupMembersOnClickListener(context, groupMembers));
|
||||||
builder.setPositiveButton(android.R.string.ok, null);
|
builder.setPositiveButton(android.R.string.ok, null);
|
||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
@ -79,15 +75,83 @@ public class GroupMembersDialog extends AsyncTask<Void, Void, Recipients> {
|
|||||||
else onPostExecute(recipients);
|
else onPostExecute(recipients);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isLocalNumber(Recipient recipient) {
|
private class GroupMembersOnClickListener implements DialogInterface.OnClickListener {
|
||||||
try {
|
private final GroupMembers groupMembers;
|
||||||
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
private final Context context;
|
||||||
String e164Number = Util.canonicalizeNumber(context, recipient.getNumber());
|
|
||||||
|
|
||||||
return e164Number != null && e164Number.equals(localNumber);
|
public GroupMembersOnClickListener(Context context, GroupMembers members) {
|
||||||
} catch (InvalidNumberException e) {
|
this.context = context;
|
||||||
Log.w(TAG, e);
|
this.groupMembers = members;
|
||||||
return false;
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int item) {
|
||||||
|
Recipient recipient = groupMembers.get(item);
|
||||||
|
|
||||||
|
if (recipient.getContactUri() != null) {
|
||||||
|
ContactsContract.QuickContact.showQuickContact(context, new Rect(0,0,0,0),
|
||||||
|
recipient.getContactUri(),
|
||||||
|
ContactsContract.QuickContact.MODE_LARGE, null);
|
||||||
|
} else {
|
||||||
|
final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
|
||||||
|
intent.putExtra(ContactsContract.Intents.Insert.PHONE, recipient.getNumber());
|
||||||
|
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps a List of Recipient (just like @class Recipients),
|
||||||
|
* but with focus on the order of the Recipients.
|
||||||
|
* So that the order of the RecipientStrings[] matches
|
||||||
|
* the internal order.
|
||||||
|
*
|
||||||
|
* @author Christoph Haefner
|
||||||
|
*/
|
||||||
|
private class GroupMembers {
|
||||||
|
private final String TAG = GroupMembers.class.getSimpleName();
|
||||||
|
|
||||||
|
private final LinkedList<Recipient> members = new LinkedList<>();
|
||||||
|
|
||||||
|
public GroupMembers(Recipients recipients) {
|
||||||
|
for (Recipient recipient : recipients.getRecipientsList()) {
|
||||||
|
if (isLocalNumber(recipient)) {
|
||||||
|
members.push(recipient);
|
||||||
|
} else {
|
||||||
|
members.add(recipient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getRecipientStrings() {
|
||||||
|
List<String> recipientStrings = new LinkedList<>();
|
||||||
|
|
||||||
|
for (Recipient recipient : members) {
|
||||||
|
if (isLocalNumber(recipient)) {
|
||||||
|
recipientStrings.add(context.getString(R.string.GroupMembersDialog_me));
|
||||||
|
} else {
|
||||||
|
recipientStrings.add(recipient.toShortString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return recipientStrings.toArray(new String[members.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Recipient get(int index) {
|
||||||
|
return members.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isLocalNumber(Recipient recipient) {
|
||||||
|
try {
|
||||||
|
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
||||||
|
String e164Number = Util.canonicalizeNumber(context, recipient.getNumber());
|
||||||
|
|
||||||
|
return e164Number != null && e164Number.equals(localNumber);
|
||||||
|
} catch (InvalidNumberException e) {
|
||||||
|
Log.w(TAG, e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user