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,16 +147,18 @@ 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) {
binding.loader.setVisibility(View.GONE); if (binding != null) {
if (binding.mediaPicture.getScale() < 1.1) { binding.loader.setVisibility(View.GONE);
binding.mediaPicture.setImageBitmap(resource); if (binding.mediaPicture.getScale() < 1.1) {
} else { binding.mediaPicture.setImageBitmap(resource);
binding.messageReady.setVisibility(View.VISIBLE); } else {
binding.messageReady.setVisibility(View.VISIBLE);
}
binding.messageReady.setOnClickListener(view -> {
binding.mediaPicture.setImageBitmap(resource);
binding.messageReady.setVisibility(View.GONE);
});
} }
binding.messageReady.setOnClickListener(view -> {
binding.mediaPicture.setImageBitmap(resource);
binding.messageReady.setVisibility(View.GONE);
});
} }
@Override @Override