mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
Fix button flicker when selecting single media item.
This commit is contained in:
parent
2f8a7fa296
commit
932e7b4af5
@ -23,7 +23,8 @@
|
||||
android:orientation="horizontal"
|
||||
android:background="@drawable/media_count_button_background"
|
||||
android:elevation="4dp"
|
||||
tools:parentTag="android.widget.LinearLayout">
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/mediasend_count_button_text"
|
||||
|
@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:title=""
|
||||
android:id="@+id/mediapicker_menu_end"
|
||||
android:visible="true"
|
||||
android:icon="@drawable/ic_create_album_filled_32"
|
||||
app:showAsAction="always" />
|
||||
|
||||
</menu>
|
@ -128,6 +128,7 @@ public class MediaPickerItemAdapter extends RecyclerView.Adapter<MediaPickerItem
|
||||
if (maxSelection > 1) {
|
||||
itemView.setOnLongClickListener(v -> {
|
||||
selected.add(media);
|
||||
eventListener.onMediaSelectionStarted();
|
||||
eventListener.onMediaSelectionChanged(new ArrayList<>(selected));
|
||||
return true;
|
||||
});
|
||||
@ -137,6 +138,7 @@ public class MediaPickerItemAdapter extends RecyclerView.Adapter<MediaPickerItem
|
||||
selectOn.setVisibility(View.VISIBLE);
|
||||
selectOverlay.setVisibility(View.VISIBLE);
|
||||
selectOrder.setText(String.valueOf(selected.indexOf(media) + 1));
|
||||
itemView.setOnLongClickListener(null);
|
||||
itemView.setOnClickListener(v -> {
|
||||
selected.remove(media);
|
||||
eventListener.onMediaSelectionChanged(new ArrayList<>(selected));
|
||||
@ -145,6 +147,7 @@ public class MediaPickerItemAdapter extends RecyclerView.Adapter<MediaPickerItem
|
||||
selectOff.setVisibility(View.VISIBLE);
|
||||
selectOn.setVisibility(View.GONE);
|
||||
selectOverlay.setVisibility(View.GONE);
|
||||
itemView.setOnLongClickListener(null);
|
||||
itemView.setOnClickListener(v -> {
|
||||
if (selected.size() < maxSelection) {
|
||||
selected.add(media);
|
||||
@ -165,6 +168,7 @@ public class MediaPickerItemAdapter extends RecyclerView.Adapter<MediaPickerItem
|
||||
|
||||
interface EventListener {
|
||||
void onMediaChosen(@NonNull Media media);
|
||||
void onMediaSelectionStarted();
|
||||
void onMediaSelectionChanged(@NonNull List<Media> media);
|
||||
void onMediaSelectionOverflow(int maxSelection);
|
||||
}
|
||||
|
@ -120,10 +120,10 @@ public class MediaPickerItemFragment extends Fragment implements MediaPickerItem
|
||||
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(Menu menu) {
|
||||
requireActivity().getMenuInflater().inflate(R.menu.mediapicker_default, menu);
|
||||
|
||||
if (viewModel.getCountButtonState().getValue() != null && viewModel.getCountButtonState().getValue().isVisible()) {
|
||||
requireActivity().getMenuInflater().inflate(R.menu.mediapicker_multiselect, menu);
|
||||
} else {
|
||||
requireActivity().getMenuInflater().inflate(R.menu.mediapicker_default, menu);
|
||||
menu.findItem(R.id.mediapicker_menu_add).setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,8 +146,12 @@ public class MediaPickerItemFragment extends Fragment implements MediaPickerItem
|
||||
|
||||
@Override
|
||||
public void onMediaChosen(@NonNull Media media) {
|
||||
viewModel.onSelectedMediaChanged(requireContext(), Collections.singletonList(media));
|
||||
controller.onMediaSelected(bucketId);
|
||||
controller.onMediaSelected(media);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMediaSelectionStarted() {
|
||||
viewModel.onMultiSelectStarted();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -188,6 +192,6 @@ public class MediaPickerItemFragment extends Fragment implements MediaPickerItem
|
||||
}
|
||||
|
||||
public interface Controller {
|
||||
void onMediaSelected(@NonNull String bucketId);
|
||||
void onMediaSelected(@NonNull Media media);
|
||||
}
|
||||
}
|
||||
|
@ -220,7 +220,8 @@ public class MediaSendActivity extends PassphraseRequiredActionBarActivity imple
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMediaSelected(@NonNull String bucketId) {
|
||||
public void onMediaSelected(@NonNull Media media) {
|
||||
viewModel.onSingleMediaSelected(this, media);
|
||||
navigateToMediaSend(recipient, transport, dynamicLanguage.getCurrentLocale());
|
||||
}
|
||||
|
||||
@ -339,7 +340,9 @@ public class MediaSendActivity extends PassphraseRequiredActionBarActivity imple
|
||||
|
||||
if (buttonState.getCount() > 0) {
|
||||
countButton.setOnClickListener(v -> navigateToMediaSend(recipient, transport, locale));
|
||||
animateButtonTextChange(countButton);
|
||||
if (buttonState.isVisible()) {
|
||||
animateButtonTextChange(countButton);
|
||||
}
|
||||
} else {
|
||||
countButton.setOnClickListener(null);
|
||||
}
|
||||
|
@ -241,7 +241,6 @@ public class MediaSendFragment extends Fragment implements ViewTreeObserver.OnGl
|
||||
super.onStop();
|
||||
fragmentPagerAdapter.saveAllState();
|
||||
viewModel.saveDrawState(fragmentPagerAdapter.getSavedState());
|
||||
viewModel.onImageEditorEnded();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,12 +65,12 @@ class MediaSendViewModel extends ViewModel {
|
||||
this.cameraButtonVisibility = new MutableLiveData<>();
|
||||
this.error = new SingleLiveEvent<>();
|
||||
this.savedDrawState = new HashMap<>();
|
||||
this.countButtonVisibility = CountButtonState.Visibility.CONDITIONAL;
|
||||
this.countButtonVisibility = CountButtonState.Visibility.FORCED_OFF;
|
||||
this.lastImageCapture = Optional.absent();
|
||||
this.body = "";
|
||||
|
||||
position.setValue(-1);
|
||||
countButtonState.setValue(new CountButtonState(0, CountButtonState.Visibility.CONDITIONAL));
|
||||
countButtonState.setValue(new CountButtonState(0, countButtonVisibility));
|
||||
cameraButtonVisibility.setValue(false);
|
||||
}
|
||||
|
||||
@ -86,33 +86,54 @@ class MediaSendViewModel extends ViewModel {
|
||||
|
||||
void onSelectedMediaChanged(@NonNull Context context, @NonNull List<Media> newMedia) {
|
||||
repository.getPopulatedMedia(context, newMedia, populatedMedia -> {
|
||||
List<Media> filteredMedia = getFilteredMedia(context, populatedMedia, mediaConstraints);
|
||||
Util.runOnMain(() -> {
|
||||
|
||||
if (filteredMedia.size() != newMedia.size()) {
|
||||
error.postValue(Error.ITEM_TOO_LARGE);
|
||||
} else if (filteredMedia.size() > maxSelection) {
|
||||
filteredMedia = filteredMedia.subList(0, maxSelection);
|
||||
error.postValue(Error.TOO_MANY_ITEMS);
|
||||
}
|
||||
List<Media> filteredMedia = getFilteredMedia(context, populatedMedia, mediaConstraints);
|
||||
|
||||
if (filteredMedia.size() > 0) {
|
||||
String computedId = Stream.of(filteredMedia)
|
||||
.skip(1)
|
||||
.reduce(filteredMedia.get(0).getBucketId().or(Media.ALL_MEDIA_BUCKET_ID), (id, m) -> {
|
||||
if (Util.equals(id, m.getBucketId().or(Media.ALL_MEDIA_BUCKET_ID))) {
|
||||
return id;
|
||||
} else {
|
||||
return Media.ALL_MEDIA_BUCKET_ID;
|
||||
}
|
||||
});
|
||||
bucketId.postValue(computedId);
|
||||
} else {
|
||||
bucketId.postValue(Media.ALL_MEDIA_BUCKET_ID);
|
||||
countButtonVisibility = CountButtonState.Visibility.CONDITIONAL;
|
||||
}
|
||||
if (filteredMedia.size() != newMedia.size()) {
|
||||
error.setValue(Error.ITEM_TOO_LARGE);
|
||||
} else if (filteredMedia.size() > maxSelection) {
|
||||
filteredMedia = filteredMedia.subList(0, maxSelection);
|
||||
error.setValue(Error.TOO_MANY_ITEMS);
|
||||
}
|
||||
|
||||
selectedMedia.postValue(filteredMedia);
|
||||
countButtonState.postValue(new CountButtonState(filteredMedia.size(), countButtonVisibility));
|
||||
if (filteredMedia.size() > 0) {
|
||||
String computedId = Stream.of(filteredMedia)
|
||||
.skip(1)
|
||||
.reduce(filteredMedia.get(0).getBucketId().or(Media.ALL_MEDIA_BUCKET_ID), (id, m) -> {
|
||||
if (Util.equals(id, m.getBucketId().or(Media.ALL_MEDIA_BUCKET_ID))) {
|
||||
return id;
|
||||
} else {
|
||||
return Media.ALL_MEDIA_BUCKET_ID;
|
||||
}
|
||||
});
|
||||
bucketId.setValue(computedId);
|
||||
} else {
|
||||
bucketId.setValue(Media.ALL_MEDIA_BUCKET_ID);
|
||||
countButtonVisibility = CountButtonState.Visibility.CONDITIONAL;
|
||||
}
|
||||
|
||||
selectedMedia.setValue(filteredMedia);
|
||||
countButtonState.setValue(new CountButtonState(filteredMedia.size(), countButtonVisibility));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void onSingleMediaSelected(@NonNull Context context, @NonNull Media media) {
|
||||
repository.getPopulatedMedia(context, Collections.singletonList(media), populatedMedia -> {
|
||||
Util.runOnMain(() -> {
|
||||
List<Media> filteredMedia = getFilteredMedia(context, populatedMedia, mediaConstraints);
|
||||
|
||||
if (filteredMedia.isEmpty()) {
|
||||
error.setValue(Error.ITEM_TOO_LARGE);
|
||||
}
|
||||
|
||||
countButtonVisibility = CountButtonState.Visibility.FORCED_OFF;
|
||||
|
||||
bucketId.setValue(filteredMedia.get(0).getBucketId().or(Media.ALL_MEDIA_BUCKET_ID));
|
||||
selectedMedia.setValue(filteredMedia);
|
||||
countButtonState.setValue(new CountButtonState(filteredMedia.size(), countButtonVisibility));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -127,20 +148,21 @@ class MediaSendViewModel extends ViewModel {
|
||||
cameraButtonVisibility.setValue(false);
|
||||
}
|
||||
|
||||
void onImageEditorEnded() {
|
||||
void onCameraStarted() {
|
||||
countButtonVisibility = CountButtonState.Visibility.CONDITIONAL;
|
||||
countButtonState.setValue(new CountButtonState(getSelectedMediaOrDefault().size(), countButtonVisibility));
|
||||
}
|
||||
|
||||
void onCameraStarted() {
|
||||
cameraButtonVisibility.setValue(false);
|
||||
}
|
||||
|
||||
void onItemPickerStarted() {
|
||||
countButtonVisibility = CountButtonState.Visibility.CONDITIONAL;
|
||||
countButtonState.setValue(new CountButtonState(getSelectedMediaOrDefault().size(), countButtonVisibility));
|
||||
cameraButtonVisibility.setValue(true);
|
||||
}
|
||||
|
||||
void onFolderPickerStarted() {
|
||||
countButtonVisibility = CountButtonState.Visibility.CONDITIONAL;
|
||||
countButtonState.setValue(new CountButtonState(getSelectedMediaOrDefault().size(), countButtonVisibility));
|
||||
cameraButtonVisibility.setValue(true);
|
||||
}
|
||||
|
||||
@ -175,7 +197,7 @@ class MediaSendViewModel extends ViewModel {
|
||||
}
|
||||
|
||||
if (selected.size() >= maxSelection) {
|
||||
error.postValue(Error.TOO_MANY_ITEMS);
|
||||
error.setValue(Error.TOO_MANY_ITEMS);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user