From 9d7dedeb8f9e205ea3fd7fa565b44a182af36fec Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Tue, 18 Sep 2018 15:08:55 +0200 Subject: [PATCH] add a simple button to add members to group; this can be easily enhanced by a 'show qr invite' code button --- res/layout/group_create_activity.xml | 24 ++- res/layout/push_recipients_panel.xml | 30 ---- .../securesms/GroupCreateActivity.java | 17 +- .../components/PushRecipientsPanel.java | 170 ------------------ 4 files changed, 22 insertions(+), 219 deletions(-) delete mode 100644 res/layout/push_recipients_panel.xml delete mode 100644 src/org/thoughtcrime/securesms/components/PushRecipientsPanel.java diff --git a/res/layout/group_create_activity.xml b/res/layout/group_create_activity.xml index f58dc92e4..1f5bd3c01 100644 --- a/res/layout/group_create_activity.xml +++ b/res/layout/group_create_activity.xml @@ -68,11 +68,25 @@ - + - - - - - - - - \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/GroupCreateActivity.java b/src/org/thoughtcrime/securesms/GroupCreateActivity.java index 685256807..04b3e3bbe 100644 --- a/src/org/thoughtcrime/securesms/GroupCreateActivity.java +++ b/src/org/thoughtcrime/securesms/GroupCreateActivity.java @@ -40,8 +40,6 @@ import com.bumptech.glide.request.target.SimpleTarget; import com.bumptech.glide.request.transition.Transition; import com.soundcloud.android.crop.Crop; -import org.thoughtcrime.securesms.components.PushRecipientsPanel; -import org.thoughtcrime.securesms.components.PushRecipientsPanel.RecipientsPanelChangedListener; import org.thoughtcrime.securesms.connect.ApplicationDcContext; import org.thoughtcrime.securesms.connect.DcHelper; import org.thoughtcrime.securesms.contacts.ContactsCursorLoader.DisplayMode; @@ -77,8 +75,7 @@ import java.util.Set; * @author Jake McGinty */ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity - implements OnRecipientDeletedListener, - RecipientsPanelChangedListener + implements OnRecipientDeletedListener { private final static String TAG = GroupCreateActivity.class.getSimpleName(); @@ -156,8 +153,6 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity } private void initializeResources() { - RecipientsEditor recipientsEditor = ViewUtil.findById(this, R.id.recipients_text); - PushRecipientsPanel recipientsPanel = ViewUtil.findById(this, R.id.recipients); lv = ViewUtil.findById(this, R.id.selected_contacts_list); avatar = ViewUtil.findById(this, R.id.avatar); groupName = ViewUtil.findById(this, R.id.group_name); @@ -165,9 +160,8 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity SelectedRecipientsAdapter adapter = new SelectedRecipientsAdapter(this); adapter.setOnRecipientDeletedListener(this); lv.setAdapter(adapter); - recipientsEditor.setHint(R.string.recipients_panel__add_members); - recipientsPanel.setPanelChangeListener(this); - findViewById(R.id.contacts_button).setOnClickListener(new AddRecipientButtonListener()); + + findViewById(R.id.add_member_button).setOnClickListener(new AddRecipientButtonListener()); avatar.setImageDrawable(new ResourceContactPhoto(R.drawable.ic_group_white_24dp).asDrawable(this, ContactColors.UNKNOWN_COLOR.toConversationColor(this))); avatar.setOnClickListener(view -> Crop.pickImage(GroupCreateActivity.this)); } @@ -212,11 +206,6 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity updateViewState(); } - @Override - public void onRecipientsPanelUpdate(List recipients) { - if (recipients != null && !recipients.isEmpty()) addSelectedContacts(recipients); - } - private void handleGroupCreate() { String groupName = getGroupName(); if(groupName==null) { diff --git a/src/org/thoughtcrime/securesms/components/PushRecipientsPanel.java b/src/org/thoughtcrime/securesms/components/PushRecipientsPanel.java deleted file mode 100644 index 062a7bed7..000000000 --- a/src/org/thoughtcrime/securesms/components/PushRecipientsPanel.java +++ /dev/null @@ -1,170 +0,0 @@ -/** - * Copyright (C) 2011 Whisper Systems - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.thoughtcrime.securesms.components; - -import android.content.Context; -import android.os.Build; -import android.support.annotation.NonNull; -import android.text.TextUtils; -import android.util.AttributeSet; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.AdapterView; -import android.widget.RelativeLayout; - -import org.thoughtcrime.securesms.R; -import org.thoughtcrime.securesms.contacts.RecipientsAdapter; -import org.thoughtcrime.securesms.contacts.RecipientsEditor; -import org.thoughtcrime.securesms.database.Address; -import org.thoughtcrime.securesms.recipients.Recipient; -import org.thoughtcrime.securesms.recipients.RecipientModifiedListener; - -import java.util.LinkedList; -import java.util.List; -import java.util.StringTokenizer; - -/** - * Panel component combining both an editable field with a button for - * a list-based contact selector. - * - * @author Moxie Marlinspike - */ -public class PushRecipientsPanel extends RelativeLayout implements RecipientModifiedListener { - private final String TAG = PushRecipientsPanel.class.getSimpleName(); - private RecipientsPanelChangedListener panelChangeListener; - - private RecipientsEditor recipientsText; - private View panel; - - private static final int RECIPIENTS_MAX_LENGTH = 312; - - public PushRecipientsPanel(Context context) { - super(context); - initialize(); - } - - public PushRecipientsPanel(Context context, AttributeSet attrs) { - super(context, attrs); - initialize(); - } - - public PushRecipientsPanel(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - initialize(); - } - - public List getRecipients() { - String rawText = recipientsText.getText().toString(); - return getRecipientsFromString(getContext(), rawText, true); - } - - public void disable() { - recipientsText.setText(""); - panel.setVisibility(View.GONE); - } - - public void setPanelChangeListener(RecipientsPanelChangedListener panelChangeListener) { - this.panelChangeListener = panelChangeListener; - } - - private void initialize() { - LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); - inflater.inflate(R.layout.push_recipients_panel, this, true); - - View imageButton = findViewById(R.id.contacts_button); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) - ((MarginLayoutParams) imageButton.getLayoutParams()).topMargin = 0; - - panel = findViewById(R.id.recipients_panel); - initRecipientsEditor(); - } - - private void initRecipientsEditor() { - - this.recipientsText = (RecipientsEditor)findViewById(R.id.recipients_text); - - List recipients = getRecipients(); - - for (Recipient recipient : recipients) { - recipient.addListener(this); - } - - recipientsText.setAdapter(new RecipientsAdapter(this.getContext())); - recipientsText.populate(recipients); - - recipientsText.setOnFocusChangeListener(new FocusChangedListener()); - recipientsText.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView adapterView, View view, int i, long l) { - if (panelChangeListener != null) { - panelChangeListener.onRecipientsPanelUpdate(getRecipients()); - } - recipientsText.setText(""); - } - }); - } - - private @NonNull List getRecipientsFromString(Context context, @NonNull String rawText, boolean asynchronous) { - StringTokenizer tokenizer = new StringTokenizer(rawText, ","); - List recipients = new LinkedList<>(); - - while (tokenizer.hasMoreTokens()) { - String token = tokenizer.nextToken().trim(); - - if (!TextUtils.isEmpty(token)) { - if (hasBracketedNumber(token)) recipients.add(Recipient.from(context, Address.fromExternal(context, parseBracketedNumber(token)), asynchronous)); - else recipients.add(Recipient.from(context, Address.fromExternal(context, token), asynchronous)); - } - } - - return recipients; - } - - private boolean hasBracketedNumber(String recipient) { - int openBracketIndex = recipient.indexOf('<'); - - return (openBracketIndex != -1) && - (recipient.indexOf('>', openBracketIndex) != -1); - } - - private String parseBracketedNumber(String recipient) { - int begin = recipient.indexOf('<'); - int end = recipient.indexOf('>', begin); - String value = recipient.substring(begin + 1, end); - - return value; - } - - @Override - public void onModified(Recipient recipient) { - recipientsText.populate(getRecipients()); - } - - private class FocusChangedListener implements View.OnFocusChangeListener { - public void onFocusChange(View v, boolean hasFocus) { - if (!hasFocus && (panelChangeListener != null)) { - panelChangeListener.onRecipientsPanelUpdate(getRecipients()); - } - } - } - - public interface RecipientsPanelChangedListener { - public void onRecipientsPanelUpdate(List recipients); - } - -} \ No newline at end of file