basic messaging when non-push users are added

This commit is contained in:
Jake McGinty 2014-02-12 17:17:33 -08:00
parent b4a4e629f1
commit 01a438de09
5 changed files with 142 additions and 40 deletions

View file

@ -3,30 +3,61 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
android:layout_height="match_parent">
<LinearLayout
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_marginBottom="20dp" >
android:layout_marginBottom="20dp">
<ImageView
android:id="@+id/avatar"
android:layout_width="70dp"
android:layout_height="70dp"
android:src="@drawable/icon"/>
<EditText
android:id="@+id/group_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:hint="Group name"
android:layout_gravity="center_vertical" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="106dp"
android:orientation="horizontal"
android:gravity="center_vertical"
android:paddingLeft="18dp"
android:paddingRight="18dp"
android:paddingTop="18dp">
<ImageView
android:id="@+id/avatar"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="10dp"
android:src="@drawable/icon"/>
<EditText
android:id="@+id/group_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:hint="Group name"
android:layout_gravity="center_vertical" />
</LinearLayout>
<RelativeLayout
android:id="@+id/push_disabled"
android:layout_width="fill_parent"
android:layout_height="106dp"
android:background="#dd555555"
android:gravity="center_vertical|center_horizontal"
android:padding="15dp"
android:visibility="gone">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#ff444444"
android:textColor="#ffeeeeee"
android:fontFamily="sans-serif-light"
android:padding="8dp"
android:textSize="16dp"
android:text="You have selected a contact that doesn't support TextSecure groups, so this group will be MMS." />
</RelativeLayout>
</RelativeLayout>
<org.thoughtcrime.securesms.components.PushRecipientsPanel
android:id="@+id/recipients"

View file

@ -118,6 +118,7 @@
<!-- GroupCreateActivity -->
<string name="GroupCreateActivity_actionbar_title">New Group</string>
<string name="GroupCreateActivity_actionbar_mms_title">New MMS Group</string>
<!-- ImportFragment -->
<string name="ImportFragment_import_system_sms_database">Import System SMS Database?</string>

View file

