new group from profile (#2100)

* add 'New Group or Subject' to contact profiles and allow group creation from there

* preselect contacts on group-creation from profile

* remove dead code

* also for existing group-creation, do not finish calling activity needlessly (this is pretty unexpected behavior)

* on editing groups, just use isProtected() from the chat to edit
This commit is contained in:
bjoern
2021-10-31 15:24:50 +01:00
committed by GitHub
parent 1e2bc56aec
commit 45187174f2
9 changed files with 40 additions and 22 deletions
+1 -1
View File
@@ -32,7 +32,7 @@
android:lines="1"
android:maxLength="255"
android:inputType="textAutoCorrect"
android:hint="@string/group_name" />
android:hint="@string/name_desktop" />
</LinearLayout>
<TextView
+2
View File
@@ -172,6 +172,8 @@
<string name="menu_new_contact">New Contact</string>
<string name="menu_new_chat">New Chat</string>
<string name="menu_new_group">New Group</string>
<!-- "Subject" here must be the same wording as used in the e-mail context, so. eg. "Betreff" in german (the idea is to help people coming from the e-mail context) -->
<string name="new_group_or_subject">New Group or Subject</string>
<string name="menu_new_verified_group">New Verified Group</string>
<!-- consider keeping the term "broadcast"; check how these lists are called eg. on whatsapp in the destination language -->
<string name="broadcast_list">Broadcast List</string>
@@ -65,6 +65,7 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
public static final String EDIT_GROUP_CHAT_ID = "edit_group_chat_id";
public static final String GROUP_CREATE_VERIFIED_EXTRA = "group_create_verified";
public static final String CREATE_BROADCAST = "group_create_broadcast";
public static final String SUGGESTED_CONTACT_IDS = "suggested_contact_ids";
private final DynamicTheme dynamicTheme = new DynamicTheme();
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
@@ -85,6 +86,7 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
private boolean isEdit;
private boolean avatarChanged;
private boolean imageLoaded;
private boolean hasSuggestedContacts;
private AttachmentManager attachmentManager;
@Override
@@ -112,6 +114,7 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
if(groupChatId !=0) {
isEdit = true;
DcChat dcChat = dcContext.getChat(groupChatId);
verified = dcChat.isProtected();
broadcast = dcChat.isBroadcast();
}
@@ -148,6 +151,8 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
}
else if(broadcast) {
title = getString(R.string.new_broadcast_list);
} else if (hasSuggestedContacts) {
title = getString(R.string.new_group_or_subject);
}
else if(verified) {
title = getString(R.string.menu_new_verified_group);
@@ -205,7 +210,7 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
Recipient recipient = result.recipient.get();
Address address = recipient.getAddress();
if(address.isDcContact()) {
activity.getAdapter().add(recipient, true);
activity.getAdapter().add(recipient);
}
}
activity.updateViewState();
@@ -223,6 +228,13 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
DcContact self = dcContext.getContact(DC_CONTACT_ID_SELF);
initList.add(new Recipient(this, self));
}
ArrayList<Integer> suggestedContactIds = getIntent().getIntegerArrayListExtra(SUGGESTED_CONTACT_IDS);
if (suggestedContactIds != null && !suggestedContactIds.isEmpty()) {
hasSuggestedContacts = true;
for (Integer contactId : suggestedContactIds) {
initList.add(new Recipient(this, dcContext.getContact(contactId)));
}
}
SelectedRecipientsAdapter adapter = new SelectedRecipientsAdapter(this, GlideApp.with(this), initList);
adapter.setOnRecipientDeletedListener(this);
lv.setAdapter(adapter);
@@ -261,9 +261,6 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity
private void editAvatar() {
Intent intent = new Intent(this, GroupCreateActivity.class);
intent.putExtra(GroupCreateActivity.EDIT_GROUP_CHAT_ID, editAvatarChatId);
if (dcContext.getChat(editAvatarChatId).isProtected()) {
intent.putExtra(GroupCreateActivity.GROUP_CREATE_VERIFIED_EXTRA, true);
}
startActivity(intent);
finish(); // avoid the need to update the enlarged-avatar
}
@@ -142,12 +142,10 @@ public class NewConversationActivity extends ContactSelectionActivity {
Intent intent = new Intent(this, GroupCreateActivity.class);
intent.putExtra(GroupCreateActivity.GROUP_CREATE_VERIFIED_EXTRA, specialId == DcContact.DC_CONTACT_ID_NEW_VERIFIED_GROUP);
startActivity(intent);
finish();
} else if(specialId == DcContact.DC_CONTACT_ID_NEW_BROADCAST_LIST) {
Intent intent = new Intent(this, GroupCreateActivity.class);
intent.putExtra(GroupCreateActivity.CREATE_BROADCAST, true);
startActivity(intent);
finish();
}
else {
if(!dcContext.mayBeValidAddr(addr)) {
@@ -496,9 +496,6 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
if (chatIsMailingList || dcChat.canSend()) {
Intent intent = new Intent(this, GroupCreateActivity.class);
intent.putExtra(GroupCreateActivity.EDIT_GROUP_CHAT_ID, chatId);
if (dcChat.isProtected()) {
intent.putExtra(GroupCreateActivity.GROUP_CREATE_VERIFIED_EXTRA, true);
}
startActivity(intent);
}
}
@@ -31,7 +31,8 @@ import java.util.Set;
public class ProfileSettingsAdapter extends RecyclerView.Adapter
implements StickyHeaderAdapter<ProfileSettingsAdapter.HeaderViewHolder>
{
public static final int SETTING_NEW_CHAT = 120;
public static final int SETTING_SEND_MESSAGE = 120;
public static final int SETTING_NEW_GROUP = 130;
private final @NonNull Context context;
private final @NonNull Locale locale;
@@ -310,7 +311,8 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter
itemDataContact = dcContact;
if (!chatIsDeviceTalk) {
itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_NEW_CHAT, context.getString(R.string.send_message)));
itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_SEND_MESSAGE, context.getString(R.string.send_message)));
itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_NEW_GROUP, context.getString(R.string.new_group_or_subject)));
}
itemDataStatusText = dcContact.getStatus();
@@ -143,8 +143,12 @@ public class ProfileSettingsFragment extends Fragment
@Override
public void onSettingsClicked(int settingsId) {
switch(settingsId) {
case ProfileSettingsAdapter.SETTING_NEW_CHAT:
onNewChat();
case ProfileSettingsAdapter.SETTING_SEND_MESSAGE:
onSendMessage();
break;
case ProfileSettingsAdapter.SETTING_NEW_GROUP:
onNewGroupWith();
break;
}
}
@@ -233,7 +237,7 @@ public class ProfileSettingsFragment extends Fragment
getActivity().finish();
}
private void onNewChat() {
private void onSendMessage() {
DcContact dcContact = dcContext.getContact(contactId);
int chatId = dcContext.createChatByContactId(dcContact.getId());
if (chatId != 0) {
@@ -244,6 +248,15 @@ public class ProfileSettingsFragment extends Fragment
}
}
private void onNewGroupWith() {
ArrayList<Integer> preselectedContactIds = new ArrayList<>();
preselectedContactIds.add(contactId);
Intent intent = new Intent(getActivity(), GroupCreateActivity.class);
intent.putExtra(GroupCreateActivity.SUGGESTED_CONTACT_IDS, preselectedContactIds);
getActivity().startActivity(intent);
}
private class ActionModeCallback implements ActionMode.Callback {
private int originalStatusBarColor;
@@ -48,13 +48,13 @@ public class SelectedRecipientsAdapter extends BaseAdapter {
this.recipients = wrapExistingMembers(existingRecipients);
}
public void add(@NonNull Recipient recipient, boolean isPush) {
public void add(@NonNull Recipient recipient) {
if (!find(recipient).isPresent()) {
boolean isModifiable = true;
if (recipient.getAddress().getDcContactId() == DC_CONTACT_ID_SELF) {
isModifiable = false;
}
RecipientWrapper wrapper = new RecipientWrapper(recipient, isModifiable, isPush);
RecipientWrapper wrapper = new RecipientWrapper(recipient, isModifiable);
this.recipients.add(0, wrapper);
notifyDataSetChanged();
}
@@ -146,7 +146,7 @@ public class SelectedRecipientsAdapter extends BaseAdapter {
if (recipient.getAddress().getDcContactId() == DC_CONTACT_ID_SELF) {
isModifiable = false;
}
wrapperList.add(new RecipientWrapper(recipient, isModifiable, true));
wrapperList.add(new RecipientWrapper(recipient, isModifiable));
}
return wrapperList;
}
@@ -162,15 +162,12 @@ public class SelectedRecipientsAdapter extends BaseAdapter {
public static class RecipientWrapper {
private final Recipient recipient;
private final boolean modifiable;
private final boolean push;
public RecipientWrapper(final @NonNull Recipient recipient,
final boolean modifiable,
final boolean push)
final boolean modifiable)
{
this.recipient = recipient;
this.modifiable = modifiable;
this.push = push;
}
public @NonNull Recipient getRecipient() {