2014-02-28 06:44:02 +00:00
|
|
|
/**
|
|
|
|
* Copyright (C) 2014 Open Whisper Systems
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-01-19 02:17:08 +00:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
2014-02-13 01:17:33 +00:00
|
|
|
import android.content.Context;
|
2014-01-19 02:17:08 +00:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.graphics.Bitmap;
|
2014-02-18 01:31:48 +00:00
|
|
|
import android.graphics.BitmapFactory;
|
|
|
|
import android.net.Uri;
|
2014-02-13 19:44:07 +00:00
|
|
|
import android.os.AsyncTask;
|
2014-01-19 02:17:08 +00:00
|
|
|
import android.os.Bundle;
|
2014-02-12 20:05:18 +00:00
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.TextWatcher;
|
2014-01-19 02:17:08 +00:00
|
|
|
import android.util.Log;
|
2014-02-18 06:04:08 +00:00
|
|
|
import android.util.Pair;
|
2014-06-29 03:40:57 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2014-01-19 02:17:08 +00:00
|
|
|
import android.view.View;
|
2014-02-12 20:05:18 +00:00
|
|
|
import android.widget.EditText;
|
2014-02-07 02:06:23 +00:00
|
|
|
import android.widget.ImageView;
|
2014-01-19 02:17:08 +00:00
|
|
|
import android.widget.ListView;
|
2014-02-13 19:44:07 +00:00
|
|
|
import android.widget.TextView;
|
2014-02-17 23:23:47 +00:00
|
|
|
import android.widget.Toast;
|
2014-01-19 02:17:08 +00:00
|
|
|
|
2014-02-20 05:06:54 +00:00
|
|
|
import com.google.protobuf.ByteString;
|
2014-12-30 01:31:41 +00:00
|
|
|
import com.soundcloud.android.crop.Crop;
|
2014-01-19 02:17:08 +00:00
|
|
|
|
2014-02-07 02:06:23 +00:00
|
|
|
import org.thoughtcrime.securesms.components.PushRecipientsPanel;
|
2014-02-03 19:52:27 +00:00
|
|
|
import org.thoughtcrime.securesms.contacts.ContactAccessor;
|
2014-02-20 23:41:52 +00:00
|
|
|
import org.thoughtcrime.securesms.contacts.RecipientsEditor;
|
2014-02-14 01:10:20 +00:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
|
|
import org.thoughtcrime.securesms.database.GroupDatabase;
|
|
|
|
import org.thoughtcrime.securesms.database.ThreadDatabase;
|
2014-02-24 08:19:54 +00:00
|
|
|
import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage;
|
2014-01-19 02:17:08 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2014-02-03 19:52:27 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
2014-01-19 02:17:08 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
2014-02-17 19:42:51 +00:00
|
|
|
import org.thoughtcrime.securesms.sms.MessageSender;
|
2014-12-16 03:48:20 +00:00
|
|
|
import org.thoughtcrime.securesms.util.BitmapDecodingException;
|
2014-02-19 06:08:24 +00:00
|
|
|
import org.thoughtcrime.securesms.util.BitmapUtil;
|
2014-01-19 02:17:08 +00:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
2014-02-14 01:10:20 +00:00
|
|
|
import org.thoughtcrime.securesms.util.GroupUtil;
|
2014-03-15 00:23:39 +00:00
|
|
|
import org.thoughtcrime.securesms.util.ProgressDialogAsyncTask;
|
2014-01-19 02:17:08 +00:00
|
|
|
import org.thoughtcrime.securesms.util.SelectedRecipientsAdapter;
|
2014-02-14 01:10:20 +00:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2014-02-13 01:17:33 +00:00
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
2014-11-03 23:16:04 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
2014-11-10 04:35:08 +00:00
|
|
|
import org.thoughtcrime.securesms.database.TextSecureDirectory;
|
|
|
|
import org.thoughtcrime.securesms.database.NotInDirectoryException;
|
2014-11-12 19:15:05 +00:00
|
|
|
import org.whispersystems.textsecure.api.util.InvalidNumberException;
|
2014-01-19 02:17:08 +00:00
|
|
|
|
2014-02-13 20:15:26 +00:00
|
|
|
import java.io.ByteArrayOutputStream;
|
2014-12-30 01:31:41 +00:00
|
|
|
import java.io.File;
|
2014-03-03 03:30:50 +00:00
|
|
|
import java.io.FileNotFoundException;
|
2014-02-18 01:31:48 +00:00
|
|
|
import java.io.IOException;
|
2014-01-19 02:17:08 +00:00
|
|
|
import java.util.ArrayList;
|
2014-02-13 01:17:33 +00:00
|
|
|
import java.util.Collection;
|
2014-01-19 02:17:08 +00:00
|
|
|
import java.util.HashSet;
|
2014-02-14 01:10:20 +00:00
|
|
|
import java.util.LinkedList;
|
2014-01-19 02:17:08 +00:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2014-02-17 19:42:51 +00:00
|
|
|
import ws.com.google.android.mms.MmsException;
|
|
|
|
|
2014-02-03 19:52:27 +00:00
|
|
|
import static org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData;
|
2014-11-12 19:35:54 +00:00
|
|
|
import static org.whispersystems.textsecure.internal.push.PushMessageProtos.PushMessageContent.GroupContext;
|
2014-02-03 19:52:27 +00:00
|
|
|
|
2014-02-28 06:44:02 +00:00
|
|
|
/**
|
|
|
|
* Activity to create and update groups
|
|
|
|
*
|
|
|
|
* @author Jake McGinty
|
|
|
|
*/
|
2014-06-29 03:40:57 +00:00
|
|
|
public class GroupCreateActivity extends PassphraseRequiredActionBarActivity {
|
2014-01-19 02:17:08 +00:00
|
|
|
|
2014-02-19 00:28:54 +00:00
|
|
|
private final static String TAG = GroupCreateActivity.class.getSimpleName();
|
2014-02-07 02:06:23 +00:00
|
|
|
|
2014-02-20 23:41:52 +00:00
|
|
|
public static final String GROUP_RECIPIENT_EXTRA = "group_recipient";
|
2014-12-18 02:14:19 +00:00
|
|
|
public static final String GROUP_THREAD_EXTRA = "group_thread";
|
|
|
|
public static final String MASTER_SECRET_EXTRA = "master_secret";
|
2014-02-13 20:36:31 +00:00
|
|
|
|
2014-01-19 02:17:08 +00:00
|
|
|
private final DynamicTheme dynamicTheme = new DynamicTheme();
|
|
|
|
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
|
|
|
|
|
|
|
private static final int PICK_CONTACT = 1;
|
2014-02-07 02:06:23 +00:00
|
|
|
private static final int PICK_AVATAR = 2;
|
2014-02-20 23:41:52 +00:00
|
|
|
public static final int AVATAR_SIZE = 210;
|
2014-02-07 02:06:23 +00:00
|
|
|
|
2014-02-12 20:05:18 +00:00
|
|
|
private EditText groupName;
|
2014-02-07 02:06:23 +00:00
|
|
|
private ListView lv;
|
|
|
|
private PushRecipientsPanel recipientsPanel;
|
|
|
|
private ImageView avatar;
|
2014-02-19 06:08:24 +00:00
|
|
|
private TextView creatingText;
|
2014-02-20 23:41:52 +00:00
|
|
|
|
2014-12-18 02:14:19 +00:00
|
|
|
private Recipient groupRecipient = null;
|
2014-02-20 23:41:52 +00:00
|
|
|
private long groupThread = -1;
|
|
|
|
private byte[] groupId = null;
|
|
|
|
private Set<Recipient> existingContacts = null;
|
|
|
|
private String existingTitle = null;
|
|
|
|
private Bitmap existingAvatarBmp = null;
|
2014-01-19 02:17:08 +00:00
|
|
|
|
2014-02-13 20:36:31 +00:00
|
|
|
private MasterSecret masterSecret;
|
|
|
|
private Bitmap avatarBmp;
|
2014-01-19 02:17:08 +00:00
|
|
|
private Set<Recipient> selectedContacts;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle state) {
|
|
|
|
dynamicTheme.onCreate(this);
|
|
|
|
dynamicLanguage.onCreate(this);
|
|
|
|
super.onCreate(state);
|
|
|
|
|
|
|
|
setContentView(R.layout.group_create_activity);
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
|
|
|
selectedContacts = new HashSet<Recipient>();
|
|
|
|
initializeResources();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
dynamicTheme.onResume(this);
|
2014-02-18 01:31:48 +00:00
|
|
|
dynamicLanguage.onResume(this);
|
2014-04-09 20:26:06 +00:00
|
|
|
getSupportActionBar().setTitle(R.string.GroupCreateActivity_actionbar_title);
|
2014-02-18 01:31:48 +00:00
|
|
|
if (!TextSecurePreferences.isPushRegistered(this)) {
|
|
|
|
disableWhisperGroupUi(R.string.GroupCreateActivity_you_dont_support_push);
|
|
|
|
}
|
2014-01-19 02:17:08 +00:00
|
|
|
}
|
|
|
|
|
2014-02-13 20:15:26 +00:00
|
|
|
private boolean whisperGroupUiEnabled() {
|
|
|
|
return groupName.isEnabled() && avatar.isEnabled();
|
|
|
|
}
|
|
|
|
|
2014-02-18 01:31:48 +00:00
|
|
|
private void disableWhisperGroupUi(int reasonResId) {
|
2014-02-13 01:17:33 +00:00
|
|
|
View pushDisabled = findViewById(R.id.push_disabled);
|
|
|
|
pushDisabled.setVisibility(View.VISIBLE);
|
2014-02-20 23:41:52 +00:00
|
|
|
((TextView) findViewById(R.id.push_disabled_reason)).setText(reasonResId);
|
2014-02-13 01:17:33 +00:00
|
|
|
avatar.setEnabled(false);
|
|
|
|
groupName.setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2014-02-13 20:15:26 +00:00
|
|
|
private void enableWhisperGroupUi() {
|
2014-02-13 01:17:33 +00:00
|
|
|
findViewById(R.id.push_disabled).setVisibility(View.GONE);
|
|
|
|
avatar.setEnabled(true);
|
|
|
|
groupName.setEnabled(true);
|
|
|
|
final CharSequence groupNameText = groupName.getText();
|
2014-03-15 00:23:39 +00:00
|
|
|
if (groupNameText != null && groupNameText.length() > 0) {
|
2014-02-13 01:17:33 +00:00
|
|
|
getSupportActionBar().setTitle(groupNameText);
|
2014-03-15 00:23:39 +00:00
|
|
|
} else {
|
2014-02-13 01:17:33 +00:00
|
|
|
getSupportActionBar().setTitle(R.string.GroupCreateActivity_actionbar_title);
|
2014-03-15 00:23:39 +00:00
|
|
|
}
|
2014-02-13 01:17:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean isActiveInDirectory(Context context, Recipient recipient) {
|
|
|
|
try {
|
2014-11-10 04:35:08 +00:00
|
|
|
if (!TextSecureDirectory.getInstance(context).isActiveNumber(Util.canonicalizeNumber(context, recipient.getNumber()))) {
|
2014-02-13 01:17:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} catch (NotInDirectoryException e) {
|
|
|
|
return false;
|
2014-02-13 20:36:31 +00:00
|
|
|
} catch (InvalidNumberException e) {
|
2014-02-13 01:17:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addSelectedContact(Recipient contact) {
|
2014-04-01 23:40:16 +00:00
|
|
|
final boolean isPushUser = isActiveInDirectory(this, contact);
|
|
|
|
if (existingContacts != null && !isPushUser) {
|
|
|
|
Toast.makeText(getApplicationContext(),
|
|
|
|
R.string.GroupCreateActivity_cannot_add_non_push_to_existing_group,
|
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-20 23:41:52 +00:00
|
|
|
if (!selectedContacts.contains(contact) && (existingContacts == null || !existingContacts.contains(contact)))
|
|
|
|
selectedContacts.add(contact);
|
2014-04-01 23:40:16 +00:00
|
|
|
if (!isPushUser) {
|
2014-02-20 23:41:52 +00:00
|
|
|
disableWhisperGroupUi(R.string.GroupCreateActivity_contacts_dont_support_push);
|
|
|
|
getSupportActionBar().setTitle(R.string.GroupCreateActivity_actionbar_mms_title);
|
|
|
|
}
|
2014-02-13 01:17:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void addAllSelectedContacts(Collection<Recipient> contacts) {
|
|
|
|
for (Recipient contact : contacts) {
|
|
|
|
addSelectedContact(contact);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void removeSelectedContact(Recipient contact) {
|
|
|
|
selectedContacts.remove(contact);
|
|
|
|
if (!isActiveInDirectory(this, contact)) {
|
|
|
|
for (Recipient recipient : selectedContacts) {
|
|
|
|
if (!isActiveInDirectory(this, recipient))
|
|
|
|
return;
|
|
|
|
}
|
2014-02-13 20:15:26 +00:00
|
|
|
enableWhisperGroupUi();
|
2014-02-13 01:17:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-19 02:17:08 +00:00
|
|
|
private void initializeResources() {
|
2014-12-18 02:14:19 +00:00
|
|
|
groupRecipient = RecipientFactory.getRecipientForId(this, getIntent().getLongExtra(GROUP_RECIPIENT_EXTRA, -1), true);
|
2014-02-20 23:41:52 +00:00
|
|
|
groupThread = getIntent().getLongExtra(GROUP_THREAD_EXTRA, -1);
|
|
|
|
if (groupRecipient != null) {
|
2014-12-18 02:14:19 +00:00
|
|
|
final String encodedGroupId = groupRecipient.getNumber();
|
2014-02-20 23:41:52 +00:00
|
|
|
if (encodedGroupId != null) {
|
|
|
|
try {
|
|
|
|
groupId = GroupUtil.getDecodedId(encodedGroupId);
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
Log.w(TAG, "Couldn't decode the encoded groupId passed in via intent", ioe);
|
|
|
|
groupId = null;
|
|
|
|
}
|
|
|
|
if (groupId != null) {
|
|
|
|
new FillExistingGroupInfoAsyncTask().execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-13 20:36:31 +00:00
|
|
|
masterSecret = getIntent().getParcelableExtra(MASTER_SECRET_EXTRA);
|
2014-02-19 06:08:24 +00:00
|
|
|
|
|
|
|
lv = (ListView) findViewById(R.id.selected_contacts_list);
|
|
|
|
avatar = (ImageView) findViewById(R.id.avatar);
|
|
|
|
groupName = (EditText) findViewById(R.id.group_name);
|
|
|
|
creatingText = (TextView) findViewById(R.id.creating_group_text);
|
|
|
|
recipientsPanel = (PushRecipientsPanel) findViewById(R.id.recipients);
|
|
|
|
|
2014-02-12 20:05:18 +00:00
|
|
|
groupName.addTextChangedListener(new TextWatcher() {
|
|
|
|
@Override
|
|
|
|
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { }
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { }
|
|
|
|
@Override
|
|
|
|
public void afterTextChanged(Editable editable) {
|
2014-03-15 00:23:39 +00:00
|
|
|
final int prefixResId = (groupId != null)
|
|
|
|
? R.string.GroupCreateActivity_actionbar_update_title
|
|
|
|
: R.string.GroupCreateActivity_actionbar_title;
|
2014-02-20 23:41:52 +00:00
|
|
|
if (editable.length() > 0) {
|
|
|
|
getSupportActionBar().setTitle(getString(prefixResId) + ": " + editable.toString());
|
|
|
|
} else {
|
2014-03-15 00:23:39 +00:00
|
|
|
getSupportActionBar().setTitle(prefixResId);
|
2014-02-20 23:41:52 +00:00
|
|
|
}
|
2014-02-12 20:05:18 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-02-20 23:41:52 +00:00
|
|
|
SelectedRecipientsAdapter adapter = new SelectedRecipientsAdapter(this, android.R.id.text1, new ArrayList<SelectedRecipientsAdapter.RecipientWrapper>());
|
2014-02-13 01:17:33 +00:00
|
|
|
adapter.setOnRecipientDeletedListener(new SelectedRecipientsAdapter.OnRecipientDeletedListener() {
|
|
|
|
@Override
|
|
|
|
public void onRecipientDeleted(Recipient recipient) {
|
|
|
|
removeSelectedContact(recipient);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
lv.setAdapter(adapter);
|
2014-02-07 02:06:23 +00:00
|
|
|
|
|
|
|
recipientsPanel.setPanelChangeListener(new PushRecipientsPanel.RecipientsPanelChangedListener() {
|
|
|
|
@Override
|
|
|
|
public void onRecipientsPanelUpdate(Recipients recipients) {
|
|
|
|
Log.i(TAG, "onRecipientsPanelUpdate received.");
|
|
|
|
if (recipients != null) {
|
2014-02-13 01:17:33 +00:00
|
|
|
addAllSelectedContacts(recipients.getRecipientsList());
|
2014-02-07 02:06:23 +00:00
|
|
|
syncAdapterWithSelectedContacts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
(findViewById(R.id.contacts_button)).setOnClickListener(new AddRecipientButtonListener());
|
|
|
|
|
|
|
|
avatar.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2014-12-30 01:31:41 +00:00
|
|
|
Crop.pickImage(GroupCreateActivity.this);
|
2014-02-07 02:06:23 +00:00
|
|
|
}
|
|
|
|
});
|
2014-02-20 23:41:52 +00:00
|
|
|
|
|
|
|
((RecipientsEditor)findViewById(R.id.recipients_text)).setHint(R.string.recipients_panel__add_member);
|
2014-01-19 02:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
2014-06-29 03:40:57 +00:00
|
|
|
MenuInflater inflater = this.getMenuInflater();
|
2014-01-19 02:17:08 +00:00
|
|
|
menu.clear();
|
|
|
|
|
|
|
|
inflater.inflate(R.menu.group_create, menu);
|
|
|
|
super.onPrepareOptionsMenu(menu);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
super.onOptionsItemSelected(item);
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case android.R.id.home:
|
2014-02-13 19:44:07 +00:00
|
|
|
finish();
|
|
|
|
return true;
|
2014-01-19 02:17:08 +00:00
|
|
|
case R.id.menu_create_group:
|
2014-02-20 23:41:52 +00:00
|
|
|
if (groupId == null) handleGroupCreate();
|
|
|
|
else handleGroupUpdate();
|
2014-02-17 23:23:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-02-13 19:44:07 +00:00
|
|
|
|
2014-02-17 23:23:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-02-13 19:44:07 +00:00
|
|
|
|
2014-02-17 23:23:47 +00:00
|
|
|
private void handleGroupCreate() {
|
|
|
|
if (selectedContacts.size() < 1) {
|
2014-02-18 00:36:31 +00:00
|
|
|
Log.i(TAG, getString(R.string.GroupCreateActivity_contacts_no_members));
|
|
|
|
Toast.makeText(getApplicationContext(), R.string.GroupCreateActivity_contacts_no_members, Toast.LENGTH_SHORT).show();
|
2014-02-17 23:23:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (whisperGroupUiEnabled()) {
|
2014-03-15 00:23:39 +00:00
|
|
|
enableWhisperGroupProgressUi(false);
|
2014-02-18 00:36:31 +00:00
|
|
|
new CreateWhisperGroupAsyncTask().execute();
|
2014-02-17 23:23:47 +00:00
|
|
|
} else {
|
2014-02-18 00:36:31 +00:00
|
|
|
new CreateMmsGroupAsyncTask().execute();
|
|
|
|
}
|
|
|
|
}
|
2014-01-19 02:17:08 +00:00
|
|
|
|
2014-02-22 01:51:25 +00:00
|
|
|
private void handleGroupUpdate() {
|
2014-03-15 00:23:39 +00:00
|
|
|
if (whisperGroupUiEnabled()) {
|
|
|
|
enableWhisperGroupProgressUi(true);
|
|
|
|
}
|
2014-02-22 01:51:25 +00:00
|
|
|
new UpdateWhisperGroupAsyncTask().execute();
|
|
|
|
}
|
|
|
|
|
2014-03-15 00:23:39 +00:00
|
|
|
private void enableWhisperGroupProgressUi(boolean isGroupUpdate) {
|
2014-02-18 00:36:31 +00:00
|
|
|
findViewById(R.id.group_details_layout).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.creating_group_layout).setVisibility(View.VISIBLE);
|
|
|
|
findViewById(R.id.menu_create_group).setVisibility(View.GONE);
|
2014-03-15 00:23:39 +00:00
|
|
|
if (groupName.getText() != null) {
|
|
|
|
final int titleResId = isGroupUpdate
|
|
|
|
? R.string.GroupCreateActivity_updating_group
|
|
|
|
: R.string.GroupCreateActivity_creating_group;
|
|
|
|
creatingText.setText(getString(titleResId, groupName.getText().toString()));
|
|
|
|
}
|
2014-02-18 00:36:31 +00:00
|
|
|
}
|
2014-02-17 23:23:47 +00:00
|
|
|
|
2014-03-15 00:23:39 +00:00
|
|
|
private void disableWhisperGroupProgressUi() {
|
2014-02-18 00:36:31 +00:00
|
|
|
findViewById(R.id.group_details_layout).setVisibility(View.VISIBLE);
|
|
|
|
findViewById(R.id.creating_group_layout).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.menu_create_group).setVisibility(View.VISIBLE);
|
2014-01-19 02:17:08 +00:00
|
|
|
}
|
|
|
|
|
2014-02-07 02:06:23 +00:00
|
|
|
private void syncAdapterWithSelectedContacts() {
|
|
|
|
SelectedRecipientsAdapter adapter = (SelectedRecipientsAdapter)lv.getAdapter();
|
|
|
|
adapter.clear();
|
|
|
|
for (Recipient contact : selectedContacts) {
|
2014-02-20 23:41:52 +00:00
|
|
|
adapter.add(new SelectedRecipientsAdapter.RecipientWrapper(contact, true));
|
|
|
|
}
|
|
|
|
if (existingContacts != null) {
|
|
|
|
for (Recipient contact : existingContacts) {
|
|
|
|
adapter.add(new SelectedRecipientsAdapter.RecipientWrapper(contact, false));
|
|
|
|
}
|
2014-02-07 02:06:23 +00:00
|
|
|
}
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
2014-01-19 02:17:08 +00:00
|
|
|
@Override
|
|
|
|
public void onActivityResult(int reqCode, int resultCode, Intent data) {
|
|
|
|
super.onActivityResult(reqCode, resultCode, data);
|
2014-12-30 01:31:41 +00:00
|
|
|
Uri outputFile = Uri.fromFile(new File(getCacheDir(), "cropped"));
|
2014-01-19 02:17:08 +00:00
|
|
|
|
|
|
|
if (data == null || resultCode != Activity.RESULT_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (reqCode) {
|
|
|
|
case PICK_CONTACT:
|
2014-02-03 19:52:27 +00:00
|
|
|
List<ContactData> selected = data.getParcelableArrayListExtra("contacts");
|
|
|
|
for (ContactData contact : selected) {
|
|
|
|
for (ContactAccessor.NumberData numberData : contact.numbers) {
|
|
|
|
try {
|
2014-02-07 02:06:23 +00:00
|
|
|
Recipient recipient = RecipientFactory.getRecipientsFromString(this, numberData.number, false)
|
2014-02-03 19:52:27 +00:00
|
|
|
.getPrimaryRecipient();
|
|
|
|
|
2014-02-20 23:41:52 +00:00
|
|
|
if (!selectedContacts.contains(recipient)
|
|
|
|
&& (existingContacts == null || !existingContacts.contains(recipient))) {
|
2014-02-13 01:17:33 +00:00
|
|
|
addSelectedContact(recipient);
|
2014-02-03 19:52:27 +00:00
|
|
|
}
|
|
|
|
} catch (RecipientFormattingException e) {
|
2014-02-19 06:08:24 +00:00
|
|
|
Log.w(TAG, e);
|
2014-02-03 19:52:27 +00:00
|
|
|
}
|
2014-01-19 02:17:08 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-07 02:06:23 +00:00
|
|
|
syncAdapterWithSelectedContacts();
|
2014-01-19 02:17:08 +00:00
|
|
|
break;
|
2014-03-03 03:30:50 +00:00
|
|
|
|
2014-12-30 01:31:41 +00:00
|
|
|
case Crop.REQUEST_PICK:
|
|
|
|
new Crop(data.getData()).output(outputFile).asSquare().start(this);
|
2014-03-03 03:30:50 +00:00
|
|
|
break;
|
2014-12-30 01:31:41 +00:00
|
|
|
case Crop.REQUEST_CROP:
|
|
|
|
new DecodeCropAndSetAsyncTask(Crop.getOutput(data)).execute();
|
2014-01-19 02:17:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class AddRecipientButtonListener implements View.OnClickListener {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent intent = new Intent(GroupCreateActivity.this, PushContactSelectionActivity.class);
|
2014-04-01 23:40:16 +00:00
|
|
|
if (existingContacts != null) intent.putExtra(PushContactSelectionActivity.PUSH_ONLY_EXTRA, true);
|
2014-01-19 02:17:08 +00:00
|
|
|
startActivityForResult(intent, PICK_CONTACT);
|
|
|
|
}
|
|
|
|
}
|
2014-02-13 20:15:26 +00:00
|
|
|
|
2014-02-22 01:51:25 +00:00
|
|
|
private Pair<Long, Recipients> handleCreatePushGroup(String groupName, byte[] avatar,
|
2014-02-20 05:06:54 +00:00
|
|
|
Set<Recipient> members)
|
2014-02-17 21:19:49 +00:00
|
|
|
throws InvalidNumberException, MmsException
|
2014-02-14 01:10:20 +00:00
|
|
|
{
|
2014-02-22 01:51:25 +00:00
|
|
|
GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(this);
|
|
|
|
byte[] groupId = groupDatabase.allocateGroupId();
|
2014-02-24 08:19:54 +00:00
|
|
|
Set<String> memberE164Numbers = getE164Numbers(members);
|
|
|
|
|
|
|
|
memberE164Numbers.add(TextSecurePreferences.getLocalNumber(this));
|
2014-02-17 21:19:49 +00:00
|
|
|
|
2014-02-24 08:19:54 +00:00
|
|
|
groupDatabase.create(groupId, groupName, new LinkedList<String>(memberE164Numbers), null, null);
|
2014-02-22 01:51:25 +00:00
|
|
|
groupDatabase.updateAvatar(groupId, avatar);
|
2014-02-14 01:10:20 +00:00
|
|
|
|
2014-02-22 01:51:25 +00:00
|
|
|
return handlePushOperation(groupId, groupName, avatar, memberE164Numbers);
|
|
|
|
}
|
|
|
|
|
|
|
|
private Pair<Long, Recipients> handleUpdatePushGroup(byte[] groupId, String groupName,
|
|
|
|
byte[] avatar, Set<Recipient> members)
|
|
|
|
throws InvalidNumberException, MmsException
|
|
|
|
{
|
|
|
|
GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(this);
|
2014-02-24 08:19:54 +00:00
|
|
|
Set<String> memberE164Numbers = getE164Numbers(members);
|
|
|
|
memberE164Numbers.add(TextSecurePreferences.getLocalNumber(this));
|
2014-02-14 01:10:20 +00:00
|
|
|
|
2014-02-24 08:19:54 +00:00
|
|
|
for (String number : memberE164Numbers)
|
|
|
|
Log.w(TAG, "Updating: " + number);
|
2014-02-22 01:51:25 +00:00
|
|
|
|
2014-02-24 08:19:54 +00:00
|
|
|
groupDatabase.updateMembers(groupId, new LinkedList<String>(memberE164Numbers));
|
2014-02-22 01:51:25 +00:00
|
|
|
groupDatabase.updateTitle(groupId, groupName);
|
|
|
|
groupDatabase.updateAvatar(groupId, avatar);
|
|
|
|
|
|
|
|
return handlePushOperation(groupId, groupName, avatar, memberE164Numbers);
|
|
|
|
}
|
|
|
|
|
|
|
|
private Pair<Long, Recipients> handlePushOperation(byte[] groupId, String groupName, byte[] avatar,
|
2014-02-24 08:19:54 +00:00
|
|
|
Set<String> e164numbers)
|
2014-11-08 19:35:58 +00:00
|
|
|
throws InvalidNumberException
|
2014-02-22 01:51:25 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
try {
|
|
|
|
String groupRecipientId = GroupUtil.getEncodedId(groupId);
|
|
|
|
Recipients groupRecipient = RecipientFactory.getRecipientsFromString(this, groupRecipientId, false);
|
2014-02-14 23:59:57 +00:00
|
|
|
|
2014-02-20 05:06:54 +00:00
|
|
|
GroupContext context = GroupContext.newBuilder()
|
|
|
|
.setId(ByteString.copyFrom(groupId))
|
2014-02-22 01:51:25 +00:00
|
|
|
.setType(GroupContext.Type.UPDATE)
|
2014-02-20 05:06:54 +00:00
|
|
|
.setName(groupName)
|
2014-02-22 01:51:25 +00:00
|
|
|
.addAllMembers(e164numbers)
|
2014-02-20 05:06:54 +00:00
|
|
|
.build();
|
|
|
|
|
|
|
|
OutgoingGroupMediaMessage outgoingMessage = new OutgoingGroupMediaMessage(this, groupRecipient, context, avatar);
|
2014-06-11 22:31:59 +00:00
|
|
|
long threadId = MessageSender.send(this, masterSecret, outgoingMessage, -1, false);
|
2014-02-20 05:06:54 +00:00
|
|
|
|
2014-11-08 19:35:58 +00:00
|
|
|
return new Pair<>(threadId, groupRecipient);
|
2014-02-14 23:59:57 +00:00
|
|
|
} catch (RecipientFormattingException e) {
|
2014-02-17 21:19:49 +00:00
|
|
|
throw new AssertionError(e);
|
2014-02-14 23:59:57 +00:00
|
|
|
}
|
2014-02-14 01:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private long handleCreateMmsGroup(Set<Recipient> members) {
|
|
|
|
Recipients recipients = new Recipients(new LinkedList<Recipient>(members));
|
|
|
|
return DatabaseFactory.getThreadDatabase(this)
|
|
|
|
.getThreadIdFor(recipients,
|
|
|
|
ThreadDatabase.DistributionTypes.CONVERSATION);
|
2014-02-13 20:15:26 +00:00
|
|
|
}
|
|
|
|
|
2014-02-20 23:41:52 +00:00
|
|
|
private static <T> ArrayList<T> setToArrayList(Set<T> set) {
|
|
|
|
ArrayList<T> arrayList = new ArrayList<T>(set.size());
|
|
|
|
for (T item : set) {
|
|
|
|
arrayList.add(item);
|
|
|
|
}
|
|
|
|
return arrayList;
|
|
|
|
}
|
|
|
|
|
2014-02-24 08:19:54 +00:00
|
|
|
private Set<String> getE164Numbers(Set<Recipient> recipients)
|
2014-02-14 01:10:20 +00:00
|
|
|
throws InvalidNumberException
|
|
|
|
{
|
2014-02-24 08:19:54 +00:00
|
|
|
Set<String> results = new HashSet<String>();
|
2014-02-14 01:10:20 +00:00
|
|
|
|
|
|
|
for (Recipient recipient : recipients) {
|
|
|
|
results.add(Util.canonicalizeNumber(this, recipient.getNumber()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
2014-02-13 20:15:26 +00:00
|
|
|
}
|
2014-02-18 00:36:31 +00:00
|
|
|
|
2014-02-19 06:08:24 +00:00
|
|
|
private class DecodeCropAndSetAsyncTask extends AsyncTask<Void,Void,Bitmap> {
|
2014-03-03 03:30:50 +00:00
|
|
|
private final Uri avatarUri;
|
|
|
|
|
|
|
|
DecodeCropAndSetAsyncTask(Uri uri) {
|
|
|
|
avatarUri = uri;
|
|
|
|
}
|
2014-02-19 06:08:24 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Bitmap doInBackground(Void... voids) {
|
2014-03-03 03:30:50 +00:00
|
|
|
if (avatarUri != null) {
|
|
|
|
try {
|
2014-12-30 01:31:41 +00:00
|
|
|
avatarBmp = BitmapUtil.createScaledBitmap(GroupCreateActivity.this, masterSecret, avatarUri, AVATAR_SIZE, AVATAR_SIZE);
|
2014-12-30 09:36:51 +00:00
|
|
|
} catch (IOException | BitmapDecodingException e) {
|
2014-03-03 03:30:50 +00:00
|
|
|
Log.w(TAG, e);
|
|
|
|
return null;
|
|
|
|
}
|
2014-02-24 07:30:43 +00:00
|
|
|
}
|
2014-02-19 06:08:24 +00:00
|
|
|
return avatarBmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Bitmap result) {
|
|
|
|
if (avatarBmp != null) avatar.setImageBitmap(avatarBmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-18 04:19:54 +00:00
|
|
|
private class CreateMmsGroupAsyncTask extends AsyncTask<Void,Void,Long> {
|
2014-02-18 00:36:31 +00:00
|
|
|
|
|
|
|
@Override
|
2014-02-18 04:19:54 +00:00
|
|
|
protected Long doInBackground(Void... voids) {
|
2014-02-23 22:38:03 +00:00
|
|
|
return handleCreateMmsGroup(selectedContacts);
|
2014-02-18 00:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-18 04:19:54 +00:00
|
|
|
protected void onPostExecute(Long resultThread) {
|
|
|
|
if (resultThread > -1) {
|
|
|
|
Intent intent = new Intent(GroupCreateActivity.this, ConversationActivity.class);
|
|
|
|
intent.putExtra(ConversationActivity.MASTER_SECRET_EXTRA, masterSecret);
|
|
|
|
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, resultThread.longValue());
|
|
|
|
intent.putExtra(ConversationActivity.DISTRIBUTION_TYPE_EXTRA, ThreadDatabase.DistributionTypes.DEFAULT);
|
|
|
|
|
2014-02-20 23:41:52 +00:00
|
|
|
ArrayList<Recipient> selectedContactsList = setToArrayList(selectedContacts);
|
2014-12-18 02:14:19 +00:00
|
|
|
intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, new Recipients(selectedContactsList).getIds());
|
2014-02-18 04:19:54 +00:00
|
|
|
startActivity(intent);
|
|
|
|
finish();
|
|
|
|
} else {
|
|
|
|
Toast.makeText(getApplicationContext(), R.string.GroupCreateActivity_contacts_mms_exception, Toast.LENGTH_LONG).show();
|
|
|
|
finish();
|
|
|
|
}
|
2014-02-18 00:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onProgressUpdate(Void... values) {
|
|
|
|
super.onProgressUpdate(values);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-22 01:51:25 +00:00
|
|
|
private class UpdateWhisperGroupAsyncTask extends AsyncTask<Void,Void,Pair<Long,Recipients>> {
|
|
|
|
private long RES_BAD_NUMBER = -2;
|
|
|
|
private long RES_MMS_EXCEPTION = -3;
|
|
|
|
@Override
|
|
|
|
protected Pair<Long, Recipients> doInBackground(Void... params) {
|
|
|
|
byte[] avatarBytes = null;
|
2014-04-01 23:40:16 +00:00
|
|
|
final Bitmap bitmap;
|
|
|
|
if (avatarBmp == null) bitmap = existingAvatarBmp;
|
|
|
|
else bitmap = avatarBmp;
|
|
|
|
|
|
|
|
if (bitmap != null) {
|
2014-02-22 01:51:25 +00:00
|
|
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
2014-04-01 23:40:16 +00:00
|
|
|
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
|
2014-02-22 01:51:25 +00:00
|
|
|
avatarBytes = stream.toByteArray();
|
|
|
|
}
|
|
|
|
final String name = (groupName.getText() != null) ? groupName.getText().toString() : null;
|
|
|
|
try {
|
2014-02-24 08:19:54 +00:00
|
|
|
Set<Recipient> unionContacts = new HashSet<Recipient>(selectedContacts);
|
|
|
|
unionContacts.addAll(existingContacts);
|
|
|
|
return handleUpdatePushGroup(groupId, name, avatarBytes, unionContacts);
|
2014-02-22 01:51:25 +00:00
|
|
|
} catch (MmsException e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
return new Pair<Long,Recipients>(RES_MMS_EXCEPTION, null);
|
|
|
|
} catch (InvalidNumberException e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
return new Pair<Long,Recipients>(RES_BAD_NUMBER, null);
|
|
|
|
}
|
|
|
|
}
|
2014-02-24 05:18:08 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Pair<Long, Recipients> groupInfo) {
|
|
|
|
final long threadId = groupInfo.first;
|
|
|
|
final Recipients recipients = groupInfo.second;
|
|
|
|
if (threadId > -1) {
|
|
|
|
Intent intent = getIntent();
|
|
|
|
intent.putExtra(GROUP_THREAD_EXTRA, threadId);
|
2014-12-18 02:14:19 +00:00
|
|
|
intent.putExtra(GROUP_RECIPIENT_EXTRA, recipients.getIds());
|
2014-02-24 05:18:08 +00:00
|
|
|
setResult(RESULT_OK, intent);
|
|
|
|
finish();
|
|
|
|
} else if (threadId == RES_BAD_NUMBER) {
|
|
|
|
Toast.makeText(getApplicationContext(), R.string.GroupCreateActivity_contacts_invalid_number, Toast.LENGTH_LONG).show();
|
2014-03-15 00:23:39 +00:00
|
|
|
disableWhisperGroupProgressUi();
|
2014-02-24 05:18:08 +00:00
|
|
|
} else if (threadId == RES_MMS_EXCEPTION) {
|
|
|
|
Toast.makeText(getApplicationContext(), R.string.GroupCreateActivity_contacts_mms_exception, Toast.LENGTH_LONG).show();
|
|
|
|
setResult(RESULT_CANCELED);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
2014-02-22 01:51:25 +00:00
|
|
|
}
|
|
|
|
|
2014-02-18 06:04:08 +00:00
|
|
|
private class CreateWhisperGroupAsyncTask extends AsyncTask<Void,Void,Pair<Long,Recipients>> {
|
2014-02-18 00:36:31 +00:00
|
|
|
private long RES_BAD_NUMBER = -2;
|
|
|
|
private long RES_MMS_EXCEPTION = -3;
|
|
|
|
|
|
|
|
@Override
|
2014-02-18 06:04:08 +00:00
|
|
|
protected Pair<Long,Recipients> doInBackground(Void... voids) {
|
2014-02-18 04:19:54 +00:00
|
|
|
byte[] avatarBytes = null;
|
2014-02-18 00:36:31 +00:00
|
|
|
if (avatarBmp != null) {
|
|
|
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
|
|
|
avatarBmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
|
2014-02-18 04:19:54 +00:00
|
|
|
avatarBytes = stream.toByteArray();
|
2014-02-18 00:36:31 +00:00
|
|
|
}
|
2014-02-18 04:19:54 +00:00
|
|
|
final String name = (groupName.getText() != null) ? groupName.getText().toString() : null;
|
2014-02-18 00:36:31 +00:00
|
|
|
try {
|
2014-02-18 04:19:54 +00:00
|
|
|
return handleCreatePushGroup(name, avatarBytes, selectedContacts);
|
2014-02-18 00:36:31 +00:00
|
|
|
} catch (MmsException e) {
|
2014-02-19 06:08:24 +00:00
|
|
|
Log.w(TAG, e);
|
2014-02-18 06:04:08 +00:00
|
|
|
return new Pair<Long,Recipients>(RES_MMS_EXCEPTION, null);
|
2014-02-18 00:36:31 +00:00
|
|
|
} catch (InvalidNumberException e) {
|
2014-02-19 06:08:24 +00:00
|
|
|
Log.w(TAG, e);
|
2014-02-18 06:04:08 +00:00
|
|
|
return new Pair<Long,Recipients>(RES_BAD_NUMBER, null);
|
2014-02-18 00:36:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-18 06:04:08 +00:00
|
|
|
protected void onPostExecute(Pair<Long,Recipients> groupInfo) {
|
|
|
|
super.onPostExecute(groupInfo);
|
|
|
|
final long threadId = groupInfo.first;
|
|
|
|
final Recipients recipients = groupInfo.second;
|
|
|
|
if (threadId > -1) {
|
2014-02-18 00:36:31 +00:00
|
|
|
Intent intent = new Intent(GroupCreateActivity.this, ConversationActivity.class);
|
|
|
|
intent.putExtra(ConversationActivity.MASTER_SECRET_EXTRA, masterSecret);
|
2014-02-18 06:04:08 +00:00
|
|
|
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId);
|
2014-02-18 00:36:31 +00:00
|
|
|
intent.putExtra(ConversationActivity.DISTRIBUTION_TYPE_EXTRA, ThreadDatabase.DistributionTypes.DEFAULT);
|
2014-12-18 02:14:19 +00:00
|
|
|
intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients.getIds());
|
2014-02-18 00:36:31 +00:00
|
|
|
startActivity(intent);
|
|
|
|
finish();
|
2014-02-18 06:04:08 +00:00
|
|
|
} else if (threadId == RES_BAD_NUMBER) {
|
2014-02-18 00:36:31 +00:00
|
|
|
Toast.makeText(getApplicationContext(), R.string.GroupCreateActivity_contacts_invalid_number, Toast.LENGTH_LONG).show();
|
2014-03-15 00:23:39 +00:00
|
|
|
disableWhisperGroupProgressUi();
|
2014-02-18 06:04:08 +00:00
|
|
|
} else if (threadId == RES_MMS_EXCEPTION) {
|
2014-02-18 00:36:31 +00:00
|
|
|
Toast.makeText(getApplicationContext(), R.string.GroupCreateActivity_contacts_mms_exception, Toast.LENGTH_LONG).show();
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onProgressUpdate(Void... values) {
|
|
|
|
super.onProgressUpdate(values);
|
|
|
|
}
|
|
|
|
}
|
2014-02-20 23:41:52 +00:00
|
|
|
|
2014-03-15 00:23:39 +00:00
|
|
|
private class FillExistingGroupInfoAsyncTask extends ProgressDialogAsyncTask<Void,Void,Void> {
|
2014-02-20 23:41:52 +00:00
|
|
|
|
2014-03-15 00:23:39 +00:00
|
|
|
public FillExistingGroupInfoAsyncTask() {
|
|
|
|
super(GroupCreateActivity.this,
|
|
|
|
R.string.GroupCreateActivity_loading_group_details,
|
|
|
|
R.string.please_wait);
|
2014-02-20 23:41:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-04-11 17:00:30 +00:00
|
|
|
protected Void doInBackground(Void... voids) {
|
2014-02-20 23:41:52 +00:00
|
|
|
final GroupDatabase db = DatabaseFactory.getGroupDatabase(GroupCreateActivity.this);
|
2014-02-24 08:19:54 +00:00
|
|
|
final Recipients recipients = db.getGroupMembers(groupId, false);
|
2014-02-20 23:41:52 +00:00
|
|
|
if (recipients != null) {
|
|
|
|
final List<Recipient> recipientList = recipients.getRecipientsList();
|
|
|
|
if (recipientList != null) {
|
|
|
|
if (existingContacts == null)
|
2014-03-15 00:23:39 +00:00
|
|
|
existingContacts = new HashSet<>(recipientList.size());
|
2014-02-20 23:41:52 +00:00
|
|
|
existingContacts.addAll(recipientList);
|
|
|
|
}
|
|
|
|
}
|
2014-02-22 01:51:25 +00:00
|
|
|
GroupDatabase.GroupRecord group = db.getGroup(groupId);
|
2014-02-20 23:41:52 +00:00
|
|
|
if (group != null) {
|
|
|
|
existingTitle = group.getTitle();
|
|
|
|
final byte[] existingAvatar = group.getAvatar();
|
|
|
|
if (existingAvatar != null) {
|
2014-12-30 01:31:41 +00:00
|
|
|
existingAvatarBmp = BitmapFactory.decodeByteArray(existingAvatar, 0, existingAvatar.length);
|
2014-02-20 23:41:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-04-11 17:00:30 +00:00
|
|
|
protected void onPostExecute(Void aVoid) {
|
|
|
|
super.onPostExecute(aVoid);
|
2014-02-20 23:41:52 +00:00
|
|
|
|
|
|
|
if (existingTitle != null) groupName.setText(existingTitle);
|
|
|
|
if (existingAvatarBmp != null) avatar.setImageBitmap(existingAvatarBmp);
|
|
|
|
if (existingContacts != null) syncAdapterWithSelectedContacts();
|
|
|
|
}
|
|
|
|
}
|
2014-01-19 02:17:08 +00:00
|
|
|
}
|