@ -1,6 +1,7 @@
package org.thoughtcrime.securesms;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
@ -26,8 +27,13 @@ import org.thoughtcrime.securesms.util.ActionBarUtil;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.SelectedRecipientsAdapter;
import org.thoughtcrime.securesms.util.Util;
import org.whispersystems.textsecure.directory.Directory;
import org.whispersystems.textsecure.directory.NotInDirectoryException;
import org.whispersystems.textsecure.util.InvalidNumberException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -42,8 +48,6 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
private final DynamicTheme dynamicTheme = new DynamicTheme();
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
private String defaultTitle;
private static final int PICK_CONTACT = 1;
private static final int PICK_AVATAR = 2;
@ -58,12 +62,11 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
public void onCreate(Bundle state) {
dynamicTheme.onCreate(this);
dynamicLanguage.onCreate(this);
defaultTitle = getString(R.string.GroupCreateActivity_actionbar_title);
super.onCreate(state);
setContentView(R.layout.group_create_activity);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBarUtil.initializeDefaultActionBar(this, getSupportActionBar(), defaultTitle);
ActionBarUtil.initializeDefaultActionBar(this, getSupportActionBar(), R.string.GroupCreateActivity_actionbar_title);
selectedContacts = new HashSet<Recipient>();
initializeResources();
@ -75,6 +78,61 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
dynamicTheme.onResume(this);
}
private void disableWhisperGroupUI() {
View pushDisabled = findViewById(R.id.push_disabled);
pushDisabled.setVisibility(View.VISIBLE);
avatar.setEnabled(false);
groupName.setEnabled(false);
getSupportActionBar().setTitle(R.string.GroupCreateActivity_actionbar_mms_title);
}
private void enableWhisperGroupUI() {
findViewById(R.id.push_disabled).setVisibility(View.GONE);
avatar.setEnabled(true);
groupName.setEnabled(true);
final CharSequence groupNameText = groupName.getText();
if (groupNameText.length() > 0)
getSupportActionBar().setTitle(groupNameText);
else
getSupportActionBar().setTitle(R.string.GroupCreateActivity_actionbar_title);
}
private static boolean isActiveInDirectory(Context context, Recipient recipient) {
try {
if (!Directory.getInstance(context).isActiveNumber(Util.canonicalizeNumber(context, recipient.getNumber()))) {
return false;
}
} catch (NotInDirectoryException e) {
return false;
} catch (InvalidNumberException e ) {
return false;
}
return true;
}
private void addSelectedContact(Recipient contact) {
selectedContacts.add(contact);
if (!isActiveInDirectory(this, contact)) disableWhisperGroupUI();
}
private void addAllSelectedContacts(Collection<Recipient> contacts) {
for (Recipient contact : contacts) {
addSelectedContact(contact);
}
}
private void removeSelectedContact(Recipient contact) {
Log.i(TAG, "remoevSelectedContact: " + contact.getName() + "/" + contact.getNumber());
selectedContacts.remove(contact);
if (!isActiveInDirectory(this, contact)) {
for (Recipient recipient : selectedContacts) {
if (!isActiveInDirectory(this, recipient))
return;
}
enableWhisperGroupUI();
}
}
private void initializeResources() {
groupName = (EditText) findViewById(R.id.group_name);
groupName.addTextChangedListener(new TextWatcher() {
@ -87,12 +145,19 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
if (editable.length() > 0)
getSupportActionBar().setTitle(editable);
else
getSupportActionBar().setTitle(defaultTitle);
getSupportActionBar().setTitle(R.string.GroupCreateActivity_actionbar_title);
}
});
lv = (ListView) findViewById(R.id.selected_contacts_list);
lv.setAdapter(new SelectedRecipientsAdapter(this, android.R.id.text1, new ArrayList<Recipient>()));
SelectedRecipientsAdapter adapter = new SelectedRecipientsAdapter(this, android.R.id.text1, new ArrayList<Recipient>());
adapter.setOnRecipientDeletedListener(new SelectedRecipientsAdapter.OnRecipientDeletedListener() {
@Override
public void onRecipientDeleted(Recipient recipient) {
removeSelectedContact(recipient);
}
});
lv.setAdapter(adapter);
recipientsPanel = (PushRecipientsPanel) findViewById(R.id.recipients);
recipientsPanel.setPanelChangeListener(new PushRecipientsPanel.RecipientsPanelChangedListener() {
@ -100,7 +165,7 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
public void onRecipientsPanelUpdate(Recipients recipients) {
Log.i(TAG, "onRecipientsPanelUpdate received.");
if (recipients != null) {
selectedContacts.addAll(recipients.getRecipientsList());
addAllSelectedContacts(recipients.getRecipientsList());
syncAdapterWithSelectedContacts();
}
}
@ -116,8 +181,8 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
photoPickerIntent.putExtra("crop", "true");
photoPickerIntent.putExtra("aspectX", 1);
photoPickerIntent.putExtra("aspectY", 1);
photoPickerIntent.putExtra("outputX", 256);
photoPickerIntent.putExtra("outputY", 256);
photoPickerIntent.putExtra("outputX", 210);
photoPickerIntent.putExtra("outputY", 210);
photoPickerIntent.putExtra("return-data", "true");
startActivityForResult(photoPickerIntent, PICK_AVATAR);
}
@ -134,14 +199,6 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
return true;
}
private List<String> selectedContactsAsIdArray() {
final List<String> ids = new ArrayList<String>();
for (Recipient recipient : selectedContacts) {
ids.add(String.valueOf(recipient.getRecipientId()));
}
return ids;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
@ -160,7 +217,6 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
adapter.clear();
for (Recipient contact : selectedContacts) {
adapter.add(contact);
Log.i("GroupCreateActivity", "Adding " + contact.getName() + "/" + contact.getNumber());
}
adapter.notifyDataSetChanged();
}
@ -176,9 +232,6 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
switch (reqCode) {
case PICK_CONTACT:
List<ContactData> selected = data.getParcelableArrayListExtra("contacts");
for (ContactData cdata : selected) {
Log.i("PushContactSelect", "selected report: " + cdata.name);
}
for (ContactData contact : selected) {
for (ContactAccessor.NumberData numberData : contact.numbers) {
try {
@ -186,7 +239,7 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
.getPrimaryRecipient();
if (!selectedContacts.contains(recipient)) {
selectedContacts.add(recipient);
addSelectedContact(recipient);
}
} catch (RecipientFormattingException e) {
Log.w("GroupCreateActivity", e);

View file

@ -9,6 +9,12 @@ import com.actionbarsherlock.app.ActionBar;
import org.thoughtcrime.securesms.R;
public class ActionBarUtil {
public static void initializeDefaultActionBar(final Context c, final ActionBar actionBar, final int title_resid) {
actionBar.setTitle(title_resid);
initializeDefaultActionBar(c, actionBar);
}
public static void initializeDefaultActionBar(final Context c, final ActionBar actionBar, final String title) {
actionBar.setTitle(title);
initializeDefaultActionBar(c, actionBar);

View file

@ -17,6 +17,7 @@ import java.util.List;
public class SelectedRecipientsAdapter extends ArrayAdapter<Recipient> {
private ArrayList<Recipient> recipients;
private OnRecipientDeletedListener onRecipientDeletedListener;
public SelectedRecipientsAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
@ -59,6 +60,9 @@ public class SelectedRecipientsAdapter extends ArrayAdapter<Recipient> {
delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (onRecipientDeletedListener != null) {
onRecipientDeletedListener.onRecipientDeleted(recipients.get(position));
}
recipients.remove(position);
SelectedRecipientsAdapter.this.notifyDataSetChanged();
}
@ -67,6 +71,13 @@ public class SelectedRecipientsAdapter extends ArrayAdapter<Recipient> {
}
return v;
}
public void setOnRecipientDeletedListener(OnRecipientDeletedListener listener) {
onRecipientDeletedListener = listener;
}
public interface OnRecipientDeletedListener {
public void onRecipientDeleted(Recipient recipient);
}
}