Fix issue #21 - Media click position always open the first one

This commit is contained in:
Thomas 2022-05-05 17:55:25 +02:00
parent 28fe8dd584
commit 0e7c5cb946
2 changed files with 16 additions and 12 deletions

View File

@ -802,7 +802,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.mediaContainer.setVisibility(View.VISIBLE); holder.binding.mediaContainer.setVisibility(View.VISIBLE);
holder.binding.attachmentsListContainer.setVisibility(View.GONE); holder.binding.attachmentsListContainer.setVisibility(View.GONE);
} else { //Several media } else { //Several media
int mediaPosition = 1;
for (Attachment attachment : statusToDeal.media_attachments) { for (Attachment attachment : statusToDeal.media_attachments) {
LayoutMediaBinding layoutMediaBinding = LayoutMediaBinding.inflate(LayoutInflater.from(context), holder.binding.attachmentsList, false); LayoutMediaBinding layoutMediaBinding = LayoutMediaBinding.inflate(LayoutInflater.from(context), holder.binding.attachmentsList, false);
RelativeLayout.LayoutParams lp; RelativeLayout.LayoutParams lp;
@ -834,14 +834,15 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
Helper.changeDrawableColor(context, layoutMediaBinding.viewHide, R.color.white); Helper.changeDrawableColor(context, layoutMediaBinding.viewHide, R.color.white);
} }
layoutMediaBinding.media.setLayoutParams(lp); layoutMediaBinding.media.setLayoutParams(lp);
int finalMediaPosition = mediaPosition;
layoutMediaBinding.media.setOnClickListener(v -> { layoutMediaBinding.media.setOnClickListener(v -> {
Intent mediaIntent = new Intent(context, MediaActivity.class); Intent mediaIntent = new Intent(context, MediaActivity.class);
Bundle b = new Bundle(); Bundle b = new Bundle();
b.putInt(Helper.ARG_MEDIA_POSITION, 1); b.putInt(Helper.ARG_MEDIA_POSITION, finalMediaPosition);
b.putSerializable(Helper.ARG_MEDIA_ARRAY, new ArrayList<>(statusToDeal.media_attachments)); b.putSerializable(Helper.ARG_MEDIA_ARRAY, new ArrayList<>(statusToDeal.media_attachments));
mediaIntent.putExtras(b); mediaIntent.putExtras(b);
ActivityOptionsCompat options = ActivityOptionsCompat ActivityOptionsCompat options = ActivityOptionsCompat
.makeSceneTransitionAnimation((Activity) context, layoutMediaBinding.media, statusToDeal.media_attachments.get(0).url); .makeSceneTransitionAnimation((Activity) context, layoutMediaBinding.media, statusToDeal.media_attachments.get(finalMediaPosition - 1).url);
// start the new activity // start the new activity
context.startActivity(mediaIntent, options.toBundle()); context.startActivity(mediaIntent, options.toBundle());
}); });
@ -850,6 +851,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
}); });
holder.binding.attachmentsList.addView(layoutMediaBinding.getRoot()); holder.binding.attachmentsList.addView(layoutMediaBinding.getRoot());
mediaPosition++;
} }
holder.binding.mediaContainer.setVisibility(View.GONE); holder.binding.mediaContainer.setVisibility(View.GONE);
holder.binding.attachmentsListContainer.setVisibility(View.VISIBLE); holder.binding.attachmentsListContainer.setVisibility(View.VISIBLE);

View File

@ -147,6 +147,7 @@ public class FragmentMedia extends Fragment {
new CustomTarget<Bitmap>() { new CustomTarget<Bitmap>() {
@Override @Override
public void onResourceReady(@NonNull final Bitmap resource, Transition<? super Bitmap> transition) { public void onResourceReady(@NonNull final Bitmap resource, Transition<? super Bitmap> transition) {
if (binding != null) {
binding.loader.setVisibility(View.GONE); binding.loader.setVisibility(View.GONE);
if (binding.mediaPicture.getScale() < 1.1) { if (binding.mediaPicture.getScale() < 1.1) {
binding.mediaPicture.setImageBitmap(resource); binding.mediaPicture.setImageBitmap(resource);
@ -158,6 +159,7 @@ public class FragmentMedia extends Fragment {
binding.messageReady.setVisibility(View.GONE); binding.messageReady.setVisibility(View.GONE);
}); });
} }
}
@Override @Override
public void onLoadCleared(@Nullable Drawable placeholder) { public void onLoadCleared(@Nullable Drawable placeholder) {