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

View File

@ -147,16 +147,18 @@ public class FragmentMedia extends Fragment {
new CustomTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull final Bitmap resource, Transition<? super Bitmap> transition) {
binding.loader.setVisibility(View.GONE);
if (binding.mediaPicture.getScale() < 1.1) {
binding.mediaPicture.setImageBitmap(resource);
} else {
binding.messageReady.setVisibility(View.VISIBLE);
if (binding != null) {
binding.loader.setVisibility(View.GONE);
if (binding.mediaPicture.getScale() < 1.1) {
binding.mediaPicture.setImageBitmap(resource);
} 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