avatar selection on gb fixed, disable push groups if not push registered

This commit is contained in:
Jake McGinty 2014-02-17 17:31:48 -08:00
parent 948f888670
commit 93329df530
3 changed files with 46 additions and 9 deletions

View File

@ -71,7 +71,7 @@
android:background="#aa000000"
android:visibility="gone">
<TextView
<TextView android:id="@+id/push_disabled_reason"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"

View File

@ -121,9 +121,11 @@
<string name="GroupCreateActivity_group_name_hint">Group Name</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_you_dont_support_push">You\'re not registered for using the data channel, so TextSecure groups are disabled.</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>
<string name="GroupCreateActivity_file_io_exception">File I/O error, couldn\'t create temporary image file</string>
<!-- ImportFragment -->
<string name="ImportFragment_import_system_sms_database">Import System SMS Database?</string>

View File

@ -4,8 +4,12 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
@ -43,6 +47,8 @@ import org.whispersystems.textsecure.directory.NotInDirectoryException;
import org.whispersystems.textsecure.util.InvalidNumberException;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@ -65,6 +71,8 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
private final DynamicTheme dynamicTheme = new DynamicTheme();
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
private static final String TEMP_PHOTO_FILE = "__tmp_group_create_avatar_photo.png";
private static final int PICK_CONTACT = 1;
private static final int PICK_AVATAR = 2;
@ -96,15 +104,20 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
public void onResume() {
super.onResume();
dynamicTheme.onResume(this);
dynamicLanguage.onResume(this);
if (!TextSecurePreferences.isPushRegistered(this)) {
disableWhisperGroupUi(R.string.GroupCreateActivity_you_dont_support_push);
}
}
private boolean whisperGroupUiEnabled() {
return groupName.isEnabled() && avatar.isEnabled();
}
private void disableWhisperGroupUi() {
private void disableWhisperGroupUi(int reasonResId) {
View pushDisabled = findViewById(R.id.push_disabled);
pushDisabled.setVisibility(View.VISIBLE);
((TextView)findViewById(R.id.push_disabled_reason)).setText(reasonResId);
avatar.setEnabled(false);
groupName.setEnabled(false);
getSupportActionBar().setTitle(R.string.GroupCreateActivity_actionbar_mms_title);
@ -136,7 +149,7 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
private void addSelectedContact(Recipient contact) {
selectedContacts.add(contact);
if (!isActiveInDirectory(this, contact)) disableWhisperGroupUi();
if (!isActiveInDirectory(this, contact)) disableWhisperGroupUi(R.string.GroupCreateActivity_contacts_dont_support_push);
}
private void addAllSelectedContacts(Collection<Recipient> contacts) {
@ -146,7 +159,6 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
}
private void removeSelectedContact(Recipient contact) {
Log.i(TAG, "remoevSelectedContact: " + contact.getName() + "/" + contact.getNumber());
selectedContacts.remove(contact);
if (!isActiveInDirectory(this, contact)) {
for (Recipient recipient : selectedContacts) {
@ -208,12 +220,33 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
photoPickerIntent.putExtra("aspectY", 1);
photoPickerIntent.putExtra("outputX", 210);
photoPickerIntent.putExtra("outputY", 210);
photoPickerIntent.putExtra("return-data", "true");
photoPickerIntent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri());
photoPickerIntent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.toString());
startActivityForResult(photoPickerIntent, PICK_AVATAR);
}
});
}
private Uri getTempUri() {
return Uri.fromFile(getTempFile());
}
private File getTempFile() {
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
File f = new File(Environment.getExternalStorageDirectory(), TEMP_PHOTO_FILE);
try {
f.createNewFile();
} catch (IOException e) {
Log.e(TAG, "Error creating new temp file.", e);
Toast.makeText(getApplicationContext(), R.string.GroupCreateActivity_file_io_exception, Toast.LENGTH_SHORT).show();
}
return f;
} else {
return null;
}
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuInflater inflater = this.getSupportMenuInflater();
@ -304,10 +337,12 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
break;
case PICK_AVATAR:
if(resultCode == RESULT_OK) {
avatarBmp = data.getParcelableExtra("data");
avatar.setImageBitmap(avatarBmp);
//Uri selectedImage = data.getData();
//avatar.setImageURI(selectedImage);
Bundle extras = data.getExtras();
if (extras != null) {
File tempFile = getTempFile();
avatarBmp = BitmapFactory.decodeFile(tempFile.getAbsolutePath());
avatar.setImageBitmap(avatarBmp);
}
break;
}
}