Fix issue with new group members count.

This commit is contained in:
Lakshay Bomotra
2023-10-11 02:42:01 +05:30
committed by Cody Henthorne
parent c00943591d
commit b7eaa9e353
4 changed files with 17 additions and 2 deletions

View File

@@ -423,6 +423,10 @@ public final class ContactSelectionListFragment extends LoggingFragment {
onRefreshListener = null; onRefreshListener = null;
} }
public int getSelectedMembersSize() {
return contactSearchMediator.getSelectedMembersSize();
}
private @NonNull Bundle safeArguments() { private @NonNull Bundle safeArguments() {
return getArguments() != null ? getArguments() : new Bundle(); return getArguments() != null ? getArguments() : new Bundle();
} }

View File

@@ -133,6 +133,10 @@ class ContactSearchMediator(
viewModel.clearSelection() viewModel.clearSelection()
} }
fun getSelectedMembersSize(): Int {
return viewModel.getSelectedMembersSize()
}
fun getSelectedContacts(): Set<ContactSearchKey> { fun getSelectedContacts(): Set<ContactSearchKey> {
return viewModel.getSelectedContacts() return viewModel.getSelectedContacts()
} }

View File

@@ -55,10 +55,14 @@ class ContactSearchViewModel(
val selectionState: LiveData<Set<ContactSearchKey>> = selectionStore.stateLiveData val selectionState: LiveData<Set<ContactSearchKey>> = selectionStore.stateLiveData
val errorEventsStream: Observable<ContactSearchError> = errorEvents val errorEventsStream: Observable<ContactSearchError> = errorEvents
private var selectionSize = 0;
override fun onCleared() { override fun onCleared() {
disposables.clear() disposables.clear()
} }
fun getSelectedMembersSize(): Int {
return selectionSize
}
fun setConfiguration(contactSearchConfiguration: ContactSearchConfiguration) { fun setConfiguration(contactSearchConfiguration: ContactSearchConfiguration) {
val pagedDataSource = ContactSearchPagedDataSource( val pagedDataSource = ContactSearchPagedDataSource(
contactSearchConfiguration, contactSearchConfiguration,
@@ -90,7 +94,7 @@ class ContactSearchViewModel(
val newSelectionEntries = results.filter { it.isSelectable }.map { it.key } - getSelectedContacts() val newSelectionEntries = results.filter { it.isSelectable }.map { it.key } - getSelectedContacts()
val newSelectionSize = newSelectionEntries.size + getSelectedContacts().size val newSelectionSize = newSelectionEntries.size + getSelectedContacts().size
selectionSize = newSelectionSize
if (selectionLimits.hasRecommendedLimit() && getSelectedContacts().size < selectionLimits.recommendedLimit && newSelectionSize >= selectionLimits.recommendedLimit) { if (selectionLimits.hasRecommendedLimit() && getSelectedContacts().size < selectionLimits.recommendedLimit && newSelectionSize >= selectionLimits.recommendedLimit) {
errorEvents.onNext(ContactSearchError.RECOMMENDED_LIMIT_REACHED) errorEvents.onNext(ContactSearchError.RECOMMENDED_LIMIT_REACHED)
} else if (selectionLimits.hasHardLimit() && newSelectionSize > selectionLimits.hardLimit) { } else if (selectionLimits.hasHardLimit() && newSelectionSize > selectionLimits.hardLimit) {
@@ -107,6 +111,8 @@ class ContactSearchViewModel(
} }
fun setKeysNotSelected(contactSearchKeys: Set<ContactSearchKey>) { fun setKeysNotSelected(contactSearchKeys: Set<ContactSearchKey>) {
val newSelectionSize = getSelectedContacts().size - contactSearchKeys.size
selectionSize = newSelectionSize
selectionStore.update { it - contactSearchKeys } selectionStore.update { it - contactSearchKeys }
} }

View File

@@ -121,11 +121,12 @@ public class CreateGroupActivity extends ContactSelectionActivity {
@Override @Override
public void onSelectionChanged() { public void onSelectionChanged() {
int selectedMembers = contactsFragment.getSelectedMembersSize();
int selectedContactsCount = contactsFragment.getTotalMemberCount(); int selectedContactsCount = contactsFragment.getTotalMemberCount();
if (selectedContactsCount == 0) { if (selectedContactsCount == 0) {
getToolbar().setTitle(getString(R.string.CreateGroupActivity__select_members)); getToolbar().setTitle(getString(R.string.CreateGroupActivity__select_members));
} else { } else {
getToolbar().setTitle(getResources().getQuantityString(R.plurals.CreateGroupActivity__d_members, selectedContactsCount, selectedContactsCount)); getToolbar().setTitle(getResources().getQuantityString(R.plurals.CreateGroupActivity__d_members, selectedMembers, selectedMembers));
} }
} }