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;
}
public int getSelectedMembersSize() {
return contactSearchMediator.getSelectedMembersSize();
}
private @NonNull Bundle safeArguments() {
return getArguments() != null ? getArguments() : new Bundle();
}

View File

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

View File

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

View File

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