mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-26 12:37:52 +00:00
Fix bug displaying an empty camera contacts search result.
This commit is contained in:
@@ -119,8 +119,7 @@ class CameraContactAdapter extends SectionedRecyclerViewAdapter<String, CameraCo
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
int count = super.getItemCount();
|
||||
return count > 0 ? count + 1 : 0;
|
||||
return super.getItemCount() + 1;
|
||||
}
|
||||
|
||||
public void setContacts(@NonNull CameraContacts contacts, @NonNull Collection<Recipient> selected) {
|
||||
@@ -140,8 +139,7 @@ class CameraContactAdapter extends SectionedRecyclerViewAdapter<String, CameraCo
|
||||
}
|
||||
|
||||
private boolean isInvitePosition(int globalPosition) {
|
||||
int count = getItemCount();
|
||||
return count > 0 && globalPosition == getItemCount() - 1;
|
||||
return globalPosition == getItemCount() - 1;
|
||||
}
|
||||
|
||||
public static class ContactSection extends SectionedRecyclerViewAdapter.Section<String> {
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.mediasend;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
@@ -163,11 +164,13 @@ public class CameraContactSelectionFragment extends Fragment implements CameraCo
|
||||
contactViewModel.getContacts().observe(getViewLifecycleOwner(), contactState -> {
|
||||
if (contactState == null) return;
|
||||
|
||||
if (contactState.getContacts().isEmpty()) {
|
||||
if (contactState.getContacts().isEmpty() && TextUtils.isEmpty(contactState.getQuery())) {
|
||||
cameraContactsEmpty.setVisibility(View.VISIBLE);
|
||||
contactList.setVisibility(View.GONE);
|
||||
selectionFooterGroup.setVisibility(View.GONE);
|
||||
} else {
|
||||
cameraContactsEmpty.setVisibility(View.GONE);
|
||||
contactList.setVisibility(View.VISIBLE);
|
||||
|
||||
sendButton.setOnClickListener(v -> controller.onCameraContactsSendClicked(contactState.getSelected()));
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.thoughtcrime.securesms.mediasend;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
@@ -24,6 +25,8 @@ class CameraContactSelectionViewModel extends ViewModel {
|
||||
private final SingleLiveEvent<Error> error;
|
||||
private final Set<Recipient> selected;
|
||||
|
||||
private String currentQuery;
|
||||
|
||||
private CameraContactSelectionViewModel(@NonNull CameraContactsRepository repository) {
|
||||
this.repository = repository;
|
||||
this.contacts = new MutableLiveData<>();
|
||||
@@ -32,7 +35,7 @@ class CameraContactSelectionViewModel extends ViewModel {
|
||||
|
||||
repository.getCameraContacts(cameraContacts -> {
|
||||
Util.runOnMain(() -> {
|
||||
contacts.postValue(new ContactState(cameraContacts, new ArrayList<>(selected)));
|
||||
contacts.postValue(new ContactState(cameraContacts, new ArrayList<>(selected), currentQuery));
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -50,9 +53,11 @@ class CameraContactSelectionViewModel extends ViewModel {
|
||||
}
|
||||
|
||||
void onQueryUpdated(String query) {
|
||||
this.currentQuery = query;
|
||||
|
||||
repository.getCameraContacts(query, cameraContacts -> {
|
||||
Util.runOnMain(() -> {
|
||||
contacts.postValue(new ContactState(cameraContacts, new ArrayList<>(selected)));
|
||||
contacts.postValue(new ContactState(cameraContacts, new ArrayList<>(selected), query));
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -60,7 +65,7 @@ class CameraContactSelectionViewModel extends ViewModel {
|
||||
void onRefresh() {
|
||||
repository.getCameraContacts(cameraContacts -> {
|
||||
Util.runOnMain(() -> {
|
||||
contacts.postValue(new ContactState(cameraContacts, new ArrayList<>(selected)));
|
||||
contacts.postValue(new ContactState(cameraContacts, new ArrayList<>(selected), currentQuery));
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -77,17 +82,19 @@ class CameraContactSelectionViewModel extends ViewModel {
|
||||
ContactState currentState = contacts.getValue();
|
||||
|
||||
if (currentState != null) {
|
||||
contacts.setValue(new ContactState(currentState.getContacts(), new ArrayList<>(selected)));
|
||||
contacts.setValue(new ContactState(currentState.getContacts(), new ArrayList<>(selected), currentQuery));
|
||||
}
|
||||
}
|
||||
|
||||
static class ContactState {
|
||||
private final CameraContacts contacts;
|
||||
private final CameraContacts contacts;
|
||||
private final List<Recipient> selected;
|
||||
private final String query;
|
||||
|
||||
ContactState(CameraContacts contacts, List<Recipient> selected) {
|
||||
ContactState(@NonNull CameraContacts contacts, @NonNull List<Recipient> selected, @Nullable String query) {
|
||||
this.contacts = contacts;
|
||||
this.selected = selected;
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
public CameraContacts getContacts() {
|
||||
@@ -97,6 +104,10 @@ class CameraContactSelectionViewModel extends ViewModel {
|
||||
public List<Recipient> getSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
public @Nullable String getQuery() {
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
enum Error {
|
||||
|
||||
Reference in New Issue
Block a user