diff --git a/res/values/strings.xml b/res/values/strings.xml index f1626a8f9..a06b35c1c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -121,6 +121,9 @@ Group Name New MMS Group You have selected a contact that doesn\'t support TextSecure groups, so this group will be MMS. + An unexpected error happened that has made group creation fail. + You need at least one person in your group! + One of the members of your group has a number that can\'t be read correctly. Please fix or remove that contact and try again. Import System SMS Database? diff --git a/src/org/thoughtcrime/securesms/GroupCreateActivity.java b/src/org/thoughtcrime/securesms/GroupCreateActivity.java index de9a4b767..7a5d086fc 100644 --- a/src/org/thoughtcrime/securesms/GroupCreateActivity.java +++ b/src/org/thoughtcrime/securesms/GroupCreateActivity.java @@ -1,7 +1,9 @@ package org.thoughtcrime.securesms; import android.app.Activity; +import android.app.AlertDialog; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.graphics.Bitmap; import android.os.AsyncTask; @@ -14,6 +16,7 @@ import android.widget.EditText; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; +import android.widget.Toast; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuInflater; @@ -40,7 +43,6 @@ import org.thoughtcrime.securesms.util.Util; import org.whispersystems.textsecure.crypto.MasterSecret; import org.whispersystems.textsecure.directory.Directory; import org.whispersystems.textsecure.directory.NotInDirectoryException; -import org.whispersystems.textsecure.util.Base64; import org.whispersystems.textsecure.util.InvalidNumberException; import java.io.ByteArrayOutputStream; @@ -234,71 +236,99 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv finish(); return true; case R.id.menu_create_group: - if (whisperGroupUiEnabled()) { - 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); - ((TextView)findViewById(R.id.creating_group_text)).setText("Creating " + groupName.getText().toString() + "..."); - new AsyncTask() { - - @Override - protected Void doInBackground(Void... voids) { - byte[] byteArray = null; - if (avatarBmp != null) { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - avatarBmp.compress(Bitmap.CompressFormat.PNG, 100, stream); - byteArray = stream.toByteArray(); - } - try { - handleCreatePushGroup(groupName.getText().toString(), byteArray, selectedContacts); - } catch (InvalidNumberException e) { - // TODO jake's gonna fill this in. - Log.w("GroupCreateActivity", e); - } catch (MmsException e) { - // TODO jake's gonna fill this in. - Log.w("GroupCreateActivity", e); - } - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - finish(); - } - - @Override - protected void onProgressUpdate(Void... values) { - super.onProgressUpdate(values); - } - }.execute(); - } else { - new AsyncTask() { - - @Override - protected Void doInBackground(Void... voids) { - handleCreateMmsGroup(selectedContacts); - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - finish(); - } - - @Override - protected void onProgressUpdate(Void... values) { - super.onProgressUpdate(values); - } - }.execute(); - } + handleGroupCreate(); return true; } return false; } + private void handleGroupCreate() { + if (selectedContacts.size() < 1) { + Toast.makeText(getApplicationContext(), R.string.GroupCreateActivity_contacts_no_members, Toast.LENGTH_SHORT); + return; + } + if (whisperGroupUiEnabled()) { + 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); + ((TextView)findViewById(R.id.creating_group_text)).setText("Creating " + groupName.getText().toString() + "..."); + new AsyncTask() { + private long RES_BAD_NUMBER = -2; + private long RES_MMS_EXCEPTION = -3; + + @Override + protected Long doInBackground(Void... voids) { + byte[] byteArray = null; + if (avatarBmp != null) { + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + avatarBmp.compress(Bitmap.CompressFormat.PNG, 100, stream); + byteArray = stream.toByteArray(); + } + try { + return Long.valueOf(handleCreatePushGroup(groupName.getText().toString(), byteArray, selectedContacts)); + } catch (MmsException e) { + Log.w("GroupCreateActivity", e); + return Long.valueOf(RES_MMS_EXCEPTION); + } catch (InvalidNumberException e) { + Log.w("GroupCreateActivity", e); + return Long.valueOf(RES_BAD_NUMBER); + } + } + + @Override + protected void onPostExecute(Long resultThread) { + super.onPostExecute(resultThread); + if (resultThread > -1) { + Intent intent = new Intent(GroupCreateActivity.this, ConversationActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + intent.putExtra(ConversationActivity.MASTER_SECRET_EXTRA, masterSecret); + intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, resultThread.longValue()); + intent.putExtra(ConversationActivity.DISTRIBUTION_TYPE_EXTRA, ThreadDatabase.DistributionTypes.DEFAULT); + + ArrayList selectedContactsList = new ArrayList(selectedContacts.size()); + for (Recipient recipient : selectedContacts) { + selectedContactsList.add(recipient); + } + intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, new Recipients(selectedContactsList)); + startActivity(intent); + GroupCreateActivity.this.finish(); + } else if (resultThread == RES_BAD_NUMBER) { + Toast.makeText(getApplicationContext(), R.string.GroupCreateActivity_contacts_invalid_number, Toast.LENGTH_LONG).show(); + } else if (resultThread == RES_MMS_EXCEPTION) { + Toast.makeText(getApplicationContext(), R.string.GroupCreateActivity_contacts_mms_exception, Toast.LENGTH_LONG).show(); + finish(); + } + } + + @Override + protected void onProgressUpdate(Void... values) { + super.onProgressUpdate(values); + } + }.execute(); + } else { + new AsyncTask() { + + @Override + protected Void doInBackground(Void... voids) { + handleCreateMmsGroup(selectedContacts); + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + super.onPostExecute(aVoid); + finish(); + } + + @Override + protected void onProgressUpdate(Void... values) { + super.onProgressUpdate(values); + } + }.execute(); + } + } + private void syncAdapterWithSelectedContacts() { SelectedRecipientsAdapter adapter = (SelectedRecipientsAdapter)lv.getAdapter(); adapter.clear();