Fix group limit enforcement and display.
This commit is contained in:
parent
40a8d21c15
commit
e316a70b6c
3 changed files with 22 additions and 4 deletions
|
@ -512,7 +512,7 @@ public final class ContactSelectionListFragment extends LoggingFragment
|
|||
}
|
||||
|
||||
private boolean selectionLimitReached() {
|
||||
return getChipCount() >= selectionLimit;
|
||||
return getChipCount() + currentSelection.size() >= selectionLimit;
|
||||
}
|
||||
|
||||
private void markContactSelected(@NonNull SelectedContact selectedContact) {
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.thoughtcrime.securesms.util.concurrent.SignalExecutors;
|
|||
import org.thoughtcrime.securesms.util.concurrent.SimpleTask;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -197,6 +198,23 @@ final class ManageGroupRepository {
|
|||
public int getTotalCapacity() {
|
||||
return totalCapacity;
|
||||
}
|
||||
|
||||
public int getRemainingCapacity() {
|
||||
return totalCapacity - members.size();
|
||||
}
|
||||
|
||||
public @NonNull ArrayList<RecipientId> getMembersWithoutSelf() {
|
||||
ArrayList<RecipientId> recipientIds = new ArrayList<>(members.size());
|
||||
RecipientId selfId = Recipient.self().getId();
|
||||
|
||||
for (RecipientId recipientId : members) {
|
||||
if (!recipientId.equals(selfId)) {
|
||||
recipientIds.add(recipientId);
|
||||
}
|
||||
}
|
||||
|
||||
return recipientIds;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -314,15 +314,15 @@ public class ManageGroupViewModel extends ViewModel {
|
|||
|
||||
public void onAddMembersClick(@NonNull Fragment fragment, int resultCode) {
|
||||
manageGroupRepository.getGroupCapacity(capacity -> {
|
||||
int remainingCapacity = capacity.getTotalCapacity();
|
||||
int remainingCapacity = capacity.getRemainingCapacity();
|
||||
if (remainingCapacity <= 0) {
|
||||
Toast.makeText(fragment.requireContext(), R.string.ContactSelectionListFragment_the_group_is_full, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
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, remainingCapacity);
|
||||
intent.putParcelableArrayListExtra(ContactSelectionListFragment.CURRENT_SELECTION, new ArrayList<>(capacity.getMembers()));
|
||||
intent.putExtra(ContactSelectionListFragment.TOTAL_CAPACITY, capacity.getTotalCapacity() - 1);
|
||||
intent.putParcelableArrayListExtra(ContactSelectionListFragment.CURRENT_SELECTION, capacity.getMembersWithoutSelf());
|
||||
fragment.startActivityForResult(intent, resultCode);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue