From f110d595d2031524e1f4f50d4c57d1977da3fc88 Mon Sep 17 00:00:00 2001 From: Alan Evans Date: Thu, 10 Sep 2020 09:59:57 -0300 Subject: [PATCH] Fix selection limit for add members GV1. Fixes #10005 --- .../securesms/ContactSelectionListFragment.java | 4 ++-- .../groups/ui/addtogroup/AddToGroupsActivity.java | 2 +- .../groups/ui/creategroup/CreateGroupActivity.java | 5 ++--- .../groups/ui/managegroup/ManageGroupRepository.java | 10 ++++++++++ .../groups/ui/managegroup/ManageGroupViewModel.java | 3 +-- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/ContactSelectionListFragment.java b/app/src/main/java/org/thoughtcrime/securesms/ContactSelectionListFragment.java index e6641d7ba7..2d2ec85990 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ContactSelectionListFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/ContactSelectionListFragment.java @@ -106,7 +106,7 @@ public final class ContactSelectionListFragment extends LoggingFragment public static final String MULTI_SELECT = "multi_select"; public static final String REFRESHABLE = "refreshable"; public static final String RECENTS = "recents"; - public static final String TOTAL_CAPACITY = "total_capacity"; + public static final String SELECTION_LIMIT = "selection_limit"; public static final String CURRENT_SELECTION = "current_selection"; private ConstraintLayout constraintLayout; @@ -208,7 +208,7 @@ public final class ContactSelectionListFragment extends LoggingFragment swipeRefresh.setEnabled(requireActivity().getIntent().getBooleanExtra(REFRESHABLE, true)); - selectionLimit = requireActivity().getIntent().getIntExtra(TOTAL_CAPACITY, NO_LIMIT); + selectionLimit = requireActivity().getIntent().getIntExtra(SELECTION_LIMIT, NO_LIMIT); currentSelection = getCurrentSelection(); updateGroupLimit(getChipCount()); diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/ui/addtogroup/AddToGroupsActivity.java b/app/src/main/java/org/thoughtcrime/securesms/groups/ui/addtogroup/AddToGroupsActivity.java index b616c47454..6cd16ea6c1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/ui/addtogroup/AddToGroupsActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/ui/addtogroup/AddToGroupsActivity.java @@ -51,7 +51,7 @@ public final class AddToGroupsActivity extends ContactSelectionActivity { intent.putExtra(EXTRA_RECIPIENT_ID, recipientId); intent.putExtra(ContactSelectionListFragment.DISPLAY_MODE, ContactsCursorLoader.DisplayMode.FLAG_ACTIVE_GROUPS); - intent.putExtra(ContactSelectionListFragment.TOTAL_CAPACITY, ContactSelectionListFragment.NO_LIMIT); + intent.putExtra(ContactSelectionListFragment.SELECTION_LIMIT, ContactSelectionListFragment.NO_LIMIT); intent.putParcelableArrayListExtra(ContactSelectionListFragment.CURRENT_SELECTION, new ArrayList<>(currentGroupsMemberOf)); diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/ui/creategroup/CreateGroupActivity.java b/app/src/main/java/org/thoughtcrime/securesms/groups/ui/creategroup/CreateGroupActivity.java index 5d532788f2..f790c776bb 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/ui/creategroup/CreateGroupActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/ui/creategroup/CreateGroupActivity.java @@ -31,7 +31,6 @@ import org.thoughtcrime.securesms.util.views.SimpleProgressDialog; import org.whispersystems.libsignal.util.guava.Optional; import java.io.IOException; -import java.util.Collection; import java.util.Collections; import java.util.List; @@ -55,8 +54,8 @@ public class CreateGroupActivity extends ContactSelectionActivity { : ContactsCursorLoader.DisplayMode.FLAG_PUSH; intent.putExtra(ContactSelectionListFragment.DISPLAY_MODE, displayMode); - intent.putExtra(ContactSelectionListFragment.TOTAL_CAPACITY, FeatureFlags.groupsV2create() ? FeatureFlags.gv2GroupCapacity() - 1 - : ContactSelectionListFragment.NO_LIMIT); + intent.putExtra(ContactSelectionListFragment.SELECTION_LIMIT, FeatureFlags.groupsV2create() ? FeatureFlags.gv2GroupCapacity() - 1 + : ContactSelectionListFragment.NO_LIMIT); return intent; } diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/ui/managegroup/ManageGroupRepository.java b/app/src/main/java/org/thoughtcrime/securesms/groups/ui/managegroup/ManageGroupRepository.java index 3e4419e642..4b4a586acd 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/ui/managegroup/ManageGroupRepository.java +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/ui/managegroup/ManageGroupRepository.java @@ -199,6 +199,16 @@ final class ManageGroupRepository { return totalCapacity; } + public int getSelectionLimit() { + if (totalCapacity == ContactSelectionListFragment.NO_LIMIT) { + return totalCapacity; + } + + boolean containsSelf = members.indexOf(Recipient.self().getId()) != -1; + + return totalCapacity - (containsSelf ? 1 : 0); + } + public int getRemainingCapacity() { return totalCapacity - members.size(); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/ui/managegroup/ManageGroupViewModel.java b/app/src/main/java/org/thoughtcrime/securesms/groups/ui/managegroup/ManageGroupViewModel.java index 397a2f64c3..c0de0992fd 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/ui/managegroup/ManageGroupViewModel.java +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/ui/managegroup/ManageGroupViewModel.java @@ -46,7 +46,6 @@ import org.thoughtcrime.securesms.util.Util; import org.thoughtcrime.securesms.util.livedata.LiveDataUtil; import org.thoughtcrime.securesms.util.views.SimpleProgressDialog; -import java.util.ArrayList; import java.util.List; public class ManageGroupViewModel extends ViewModel { @@ -321,7 +320,7 @@ public class ManageGroupViewModel extends ViewModel { Intent intent = new Intent(fragment.requireActivity(), AddMembersActivity.class); intent.putExtra(AddMembersActivity.GROUP_ID, manageGroupRepository.getGroupId().toString()); intent.putExtra(ContactSelectionListFragment.DISPLAY_MODE, ContactsCursorLoader.DisplayMode.FLAG_PUSH); - intent.putExtra(ContactSelectionListFragment.TOTAL_CAPACITY, capacity.getTotalCapacity() - 1); + intent.putExtra(ContactSelectionListFragment.SELECTION_LIMIT, capacity.getSelectionLimit()); intent.putParcelableArrayListExtra(ContactSelectionListFragment.CURRENT_SELECTION, capacity.getMembersWithoutSelf()); fragment.startActivityForResult(intent, resultCode); }