Skip to content

Commit 417a4b8

Browse files
chr1shaefn3rmoxie0
authored andcommitted
Added QuickContact onclick in GroupMembersDialog
Fixes #2837 Closes #3033
1 parent 41cad29 commit 417a4b8

1 file changed

Lines changed: 83 additions & 19 deletions

File tree

‎src/org/thoughtcrime/securesms/GroupMembersDialog.java‎

Lines changed: 83 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
import android.app.ProgressDialog;
44
import android.content.Context;
5+
import android.content.DialogInterface;
6+
import android.content.Intent;
7+
import android.graphics.Rect;
58
import android.os.AsyncTask;
9+
import android.provider.ContactsContract;
610
import android.util.Log;
711

812
import com.afollestad.materialdialogs.AlertDialogWrapper;
@@ -45,7 +49,7 @@ protected Recipients doInBackground(Void... params) {
4549
return DatabaseFactory.getGroupDatabase(context)
4650
.getGroupMembers(GroupUtil.getDecodedId(groupId), true);
4751
} catch (IOException e) {
48-
Log.w("ConverstionActivity", e);
52+
Log.w(TAG, e);
4953
return new Recipients(new LinkedList<Recipient>());
5054
}
5155
}
@@ -56,20 +60,12 @@ public void onPostExecute(Recipients members) {
5660
progress.dismiss();
5761
}
5862

59-
List<String> recipientStrings = new LinkedList<>();
60-
recipientStrings.add(context.getString(R.string.GroupMembersDialog_me));
61-
62-
for (Recipient recipient : members.getRecipientsList()) {
63-
if (!isLocalNumber(recipient)) {
64-
recipientStrings.add(recipient.toShortString());
65-
}
66-
}
67-
63+
GroupMembers groupMembers = new GroupMembers(members);
6864
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(context);
6965
builder.setTitle(R.string.ConversationActivity_group_members);
7066
builder.setIconAttribute(R.attr.group_members_dialog_icon);
7167
builder.setCancelable(true);
72-
builder.setItems(recipientStrings.toArray(new String[]{}), null);
68+
builder.setItems(groupMembers.getRecipientStrings(), new GroupMembersOnClickListener(context, groupMembers));
7369
builder.setPositiveButton(android.R.string.ok, null);
7470
builder.show();
7571
}
@@ -79,15 +75,83 @@ public void display() {
7975
else onPostExecute(recipients);
8076
}
8177

82-
private boolean isLocalNumber(Recipient recipient) {
83-
try {
84-
String localNumber = TextSecurePreferences.getLocalNumber(context);
85-
String e164Number = Util.canonicalizeNumber(context, recipient.getNumber());
78+
private class GroupMembersOnClickListener implements DialogInterface.OnClickListener {
79+
private final GroupMembers groupMembers;
80+
private final Context context;
8681

87-
return e164Number != null && e164Number.equals(localNumber);
88-
} catch (InvalidNumberException e) {
89-
Log.w(TAG, e);
90-
return false;
82+
public GroupMembersOnClickListener(Context context, GroupMembers members) {
83+
this.context = context;
84+
this.groupMembers = members;
85+
}
86+
87+
@Override
88+
public void onClick(DialogInterface dialogInterface, int item) {
89+
Recipient recipient = groupMembers.get(item);
90+
91+
if (recipient.getContactUri() != null) {
92+
ContactsContract.QuickContact.showQuickContact(context, new Rect(0,0,0,0),
93+
recipient.getContactUri(),
94+
ContactsContract.QuickContact.MODE_LARGE, null);
95+
} else {
96+
final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
97+
intent.putExtra(ContactsContract.Intents.Insert.PHONE, recipient.getNumber());
98+
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
99+
context.startActivity(intent);
100+
}
101+
}
102+
}
103+
104+
/**
105+
* Wraps a List of Recipient (just like @class Recipients),
106+
* but with focus on the order of the Recipients.
107+
* So that the order of the RecipientStrings[] matches
108+
* the internal order.
109+
*
110+
* @author Christoph Haefner
111+
*/
112+
private class GroupMembers {
113+
private final String TAG = GroupMembers.class.getSimpleName();
114+
115+
private final LinkedList<Recipient> members = new LinkedList<>();
116+
117+
public GroupMembers(Recipients recipients) {
118+
for (Recipient recipient : recipients.getRecipientsList()) {
119+
if (isLocalNumber(recipient)) {
120+
members.push(recipient);
121+
} else {
122+
members.add(recipient);
123+
}
124+
}
125+
}
126+
127+
public String[] getRecipientStrings() {
128+
List<String> recipientStrings = new LinkedList<>();
129+
130+
for (Recipient recipient : members) {
131+
if (isLocalNumber(recipient)) {
132+
recipientStrings.add(context.getString(R.string.GroupMembersDialog_me));
133+
} else {
134+
recipientStrings.add(recipient.toShortString());
135+
}
136+
}
137+
138+
return recipientStrings.toArray(new String[members.size()]);
139+
}
140+
141+
public Recipient get(int index) {
142+
return members.get(index);
143+
}
144+
145+
private boolean isLocalNumber(Recipient recipient) {
146+
try {
147+
String localNumber = TextSecurePreferences.getLocalNumber(context);
148+
String e164Number = Util.canonicalizeNumber(context, recipient.getNumber());
149+
150+
return e164Number != null && e164Number.equals(localNumber);
151+
} catch (InvalidNumberException e) {
152+
Log.w(TAG, e);
153+
return false;
154+
}
91155
}
92156
}
93157
}

0 commit comments

Comments
 (0)