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;
|
2015-11-20 22:13:17 +00:00
|
|
|
import android.graphics.drawable.Drawable;
|
2014-02-18 01:31:48 +00:00
|
|
|
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-12-15 20:25:55 +00:00
|
|
|
import android.support.annotation.NonNull;
|
2015-10-28 17:36:21 +00:00
|
|
|
import android.support.annotation.Nullable;
|
2015-11-12 20:20:14 +00:00
|
|
|
import android.text.TextUtils;
|
2014-01-19 02:17:08 +00:00
|
|
|
import android.util.Log;
|
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
|
|
|
|
2015-07-25 00:07:33 +00:00
|
|
|
import com.bumptech.glide.Glide;
|
|
|
|
import com.bumptech.glide.request.animation.GlideAnimation;
|
|
|
|
import com.bumptech.glide.request.target.SimpleTarget;
|
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;
|
2015-11-05 18:41:43 +00:00
|
|
|
import org.thoughtcrime.securesms.components.PushRecipientsPanel.RecipientsPanelChangedListener;
|
2014-02-20 23:41:52 +00:00
|
|
|
import org.thoughtcrime.securesms.contacts.RecipientsEditor;
|
2015-11-20 22:13:17 +00:00
|
|
|
import org.thoughtcrime.securesms.contacts.avatars.ContactColors;
|
|
|
|
import org.thoughtcrime.securesms.contacts.avatars.ContactPhotoFactory;
|
|
|
|
import org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto;
|
2015-05-29 23:23:47 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
2014-02-14 01:10:20 +00:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
|
|
import org.thoughtcrime.securesms.database.GroupDatabase;
|
2015-11-05 18:41:43 +00:00
|
|
|
import org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord;
|
2015-05-29 23:23:47 +00:00
|
|
|
import org.thoughtcrime.securesms.database.NotInDirectoryException;
|
|
|
|
import org.thoughtcrime.securesms.database.TextSecureDirectory;
|
2014-02-14 01:10:20 +00:00
|
|
|
import org.thoughtcrime.securesms.database.ThreadDatabase;
|
2015-11-05 18:41:43 +00:00
|
|
|
import org.thoughtcrime.securesms.groups.GroupManager;
|
|
|
|
import org.thoughtcrime.securesms.groups.GroupManager.GroupActionResult;
|
2015-07-25 00:07:33 +00:00
|
|
|
import org.thoughtcrime.securesms.mms.RoundedCorners;
|
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;
|
2014-01-19 02:17:08 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
2015-11-05 18:41:43 +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;
|
2015-11-05 18:41:43 +00:00
|
|
|
import org.thoughtcrime.securesms.util.SelectedRecipientsAdapter.OnRecipientDeletedListener;
|
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;
|
2015-11-05 18:41:43 +00:00
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
|
|
|
import org.whispersystems.libaxolotl.util.guava.Optional;
|
2014-11-12 19:15:05 +00:00
|
|
|
import org.whispersystems.textsecure.api.util.InvalidNumberException;
|
2014-01-19 02:17:08 +00:00
|
|
|
|
2014-12-30 01:31:41 +00:00
|
|
|
import java.io.File;
|
2014-02-18 01:31:48 +00:00
|
|
|
import java.io.IOException;
|
2014-02-13 01:17:33 +00:00
|
|
|
import java.util.Collection;
|
2014-01-19 02:17:08 +00:00
|
|
|
import java.util.HashSet;
|
2015-11-12 20:20:14 +00:00
|
|
|
import java.util.LinkedList;
|
2014-01-19 02:17:08 +00:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2014-02-28 06:44:02 +00:00
|
|
|
/**
|
|
|
|
* Activity to create and update groups
|
|
|
|
*
|
|
|
|
* @author Jake McGinty
|
|
|
|
*/
|
2015-11-05 18:41:43 +00:00
|
|
|
public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
|
|
|
implements OnRecipientDeletedListener,
|
|
|
|
RecipientsPanelChangedListener
|
|
|
|
{
|
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";
|
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-20 23:41:52 +00:00
|
|
|
public static final int AVATAR_SIZE = 210;
|
2014-02-07 02:06:23 +00:00
|
|
|
|
2015-11-05 18:41:43 +00:00
|
|
|
private EditText groupName;
|
|
|
|
private ListView lv;
|
|
|
|
private ImageView avatar;
|
|
|
|
private TextView creatingText;
|
|
|
|
private MasterSecret masterSecret;
|
|
|
|
private Bitmap avatarBmp;
|
2014-02-20 23:41:52 +00:00
|
|
|
|
2015-11-05 18:41:43 +00:00
|
|
|
@NonNull private Optional<GroupData> groupToUpdate = Optional.absent();
|
2014-01-19 02:17:08 +00:00
|
|
|
|
|
|
|
@Override
|
2014-12-15 20:25:55 +00:00
|
|
|
protected void onPreCreate() {
|
2014-01-19 02:17:08 +00:00
|
|
|
dynamicTheme.onCreate(this);
|
|
|
|
dynamicLanguage.onCreate(this);
|
2014-12-15 20:25:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle state, @NonNull MasterSecret masterSecret) {
|
|
|
|
this.masterSecret = masterSecret;
|
2014-01-19 02:17:08 +00:00
|
|
|
|
|
|
|
setContentView(R.layout.group_create_activity);
|
2015-11-05 18:41:43 +00:00
|
|
|
//noinspection ConstantConditions
|
2014-01-19 02:17:08 +00:00
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
initializeResources();
|
2015-11-05 18:41:43 +00:00
|
|
|
initializeExistingGroup();
|
2014-01-19 02:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
dynamicTheme.onResume(this);
|
2014-02-18 01:31:48 +00:00
|
|
|
dynamicLanguage.onResume(this);
|
2015-11-05 18:41:43 +00:00
|
|
|
updateViewState();
|
2014-01-19 02:17:08 +00:00
|
|
|
}
|
|
|
|
|
2015-11-05 18:41:43 +00:00
|
|
|
private boolean isSignalGroup() {
|
|
|
|
return TextSecurePreferences.isPushRegistered(this) && !getAdapter().hasNonPushMembers();
|
2014-02-13 20:15:26 +00:00
|
|
|
}
|
|
|
|
|
2015-11-05 18:41:43 +00:00
|
|
|
private void disableSignalGroupViews(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);
|
|
|
|
}
|
|
|
|
|
2015-11-05 18:41:43 +00:00
|
|
|
private void enableSignalGroupViews() {
|
2014-02-13 01:17:33 +00:00
|
|
|
findViewById(R.id.push_disabled).setVisibility(View.GONE);
|
|
|
|
avatar.setEnabled(true);
|
|
|
|
groupName.setEnabled(true);
|
2015-11-05 18:41:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("ConstantConditions")
|
|
|
|
private void updateViewState() {
|
|
|
|
if (!TextSecurePreferences.isPushRegistered(this)) {
|
|
|
|
disableSignalGroupViews(R.string.GroupCreateActivity_you_dont_support_push);
|
|
|
|
getSupportActionBar().setTitle(R.string.GroupCreateActivity_actionbar_mms_title);
|
|
|
|
} else if (getAdapter().hasNonPushMembers()) {
|
|
|
|
disableSignalGroupViews(R.string.GroupCreateActivity_contacts_dont_support_push);
|
|
|
|
getSupportActionBar().setTitle(R.string.GroupCreateActivity_actionbar_mms_title);
|
2014-03-15 00:23:39 +00:00
|
|
|
} else {
|
2015-11-05 18:41:43 +00:00
|
|
|
enableSignalGroupViews();
|
2015-11-12 20:20:14 +00:00
|
|
|
getSupportActionBar().setTitle(groupToUpdate.isPresent()
|
|
|
|
? R.string.GroupCreateActivity_actionbar_update_title
|
|
|
|
: 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 {
|
2015-11-05 18:41:43 +00:00
|
|
|
return TextSecureDirectory.getInstance(context)
|
|
|
|
.isSecureTextSupported(Util.canonicalizeNumber(context, recipient.getNumber()));
|
|
|
|
} catch (NotInDirectoryException | InvalidNumberException e) {
|
2014-02-13 01:17:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-12 20:20:14 +00:00
|
|
|
private void addSelectedContacts(@NonNull Recipient... recipients) {
|
|
|
|
new AddMembersTask(this).execute(recipients);
|
2014-02-13 01:17:33 +00:00
|
|
|
}
|
|
|
|
|
2015-11-12 20:20:14 +00:00
|
|
|
private void addSelectedContacts(@NonNull Collection<Recipient> recipients) {
|
|
|
|
addSelectedContacts(recipients.toArray(new Recipient[recipients.size()]));
|
2014-02-13 01:17:33 +00:00
|
|
|
}
|
|
|
|
|
2014-01-19 02:17:08 +00:00
|
|
|
private void initializeResources() {
|
2015-11-05 18:41:43 +00:00
|
|
|
RecipientsEditor recipientsEditor = ViewUtil.findById(this, R.id.recipients_text);
|
|
|
|
PushRecipientsPanel recipientsPanel = ViewUtil.findById(this, R.id.recipients);
|
|
|
|
lv = ViewUtil.findById(this, R.id.selected_contacts_list);
|
|
|
|
avatar = ViewUtil.findById(this, R.id.avatar);
|
|
|
|
groupName = ViewUtil.findById(this, R.id.group_name);
|
|
|
|
creatingText = ViewUtil.findById(this, R.id.creating_group_text);
|
|
|
|
SelectedRecipientsAdapter adapter = new SelectedRecipientsAdapter(this);
|
|
|
|
adapter.setOnRecipientDeletedListener(this);
|
2014-02-13 01:17:33 +00:00
|
|
|
lv.setAdapter(adapter);
|
2015-11-05 18:41:43 +00:00
|
|
|
recipientsEditor.setHint(R.string.recipients_panel__add_member);
|
|
|
|
recipientsPanel.setPanelChangeListener(this);
|
|
|
|
findViewById(R.id.contacts_button).setOnClickListener(new AddRecipientButtonListener());
|
2015-11-20 22:13:17 +00:00
|
|
|
avatar.setImageDrawable(ContactPhotoFactory.getDefaultGroupPhoto()
|
|
|
|
.asDrawable(this, ContactColors.UNKNOWN_COLOR.toConversationColor(this)));
|
2014-02-07 02:06:23 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
});
|
2015-11-05 18:41:43 +00:00
|
|
|
}
|
2014-02-20 23:41:52 +00:00
|
|
|
|
2015-11-05 18:41:43 +00:00
|
|
|
private void initializeExistingGroup() {
|
|
|
|
final String encodedGroupId = RecipientFactory.getRecipientForId(this, getIntent().getLongExtra(GROUP_RECIPIENT_EXTRA, -1), true)
|
|
|
|
.getNumber();
|
|
|
|
byte[] groupId;
|
|
|
|
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(this).execute(groupId);
|
|
|
|
}
|
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:
|
2015-11-05 18:41:43 +00:00
|
|
|
if (groupToUpdate.isPresent()) handleGroupUpdate();
|
|
|
|
else handleGroupCreate();
|
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
|
|
|
|
2015-11-05 18:41:43 +00:00
|
|
|
@Override
|
|
|
|
public void onRecipientDeleted(Recipient recipient) {
|
|
|
|
getAdapter().remove(recipient);
|
|
|
|
updateViewState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRecipientsPanelUpdate(Recipients recipients) {
|
2015-11-12 20:20:14 +00:00
|
|
|
if (recipients != null) addSelectedContacts(recipients.getRecipientsList());
|
2015-11-05 18:41:43 +00:00
|
|
|
}
|
|
|
|
|
2014-02-17 23:23:47 +00:00
|
|
|
private void handleGroupCreate() {
|
2015-11-05 18:41:43 +00:00
|
|
|
if (getAdapter().getCount() < 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;
|
|
|
|
}
|
2015-11-05 18:41:43 +00:00
|
|
|
if (isSignalGroup()) {
|
|
|
|
new CreateSignalGroupTask(this, masterSecret, avatarBmp, getGroupName(), getAdapter().getRecipients()).execute();
|
2014-02-17 23:23:47 +00:00
|
|
|
} else {
|
2015-11-05 18:41:43 +00:00
|
|
|
new CreateMmsGroupTask(this, getAdapter().getRecipients()).execute();
|
2014-02-18 00:36:31 +00:00
|
|
|
}
|
|
|
|
}
|
2014-01-19 02:17:08 +00:00
|
|
|
|
2014-02-22 01:51:25 +00:00
|
|
|
private void handleGroupUpdate() {
|
2015-11-05 18:41:43 +00:00
|
|
|
new UpdateSignalGroupTask(this, masterSecret, groupToUpdate.get().id, avatarBmp,
|
|
|
|
getGroupName(), getAdapter().getRecipients()).execute();
|
2014-02-22 01:51:25 +00:00
|
|
|
}
|
|
|
|
|
2015-11-05 18:41:43 +00:00
|
|
|
private void handleOpenConversation(long threadId, Recipients recipients) {
|
|
|
|
Intent intent = new Intent(this, ConversationActivity.class);
|
|
|
|
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId);
|
|
|
|
intent.putExtra(ConversationActivity.DISTRIBUTION_TYPE_EXTRA, ThreadDatabase.DistributionTypes.DEFAULT);
|
|
|
|
intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients.getIds());
|
|
|
|
startActivity(intent);
|
|
|
|
finish();
|
2014-02-18 00:36:31 +00:00
|
|
|
}
|
2014-02-17 23:23:47 +00:00
|
|
|
|
2015-11-05 18:41:43 +00:00
|
|
|
private SelectedRecipientsAdapter getAdapter() {
|
|
|
|
return (SelectedRecipientsAdapter)lv.getAdapter();
|
2014-01-19 02:17:08 +00:00
|
|
|
}
|
|
|
|
|
2015-11-05 18:41:43 +00:00
|
|
|
private @Nullable String getGroupName() {
|
|
|
|
return groupName.getText() != null ? groupName.getText().toString() : null;
|
2014-02-07 02:06:23 +00:00
|
|
|
}
|
|
|
|
|
2014-01-19 02:17:08 +00:00
|
|
|
@Override
|
2015-07-25 00:07:33 +00:00
|
|
|
public void onActivityResult(int reqCode, int resultCode, final Intent data) {
|
2014-01-19 02:17:08 +00:00
|
|
|
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:
|
2015-05-19 21:00:54 +00:00
|
|
|
List<String> selected = data.getStringArrayListExtra("contacts");
|
|
|
|
for (String contact : selected) {
|
2015-11-05 18:41:43 +00:00
|
|
|
final Recipient recipient = RecipientFactory.getRecipientsFromString(this, contact, false).getPrimaryRecipient();
|
2015-11-12 20:20:14 +00:00
|
|
|
if (recipient != null) addSelectedContacts(recipient);
|
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:
|
2015-07-25 00:07:33 +00:00
|
|
|
Glide.with(this).load(Crop.getOutput(data)).asBitmap().skipMemoryCache(true)
|
|
|
|
.centerCrop().override(AVATAR_SIZE, AVATAR_SIZE)
|
|
|
|
.into(new SimpleTarget<Bitmap>() {
|
2015-11-05 18:41:43 +00:00
|
|
|
@Override
|
|
|
|
public void onResourceReady(Bitmap resource,
|
2015-07-25 00:07:33 +00:00
|
|
|
GlideAnimation<? super Bitmap> glideAnimation)
|
|
|
|
{
|
|
|
|
avatarBmp = resource;
|
|
|
|
Glide.with(GroupCreateActivity.this).load(Crop.getOutput(data)).skipMemoryCache(true)
|
|
|
|
.transform(new RoundedCorners(GroupCreateActivity.this, avatar.getWidth() / 2))
|
|
|
|
.into(avatar);
|
|
|
|
}
|
|
|
|
});
|
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);
|
2015-11-05 18:41:43 +00:00
|
|
|
if (groupToUpdate.isPresent()) intent.putExtra(ContactSelectionListFragment.DISPLAY_MODE,
|
|
|
|
ContactSelectionListFragment.DISPLAY_MODE_PUSH_ONLY);
|
2014-01-19 02:17:08 +00:00
|
|
|
startActivityForResult(intent, PICK_CONTACT);
|
|
|
|
}
|
|
|
|
}
|
2014-02-13 20:15:26 +00:00
|
|
|
|
2015-11-05 18:41:43 +00:00
|
|
|
private static class CreateMmsGroupTask extends AsyncTask<Void,Void,Long> {
|
|
|
|
private GroupCreateActivity activity;
|
|
|
|
private Set<Recipient> members;
|
2014-02-13 20:15:26 +00:00
|
|
|
|
2015-11-05 18:41:43 +00:00
|
|
|
public CreateMmsGroupTask(GroupCreateActivity activity, Set<Recipient> members) {
|
|
|
|
this.activity = activity;
|
|
|
|
this.members = members;
|
2014-02-20 23:41:52 +00:00
|
|
|
}
|
2014-02-18 00:36:31 +00:00
|
|
|
|
|
|
|
@Override
|
2015-11-05 18:41:43 +00:00
|
|
|
protected Long doInBackground(Void... avoid) {
|
|
|
|
Recipients recipients = RecipientFactory.getRecipientsFor(activity, members, false);
|
|
|
|
return DatabaseFactory.getThreadDatabase(activity)
|
|
|
|
.getThreadIdFor(recipients, ThreadDatabase.DistributionTypes.CONVERSATION);
|
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) {
|
2015-11-05 18:41:43 +00:00
|
|
|
activity.handleOpenConversation(resultThread,
|
|
|
|
RecipientFactory.getRecipientsFor(activity, members, true));
|
2014-02-18 04:19:54 +00:00
|
|
|
} else {
|
2015-11-05 18:41:43 +00:00
|
|
|
Toast.makeText(activity, R.string.GroupCreateActivity_contacts_mms_exception, Toast.LENGTH_LONG).show();
|
|
|
|
activity.finish();
|
2014-02-18 04:19:54 +00:00
|
|
|
}
|
2014-02-18 00:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onProgressUpdate(Void... values) {
|
|
|
|
super.onProgressUpdate(values);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-05 18:41:43 +00:00
|
|
|
private abstract static class SignalGroupTask extends AsyncTask<Void,Void,Optional<GroupActionResult>> {
|
|
|
|
protected GroupCreateActivity activity;
|
|
|
|
protected MasterSecret masterSecret;
|
|
|
|
protected Bitmap avatar;
|
|
|
|
protected Set<Recipient> members;
|
|
|
|
protected String name;
|
|
|
|
|
|
|
|
public SignalGroupTask(GroupCreateActivity activity,
|
|
|
|
MasterSecret masterSecret,
|
|
|
|
Bitmap avatar,
|
|
|
|
String name,
|
|
|
|
Set<Recipient> members)
|
|
|
|
{
|
|
|
|
this.activity = activity;
|
|
|
|
this.masterSecret = masterSecret;
|
|
|
|
this.avatar = avatar;
|
|
|
|
this.name = name;
|
|
|
|
this.members = members;
|
|
|
|
}
|
|
|
|
|
2014-02-22 01:51:25 +00:00
|
|
|
@Override
|
2015-11-05 18:41:43 +00:00
|
|
|
protected void onPreExecute() {
|
|
|
|
activity.findViewById(R.id.group_details_layout).setVisibility(View.GONE);
|
|
|
|
activity.findViewById(R.id.creating_group_layout).setVisibility(View.VISIBLE);
|
|
|
|
activity.findViewById(R.id.menu_create_group).setVisibility(View.GONE);
|
|
|
|
final int titleResId = activity.groupToUpdate.isPresent()
|
|
|
|
? R.string.GroupCreateActivity_updating_group
|
|
|
|
: R.string.GroupCreateActivity_creating_group;
|
|
|
|
activity.creatingText.setText(activity.getString(titleResId, activity.getGroupName()));
|
2014-02-22 01:51:25 +00:00
|
|
|
}
|
2015-11-05 18:41:43 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Optional<GroupActionResult> groupActionResultOptional) {
|
|
|
|
if (activity.isFinishing()) return;
|
|
|
|
activity.findViewById(R.id.group_details_layout).setVisibility(View.VISIBLE);
|
|
|
|
activity.findViewById(R.id.creating_group_layout).setVisibility(View.GONE);
|
|
|
|
activity.findViewById(R.id.menu_create_group).setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static class CreateSignalGroupTask extends SignalGroupTask {
|
|
|
|
public CreateSignalGroupTask(GroupCreateActivity activity, MasterSecret masterSecret, Bitmap avatar, String name, Set<Recipient> members) {
|
|
|
|
super(activity, masterSecret, avatar, name, members);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Optional<GroupActionResult> doInBackground(Void... aVoid) {
|
2014-02-22 01:51:25 +00:00
|
|
|
try {
|
2015-11-05 18:41:43 +00:00
|
|
|
return Optional.of(GroupManager.createGroup(activity, masterSecret, members, avatar, name));
|
2014-02-22 01:51:25 +00:00
|
|
|
} catch (InvalidNumberException e) {
|
2015-11-05 18:41:43 +00:00
|
|
|
return Optional.absent();
|
2014-02-22 01:51:25 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-24 05:18:08 +00:00
|
|
|
|
|
|
|
@Override
|
2015-11-05 18:41:43 +00:00
|
|
|
protected void onPostExecute(Optional<GroupActionResult> result) {
|
|
|
|
if (result.isPresent() && result.get().getThreadId() > -1) {
|
|
|
|
if (!activity.isFinishing()) {
|
|
|
|
activity.handleOpenConversation(result.get().getThreadId(), result.get().getGroupRecipient());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
super.onPostExecute(result);
|
|
|
|
Toast.makeText(activity.getApplicationContext(),
|
|
|
|
R.string.GroupCreateActivity_contacts_invalid_number, Toast.LENGTH_LONG).show();
|
2014-02-24 05:18:08 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-22 01:51:25 +00:00
|
|
|
}
|
|
|
|
|
2015-11-05 18:41:43 +00:00
|
|
|
private static class UpdateSignalGroupTask extends SignalGroupTask {
|
|
|
|
private byte[] groupId;
|
|
|
|
|
|
|
|
public UpdateSignalGroupTask(GroupCreateActivity activity,
|
|
|
|
MasterSecret masterSecret, byte[] groupId, Bitmap avatar, String name,
|
|
|
|
Set<Recipient> members)
|
|
|
|
{
|
|
|
|
super(activity, masterSecret, avatar, name, members);
|
|
|
|
this.groupId = groupId;
|
|
|
|
}
|
2014-02-18 00:36:31 +00:00
|
|
|
|
|
|
|
@Override
|
2015-11-05 18:41:43 +00:00
|
|
|
protected Optional<GroupActionResult> doInBackground(Void... aVoid) {
|
2014-02-18 00:36:31 +00:00
|
|
|
try {
|
2015-11-05 18:41:43 +00:00
|
|
|
return Optional.of(GroupManager.updateGroup(activity, masterSecret, groupId, members, avatar, name));
|
2014-02-18 00:36:31 +00:00
|
|
|
} catch (InvalidNumberException e) {
|
2015-11-05 18:41:43 +00:00
|
|
|
return Optional.absent();
|
2014-02-18 00:36:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-05 18:41:43 +00:00
|
|
|
protected void onPostExecute(Optional<GroupActionResult> result) {
|
|
|
|
if (result.isPresent() && result.get().getThreadId() > -1) {
|
|
|
|
if (!activity.isFinishing()) {
|
|
|
|
Intent intent = activity.getIntent();
|
|
|
|
intent.putExtra(GROUP_THREAD_EXTRA, result.get().getThreadId());
|
|
|
|
intent.putExtra(GROUP_RECIPIENT_EXTRA, result.get().getGroupRecipient().getIds());
|
|
|
|
activity.setResult(RESULT_OK, intent);
|
|
|
|
activity.finish();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
super.onPostExecute(result);
|
|
|
|
Toast.makeText(activity.getApplicationContext(),
|
|
|
|
R.string.GroupCreateActivity_contacts_invalid_number, Toast.LENGTH_LONG).show();
|
2014-02-18 00:36:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-20 23:41:52 +00:00
|
|
|
|
2015-11-12 20:20:14 +00:00
|
|
|
private static class AddMembersTask extends AsyncTask<Recipient,Void,List<AddMembersTask.Result>> {
|
|
|
|
static class Result {
|
|
|
|
Optional<Recipient> recipient;
|
|
|
|
boolean isPush;
|
|
|
|
String reason;
|
|
|
|
|
|
|
|
public Result(@Nullable Recipient recipient, boolean isPush, @Nullable String reason) {
|
|
|
|
this.recipient = Optional.fromNullable(recipient);
|
|
|
|
this.isPush = isPush;
|
|
|
|
this.reason = reason;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private GroupCreateActivity activity;
|
|
|
|
private boolean failIfNotPush;
|
|
|
|
|
|
|
|
public AddMembersTask(@NonNull GroupCreateActivity activity) {
|
|
|
|
this.activity = activity;
|
|
|
|
this.failIfNotPush = activity.groupToUpdate.isPresent();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<Result> doInBackground(Recipient... recipients) {
|
|
|
|
final List<Result> results = new LinkedList<>();
|
|
|
|
|
|
|
|
for (Recipient recipient : recipients) {
|
|
|
|
boolean isPush = isActiveInDirectory(activity, recipient);
|
|
|
|
String recipientE164 = null;
|
|
|
|
try {
|
|
|
|
recipientE164 = Util.canonicalizeNumber(activity, recipient.getNumber());
|
|
|
|
} catch (InvalidNumberException ine) { /* do nothing */ }
|
|
|
|
|
|
|
|
if (failIfNotPush && !isPush) {
|
|
|
|
results.add(new Result(null, false, activity.getString(R.string.GroupCreateActivity_cannot_add_non_push_to_existing_group,
|
|
|
|
recipient.getNumber())));
|
|
|
|
} else if (TextUtils.equals(TextSecurePreferences.getLocalNumber(activity), recipientE164)) {
|
|
|
|
results.add(new Result(null, false, activity.getString(R.string.GroupCreateActivity_youre_already_in_the_group)));
|
|
|
|
} else {
|
|
|
|
results.add(new Result(recipient, isPush, null));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(List<Result> results) {
|
|
|
|
if (activity.isFinishing()) return;
|
|
|
|
|
|
|
|
for (Result result : results) {
|
|
|
|
if (result.recipient.isPresent()) {
|
|
|
|
activity.getAdapter().add(result.recipient.get(), result.isPush);
|
|
|
|
} else {
|
|
|
|
Toast.makeText(activity, result.reason, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
activity.updateViewState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-05 18:41:43 +00:00
|
|
|
private static class FillExistingGroupInfoAsyncTask extends ProgressDialogAsyncTask<byte[],Void,Optional<GroupData>> {
|
|
|
|
private GroupCreateActivity activity;
|
2014-02-20 23:41:52 +00:00
|
|
|
|
2015-11-05 18:41:43 +00:00
|
|
|
public FillExistingGroupInfoAsyncTask(GroupCreateActivity activity) {
|
|
|
|
super(activity,
|
2014-03-15 00:23:39 +00:00
|
|
|
R.string.GroupCreateActivity_loading_group_details,
|
|
|
|
R.string.please_wait);
|
2015-11-05 18:41:43 +00:00
|
|
|
this.activity = activity;
|
2014-02-20 23:41:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-05 18:41:43 +00:00
|
|
|
protected Optional<GroupData> doInBackground(byte[]... groupIds) {
|
|
|
|
final GroupDatabase db = DatabaseFactory.getGroupDatabase(activity);
|
|
|
|
final Recipients recipients = db.getGroupMembers(groupIds[0], false);
|
|
|
|
final GroupRecord group = db.getGroup(groupIds[0]);
|
|
|
|
final Set<Recipient> existingContacts = new HashSet<>(recipients.getRecipientsList().size());
|
|
|
|
existingContacts.addAll(recipients.getRecipientsList());
|
|
|
|
|
2014-02-20 23:41:52 +00:00
|
|
|
if (group != null) {
|
2015-11-05 18:41:43 +00:00
|
|
|
return Optional.of(new GroupData(groupIds[0],
|
|
|
|
existingContacts,
|
|
|
|
BitmapUtil.fromByteArray(group.getAvatar()),
|
|
|
|
group.getTitle()));
|
|
|
|
} else {
|
|
|
|
return Optional.absent();
|
2014-02-20 23:41:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-05 18:41:43 +00:00
|
|
|
protected void onPostExecute(Optional<GroupData> group) {
|
|
|
|
super.onPostExecute(group);
|
|
|
|
|
|
|
|
if (group.isPresent() && !activity.isFinishing()) {
|
|
|
|
activity.groupToUpdate = group;
|
|
|
|
|
|
|
|
activity.groupName.setText(group.get().name);
|
|
|
|
if (group.get().avatar != null) activity.avatar.setImageBitmap(group.get().avatar);
|
|
|
|
SelectedRecipientsAdapter adapter = new SelectedRecipientsAdapter(activity, group.get().recipients);
|
|
|
|
adapter.setOnRecipientDeletedListener(activity);
|
|
|
|
activity.lv.setAdapter(adapter);
|
2015-11-12 20:20:14 +00:00
|
|
|
activity.updateViewState();
|
2015-11-05 18:41:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-20 23:41:52 +00:00
|
|
|
|
2015-11-05 18:41:43 +00:00
|
|
|
private static class GroupData {
|
|
|
|
byte[] id;
|
|
|
|
Set<Recipient> recipients;
|
|
|
|
Bitmap avatar;
|
|
|
|
String name;
|
|
|
|
|
|
|
|
public GroupData(byte[] id, Set<Recipient> recipients, Bitmap avatar, String name) {
|
|
|
|
this.id = id;
|
|
|
|
this.recipients = recipients;
|
|
|
|
this.avatar = avatar;
|
|
|
|
this.name = name;
|
2014-02-20 23:41:52 +00:00
|
|
|
}
|
|
|
|
}
|
2014-01-19 02:17:08 +00:00
|
|
|
}
|