error messaging for group creation issues

This commit is contained in:
Jake McGinty 2014-02-17 15:23:47 -08:00
parent 4f87c1e52e
commit e81526e581
2 changed files with 93 additions and 60 deletions

View File

@ -121,6 +121,9 @@
<string name="GroupCreateActivity_group_name_hint">Group Name</string> <string name="GroupCreateActivity_group_name_hint">Group Name</string>
<string name="GroupCreateActivity_actionbar_mms_title">New MMS Group</string> <string name="GroupCreateActivity_actionbar_mms_title">New MMS Group</string>
<string name="GroupCreateActivity_contacts_dont_support_push">You have selected a contact that doesn\'t support TextSecure groups, so this group will be MMS.</string> <string name="GroupCreateActivity_contacts_dont_support_push">You have selected a contact that doesn\'t support TextSecure groups, so this group will be MMS.</string>
<string name="GroupCreateActivity_contacts_mms_exception">An unexpected error happened that has made group creation fail.</string>
<string name="GroupCreateActivity_contacts_no_members">You need at least one person in your group!</string>
<string name="GroupCreateActivity_contacts_invalid_number">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.</string>
<!-- ImportFragment --> <!-- ImportFragment -->
<string name="ImportFragment_import_system_sms_database">Import System SMS Database?</string> <string name="ImportFragment_import_system_sms_database">Import System SMS Database?</string>

View File

@ -1,7 +1,9 @@
package org.thoughtcrime.securesms; package org.thoughtcrime.securesms;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.AsyncTask; import android.os.AsyncTask;
@ -14,6 +16,7 @@ import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater; 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.crypto.MasterSecret;
import org.whispersystems.textsecure.directory.Directory; import org.whispersystems.textsecure.directory.Directory;
import org.whispersystems.textsecure.directory.NotInDirectoryException; import org.whispersystems.textsecure.directory.NotInDirectoryException;
import org.whispersystems.textsecure.util.Base64;
import org.whispersystems.textsecure.util.InvalidNumberException; import org.whispersystems.textsecure.util.InvalidNumberException;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -234,15 +236,29 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
finish(); finish();
return true; return true;
case R.id.menu_create_group: case R.id.menu_create_group:
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()) { if (whisperGroupUiEnabled()) {
findViewById(R.id.group_details_layout).setVisibility(View.GONE); findViewById(R.id.group_details_layout).setVisibility(View.GONE);
findViewById(R.id.creating_group_layout).setVisibility(View.VISIBLE); findViewById(R.id.creating_group_layout).setVisibility(View.VISIBLE);
findViewById(R.id.menu_create_group).setVisibility(View.GONE); findViewById(R.id.menu_create_group).setVisibility(View.GONE);
((TextView)findViewById(R.id.creating_group_text)).setText("Creating " + groupName.getText().toString() + "..."); ((TextView)findViewById(R.id.creating_group_text)).setText("Creating " + groupName.getText().toString() + "...");
new AsyncTask<Void,Void,Void>() { new AsyncTask<Void,Void,Long>() {
private long RES_BAD_NUMBER = -2;
private long RES_MMS_EXCEPTION = -3;
@Override @Override
protected Void doInBackground(Void... voids) { protected Long doInBackground(Void... voids) {
byte[] byteArray = null; byte[] byteArray = null;
if (avatarBmp != null) { if (avatarBmp != null) {
ByteArrayOutputStream stream = new ByteArrayOutputStream(); ByteArrayOutputStream stream = new ByteArrayOutputStream();
@ -250,22 +266,40 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
byteArray = stream.toByteArray(); byteArray = stream.toByteArray();
} }
try { try {
handleCreatePushGroup(groupName.getText().toString(), byteArray, selectedContacts); return Long.valueOf(handleCreatePushGroup(groupName.getText().toString(), byteArray, selectedContacts));
} catch (InvalidNumberException e) {
// TODO jake's gonna fill this in.
Log.w("GroupCreateActivity", e);
} catch (MmsException e) { } catch (MmsException e) {
// TODO jake's gonna fill this in.
Log.w("GroupCreateActivity", e); Log.w("GroupCreateActivity", e);
return Long.valueOf(RES_MMS_EXCEPTION);
} catch (InvalidNumberException e) {
Log.w("GroupCreateActivity", e);
return Long.valueOf(RES_BAD_NUMBER);
} }
return null;
} }
@Override @Override
protected void onPostExecute(Void aVoid) { protected void onPostExecute(Long resultThread) {
super.onPostExecute(aVoid); 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<Recipient> selectedContactsList = new ArrayList<Recipient>(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(); finish();
} }
}
@Override @Override
protected void onProgressUpdate(Void... values) { protected void onProgressUpdate(Void... values) {
@ -293,10 +327,6 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
} }
}.execute(); }.execute();
} }
return true;
}
return false;
} }
private void syncAdapterWithSelectedContacts() { private void syncAdapterWithSelectedContacts() {