Skip to content

Commit

Permalink
avatar selection on gb fixed, disable push groups if not push registered
Browse files Browse the repository at this point in the history
  • Loading branch information
mcginty committed Feb 18, 2014
1 parent 948f888 commit 93329df
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
2 changes: 1 addition & 1 deletion res/layout/group_create_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
51 changes: 43 additions & 8 deletions src/org/thoughtcrime/securesms/GroupCreateActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
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;
Expand Down Expand Up @@ -43,6 +47,8 @@
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;
Expand All @@ -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;

Expand Down Expand Up @@ -96,15 +104,20 @@ public void onCreate(Bundle state) {
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);
Expand Down Expand Up @@ -136,7 +149,7 @@ private static boolean isActiveInDirectory(Context context, Recipient recipient)

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) {
Expand All @@ -146,7 +159,6 @@ private void addAllSelectedContacts(Collection<Recipient> contacts) {
}

private void removeSelectedContact(Recipient contact) {
Log.i(TAG, "remoevSelectedContact: " + contact.getName() + "/" + contact.getNumber());
selectedContacts.remove(contact);
if (!isActiveInDirectory(this, contact)) {
for (Recipient recipient : selectedContacts) {
Expand Down Expand Up @@ -208,12 +220,33 @@ public void onClick(View view) {
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();
Expand Down Expand Up @@ -304,10 +337,12 @@ public void onActivityResult(int reqCode, int resultCode, Intent data) {
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;
}
}
Expand Down

0 comments on commit 93329df

Please sign in to comment.