2014-02-15 19:28:07 +00:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.app.ProgressDialog;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.os.AsyncTask;
|
|
|
|
import android.util.Log;
|
|
|
|
|
2015-03-24 12:44:22 +00:00
|
|
|
import com.afollestad.materialdialogs.AlertDialogWrapper;
|
|
|
|
|
2014-02-15 19:28:07 +00:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
|
|
|
import org.thoughtcrime.securesms.util.GroupUtil;
|
2014-11-28 18:46:50 +00:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
|
|
|
import org.whispersystems.textsecure.api.util.InvalidNumberException;
|
2014-02-15 19:28:07 +00:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class GroupMembersDialog extends AsyncTask<Void, Void, Recipients> {
|
|
|
|
|
2014-11-28 18:46:50 +00:00
|
|
|
private static final String TAG = GroupMembersDialog.class.getSimpleName();
|
|
|
|
|
2014-02-15 19:28:07 +00:00
|
|
|
private final Recipients recipients;
|
|
|
|
private final Context context;
|
|
|
|
|
|
|
|
private ProgressDialog progress = null;
|
|
|
|
|
|
|
|
public GroupMembersDialog(Context context, Recipients recipients) {
|
|
|
|
this.recipients = recipients;
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPreExecute() {
|
2014-12-15 14:44:41 +00:00
|
|
|
progress = ProgressDialog.show(context, context.getString(R.string.GroupMembersDialog_members), context.getString(R.string.GroupMembersDialog_members), true, false);
|
2014-02-15 19:28:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Recipients doInBackground(Void... params) {
|
|
|
|
try {
|
|
|
|
String groupId = recipients.getPrimaryRecipient().getNumber();
|
|
|
|
return DatabaseFactory.getGroupDatabase(context)
|
2014-02-24 08:19:54 +00:00
|
|
|
.getGroupMembers(GroupUtil.getDecodedId(groupId), true);
|
2014-02-15 19:28:07 +00:00
|
|
|
} catch (IOException e) {
|
|
|
|
Log.w("ConverstionActivity", e);
|
|
|
|
return new Recipients(new LinkedList<Recipient>());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPostExecute(Recipients members) {
|
|
|
|
if (progress != null) {
|
|
|
|
progress.dismiss();
|
|
|
|
}
|
|
|
|
|
2014-11-28 18:46:50 +00:00
|
|
|
List<String> recipientStrings = new LinkedList<>();
|
|
|
|
recipientStrings.add(context.getString(R.string.GroupMembersDialog_me));
|
2014-02-15 19:28:07 +00:00
|
|
|
|
|
|
|
for (Recipient recipient : members.getRecipientsList()) {
|
2014-11-28 18:46:50 +00:00
|
|
|
if (!isLocalNumber(recipient)) {
|
|
|
|
recipientStrings.add(recipient.toShortString());
|
|
|
|
}
|
2014-02-15 19:28:07 +00:00
|
|
|
}
|
|
|
|
|
2015-03-24 12:44:22 +00:00
|
|
|
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(context);
|
|
|
|
builder.setTitle(R.string.ConversationActivity_group_members);
|
|
|
|
builder.setIconAttribute(R.attr.group_members_dialog_icon);
|
2014-02-15 19:28:07 +00:00
|
|
|
builder.setCancelable(true);
|
|
|
|
builder.setItems(recipientStrings.toArray(new String[]{}), null);
|
|
|
|
builder.setPositiveButton(android.R.string.ok, null);
|
|
|
|
builder.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void display() {
|
|
|
|
if (recipients.isGroupRecipient()) execute();
|
|
|
|
else onPostExecute(recipients);
|
|
|
|
}
|
2014-11-28 18:46:50 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2014-02-15 19:28:07 +00:00
|
|
|
}
|