mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 14:38:33 +00:00
Fix bug displaying an empty camera contacts search result.
This commit is contained in:
parent
a5fbcffa14
commit
4ca90374b9
@ -73,6 +73,7 @@
|
|||||||
android:id="@+id/camera_contacts_list"
|
android:id="@+id/camera_contacts_list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
|
android:visibility="gone"
|
||||||
app:layout_constraintBottom_toBottomOf="@id/camera_contacts_footer_barrier"
|
app:layout_constraintBottom_toBottomOf="@id/camera_contacts_footer_barrier"
|
||||||
app:layout_constraintTop_toBottomOf="@id/camera_contacts_toolbar" />
|
app:layout_constraintTop_toBottomOf="@id/camera_contacts_toolbar" />
|
||||||
|
|
||||||
|
@ -119,8 +119,7 @@ class CameraContactAdapter extends SectionedRecyclerViewAdapter<String, CameraCo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
int count = super.getItemCount();
|
return super.getItemCount() + 1;
|
||||||
return count > 0 ? count + 1 : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContacts(@NonNull CameraContacts contacts, @NonNull Collection<Recipient> selected) {
|
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) {
|
private boolean isInvitePosition(int globalPosition) {
|
||||||
int count = getItemCount();
|
return globalPosition == getItemCount() - 1;
|
||||||
return count > 0 && globalPosition == getItemCount() - 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ContactSection extends SectionedRecyclerViewAdapter.Section<String> {
|
public static class ContactSection extends SectionedRecyclerViewAdapter.Section<String> {
|
||||||
|
@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.mediasend;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@ -163,11 +164,13 @@ public class CameraContactSelectionFragment extends Fragment implements CameraCo
|
|||||||
contactViewModel.getContacts().observe(getViewLifecycleOwner(), contactState -> {
|
contactViewModel.getContacts().observe(getViewLifecycleOwner(), contactState -> {
|
||||||
if (contactState == null) return;
|
if (contactState == null) return;
|
||||||
|
|
||||||
if (contactState.getContacts().isEmpty()) {
|
if (contactState.getContacts().isEmpty() && TextUtils.isEmpty(contactState.getQuery())) {
|
||||||
cameraContactsEmpty.setVisibility(View.VISIBLE);
|
cameraContactsEmpty.setVisibility(View.VISIBLE);
|
||||||
|
contactList.setVisibility(View.GONE);
|
||||||
selectionFooterGroup.setVisibility(View.GONE);
|
selectionFooterGroup.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
cameraContactsEmpty.setVisibility(View.GONE);
|
cameraContactsEmpty.setVisibility(View.GONE);
|
||||||
|
contactList.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
sendButton.setOnClickListener(v -> controller.onCameraContactsSendClicked(contactState.getSelected()));
|
sendButton.setOnClickListener(v -> controller.onCameraContactsSendClicked(contactState.getSelected()));
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.thoughtcrime.securesms.mediasend;
|
package org.thoughtcrime.securesms.mediasend;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
import androidx.lifecycle.ViewModel;
|
import androidx.lifecycle.ViewModel;
|
||||||
@ -24,6 +25,8 @@ class CameraContactSelectionViewModel extends ViewModel {
|
|||||||
private final SingleLiveEvent<Error> error;
|
private final SingleLiveEvent<Error> error;
|
||||||
private final Set<Recipient> selected;
|
private final Set<Recipient> selected;
|
||||||
|
|
||||||
|
private String currentQuery;
|
||||||
|
|
||||||
private CameraContactSelectionViewModel(@NonNull CameraContactsRepository repository) {
|
private CameraContactSelectionViewModel(@NonNull CameraContactsRepository repository) {
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.contacts = new MutableLiveData<>();
|
this.contacts = new MutableLiveData<>();
|
||||||
@ -32,7 +35,7 @@ class CameraContactSelectionViewModel extends ViewModel {
|
|||||||
|
|
||||||
repository.getCameraContacts(cameraContacts -> {
|
repository.getCameraContacts(cameraContacts -> {
|
||||||
Util.runOnMain(() -> {
|
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) {
|
void onQueryUpdated(String query) {
|
||||||
|
this.currentQuery = query;
|
||||||
|
|
||||||
repository.getCameraContacts(query, cameraContacts -> {
|
repository.getCameraContacts(query, cameraContacts -> {
|
||||||
Util.runOnMain(() -> {
|
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() {
|
void onRefresh() {
|
||||||
repository.getCameraContacts(cameraContacts -> {
|
repository.getCameraContacts(cameraContacts -> {
|
||||||
Util.runOnMain(() -> {
|
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();
|
ContactState currentState = contacts.getValue();
|
||||||
|
|
||||||
if (currentState != null) {
|
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 {
|
static class ContactState {
|
||||||
private final CameraContacts contacts;
|
private final CameraContacts contacts;
|
||||||
private final List<Recipient> selected;
|
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.contacts = contacts;
|
||||||
this.selected = selected;
|
this.selected = selected;
|
||||||
|
this.query = query;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CameraContacts getContacts() {
|
public CameraContacts getContacts() {
|
||||||
@ -97,6 +104,10 @@ class CameraContactSelectionViewModel extends ViewModel {
|
|||||||
public List<Recipient> getSelected() {
|
public List<Recipient> getSelected() {
|
||||||
return selected;
|
return selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @Nullable String getQuery() {
|
||||||
|
return query;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Error {
|
enum Error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user