Change media

bubble_view
Thomas 2 years ago
parent d89c16b3ea
commit 0405e1e29f

@ -402,7 +402,7 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
holderStatus.bindingNotification.status.mainContainer.setAlpha(.7f); holderStatus.bindingNotification.status.mainContainer.setAlpha(.7f);
boolean displayMedia = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_MEDIA_NOTIFICATION), true); boolean displayMedia = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_MEDIA_NOTIFICATION), true);
if (!displayMedia) { if (!displayMedia) {
holderStatus.bindingNotification.status.attachmentsListContainer.setVisibility(View.GONE); holderStatus.bindingNotification.status.media.mediaContainer.setVisibility(View.GONE);
holderStatus.bindingNotification.status.mediaContainer.setVisibility(View.GONE); holderStatus.bindingNotification.status.mediaContainer.setVisibility(View.GONE);
} }
String title = ""; String title = "";

@ -446,9 +446,9 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
LinearLayoutCompat.MarginLayoutParams pmc = (LinearLayoutCompat.MarginLayoutParams) holder.binding.mediaContainer.getLayoutParams(); LinearLayoutCompat.MarginLayoutParams pmc = (LinearLayoutCompat.MarginLayoutParams) holder.binding.mediaContainer.getLayoutParams();
pmc.setMarginStart((int) Helper.convertDpToPixel(6, context)); pmc.setMarginStart((int) Helper.convertDpToPixel(6, context));
holder.binding.mediaContainer.setLayoutParams(pmc); holder.binding.mediaContainer.setLayoutParams(pmc);
LinearLayoutCompat.MarginLayoutParams pal = (LinearLayoutCompat.MarginLayoutParams) holder.binding.attachmentsListContainer.getLayoutParams(); LinearLayoutCompat.MarginLayoutParams pal = (LinearLayoutCompat.MarginLayoutParams) holder.binding.media.mediaContainer.getLayoutParams();
pal.setMarginStart((int) Helper.convertDpToPixel(6, context)); pal.setMarginStart((int) Helper.convertDpToPixel(6, context));
holder.binding.attachmentsListContainer.setLayoutParams(pal); holder.binding.media.mediaContainer.setLayoutParams(pal);
LinearLayoutCompat.MarginLayoutParams pp = (LinearLayoutCompat.MarginLayoutParams) holder.binding.poll.pollContainer.getLayoutParams(); LinearLayoutCompat.MarginLayoutParams pp = (LinearLayoutCompat.MarginLayoutParams) holder.binding.poll.pollContainer.getLayoutParams();
pp.setMarginStart((int) Helper.convertDpToPixel(6, context)); pp.setMarginStart((int) Helper.convertDpToPixel(6, context));
holder.binding.poll.pollContainer.setLayoutParams(pp); holder.binding.poll.pollContainer.setLayoutParams(pp);
@ -1372,7 +1372,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
boolean cardDisplayed = (statusToDeal.card != null && (display_card || statusToDeal.isFocused) && statusToDeal.quote_id == null); boolean cardDisplayed = (statusToDeal.card != null && (display_card || statusToDeal.isFocused) && statusToDeal.quote_id == null);
if (statusToDeal.media_attachments != null && statusToDeal.media_attachments.size() > 0 && (!hideSingleMediaWithCard || !cardDisplayed || statusToDeal.media_attachments.size() > 1)) { if (statusToDeal.media_attachments != null && statusToDeal.media_attachments.size() > 0 && (!hideSingleMediaWithCard || !cardDisplayed || statusToDeal.media_attachments.size() > 1)) {
holder.binding.attachmentsList.removeAllViews();
holder.binding.mediaContainer.removeAllViews(); holder.binding.mediaContainer.removeAllViews();
if ((loadMediaType.equals("ASK") || (loadMediaType.equals("WIFI") && !TimelineHelper.isOnWIFI(context))) && !statusToDeal.canLoadMedia) { if ((loadMediaType.equals("ASK") || (loadMediaType.equals("WIFI") && !TimelineHelper.isOnWIFI(context))) && !statusToDeal.canLoadMedia) {
holder.binding.mediaContainer.setVisibility(View.GONE); holder.binding.mediaContainer.setVisibility(View.GONE);
@ -1385,10 +1385,73 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}); });
} else { } else {
int mediaPosition = 1; int mediaPosition = 1;
boolean singleMedia = statusToDeal.media_attachments.size() == 1; if (!fullAttachement) {
int defaultHeight = (int) Helper.convertDpToPixel(300, context);
if (measuredWidth > 0) {
defaultHeight = (int) (measuredWidth * 3) / 4;
}
LinearLayoutCompat.LayoutParams lp = new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, defaultHeight);
holder.binding.media.mediaContainer.setLayoutParams(lp);
if (statusToDeal.media_attachments.size() == 1) {
holder.binding.media.media1Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.media2Container.mediaRoot.setVisibility(View.GONE);
holder.binding.media.media3Container.mediaRoot.setVisibility(View.GONE);
holder.binding.media.media4Container.mediaRoot.setVisibility(View.GONE);
holder.binding.media.moreMedia.setVisibility(View.GONE);
} else if (statusToDeal.media_attachments.size() == 2) {
holder.binding.media.media1Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.media2Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.media3Container.mediaRoot.setVisibility(View.GONE);
holder.binding.media.media4Container.mediaRoot.setVisibility(View.GONE);
holder.binding.media.moreMedia.setVisibility(View.GONE);
} else if (statusToDeal.media_attachments.size() == 3) {
holder.binding.media.media1Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.media2Container.mediaRoot.setVisibility(View.GONE);
holder.binding.media.media3Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.media4Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.moreMedia.setVisibility(View.GONE);
} else if (statusToDeal.media_attachments.size() == 4) {
holder.binding.media.media1Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.media2Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.media3Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.media4Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.moreMedia.setVisibility(View.GONE);
} else if (statusToDeal.media_attachments.size() > 4) {
holder.binding.media.media1Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.media2Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.media3Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.media4Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.moreMedia.setVisibility(View.VISIBLE);
}
}
for (Attachment attachment : statusToDeal.media_attachments) { for (Attachment attachment : statusToDeal.media_attachments) {
LayoutMediaBinding layoutMediaBinding = LayoutMediaBinding.inflate(LayoutInflater.from(context));
if (fullAttachement) {
}
LayoutMediaBinding layoutMediaBinding = null;
if ((fullAttachement && (!statusToDeal.sensitive || expand_media))) {
layoutMediaBinding = LayoutMediaBinding.inflate(LayoutInflater.from(context));
holder.binding.mediaContainer.addView(layoutMediaBinding.getRoot());
} else {
if (mediaPosition == 1) {
layoutMediaBinding = holder.binding.media.media1Container;
} else if (mediaPosition == 2 && statusToDeal.media_attachments.size() == 3) {
layoutMediaBinding = holder.binding.media.media3Container;
} else if (mediaPosition == 2) {
layoutMediaBinding = holder.binding.media.media2Container;
} else if (mediaPosition == 3 && statusToDeal.media_attachments.size() == 3) {
layoutMediaBinding = holder.binding.media.media4Container;
} else if (mediaPosition == 3) {
layoutMediaBinding = holder.binding.media.media3Container;
} else if (mediaPosition == 4) {
layoutMediaBinding = holder.binding.media.media4Container;
}
}
if (fullAttachement && (!statusToDeal.sensitive || expand_media)) { if (fullAttachement && (!statusToDeal.sensitive || expand_media)) {
float ratio = 1.0f; float ratio = 1.0f;
float mediaH = -1.0f; float mediaH = -1.0f;
float mediaW = -1.0f; float mediaW = -1.0f;
@ -1399,30 +1462,29 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
ratio = measuredWidth > 0 ? measuredWidth / mediaW : 1.0f; ratio = measuredWidth > 0 ? measuredWidth / mediaW : 1.0f;
} }
} }
loadAndAddAttachment(context, layoutMediaBinding, holder, adapter, mediaPosition, mediaW, mediaH, ratio, statusToDeal, attachment, singleMedia); loadAndAddAttachment(context, layoutMediaBinding, holder, adapter, mediaPosition, mediaW, mediaH, ratio, statusToDeal, attachment);
} else { } else {
loadAndAddAttachment(context, layoutMediaBinding, holder, adapter, mediaPosition, -1.f, -1.f, -1.f, statusToDeal, attachment, singleMedia); if (layoutMediaBinding != null) {
loadAndAddAttachment(context, layoutMediaBinding, holder, adapter, mediaPosition, -1.f, -1.f, -1.f, statusToDeal, attachment);
}
} }
mediaPosition++; mediaPosition++;
if ((fullAttachement && (!statusToDeal.sensitive || expand_media)) || singleMedia) {
holder.binding.mediaContainer.addView(layoutMediaBinding.getRoot());
} else {
holder.binding.attachmentsList.addView(layoutMediaBinding.getRoot());
}
} }
if ((!fullAttachement || statusToDeal.sensitive) && !singleMedia) { if (!fullAttachement || statusToDeal.sensitive) {
holder.binding.mediaContainer.setVisibility(View.GONE); holder.binding.mediaContainer.setVisibility(View.GONE);
holder.binding.attachmentsListContainer.setVisibility(View.VISIBLE); holder.binding.media.mediaContainer.setVisibility(View.VISIBLE);
} else { } else {
holder.binding.mediaContainer.setVisibility(View.VISIBLE); holder.binding.mediaContainer.setVisibility(View.VISIBLE);
holder.binding.attachmentsListContainer.setVisibility(View.GONE); holder.binding.media.mediaContainer.setVisibility(View.GONE);
} }
} }
} else { } else {
holder.binding.displayMedia.setVisibility(View.GONE); holder.binding.displayMedia.setVisibility(View.GONE);
holder.binding.mediaContainer.setVisibility(View.GONE); holder.binding.mediaContainer.setVisibility(View.GONE);
holder.binding.attachmentsListContainer.setVisibility(View.GONE); holder.binding.media.mediaContainer.setVisibility(View.GONE);
} }
holder.binding.statusContent.setMovementMethod(LongClickLinkMovementMethod.getInstance()); holder.binding.statusContent.setMovementMethod(LongClickLinkMovementMethod.getInstance());
holder.binding.reblogInfo.setOnClickListener(v -> { holder.binding.reblogInfo.setOnClickListener(v -> {
@ -2202,9 +2264,9 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} }
} }
private static RequestBuilder<Drawable> prepareRequestBuilder(Context context, Attachment attachment, public static RequestBuilder<Drawable> prepareRequestBuilder(Context context, Attachment attachment,
float mediaW, float mediaH, float mediaW, float mediaH,
float focusX, float focusY, boolean isSensitive, boolean isArt) { float focusX, float focusY, boolean isSensitive, boolean isArt) {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean fullAttachement = sharedpreferences.getBoolean(context.getString(R.string.SET_FULL_PREVIEW), false); boolean fullAttachement = sharedpreferences.getBoolean(context.getString(R.string.SET_FULL_PREVIEW), false);
@ -2249,7 +2311,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
StatusViewHolder holder, StatusViewHolder holder,
RecyclerView.Adapter<RecyclerView.ViewHolder> adapter, RecyclerView.Adapter<RecyclerView.ViewHolder> adapter,
int mediaPosition, float mediaW, float mediaH, float ratio, int mediaPosition, float mediaW, float mediaH, float ratio,
Status statusToDeal, Attachment attachment, boolean singleImage) { Status statusToDeal, Attachment attachment) {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
final int timeout = sharedpreferences.getInt(context.getString(R.string.SET_NSFW_TIMEOUT), 5); final int timeout = sharedpreferences.getInt(context.getString(R.string.SET_NSFW_TIMEOUT), 5);
boolean fullAttachement = sharedpreferences.getBoolean(context.getString(R.string.SET_FULL_PREVIEW), false); boolean fullAttachement = sharedpreferences.getBoolean(context.getString(R.string.SET_FULL_PREVIEW), false);
@ -2257,24 +2319,15 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
boolean expand_media = sharedpreferences.getBoolean(context.getString(R.string.SET_EXPAND_MEDIA), false); boolean expand_media = sharedpreferences.getBoolean(context.getString(R.string.SET_EXPAND_MEDIA), false);
LinearLayout.LayoutParams lp; LinearLayout.LayoutParams lp;
int defaultHeight = (int) Helper.convertDpToPixel(200, context);
if (measuredWidth > 0) {
defaultHeight = (int) (measuredWidth * 3) / 4;
}
if (fullAttachement && mediaH > 0 && (!statusToDeal.sensitive || expand_media)) { if (fullAttachement && mediaH > 0 && (!statusToDeal.sensitive || expand_media)) {
lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (int) (mediaH * ratio)); lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (int) (mediaH * ratio));
layoutMediaBinding.media.setScaleType(ImageView.ScaleType.FIT_CENTER); layoutMediaBinding.media.setScaleType(ImageView.ScaleType.FIT_CENTER);
} else { } else {
if (singleImage) { lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, defaultHeight);
} else {
//noinspection SuspiciousNameCombination
lp = new LinearLayout.LayoutParams(defaultHeight, defaultHeight);
}
layoutMediaBinding.media.setScaleType(ImageView.ScaleType.CENTER_CROP); layoutMediaBinding.media.setScaleType(ImageView.ScaleType.CENTER_CROP);
} }
layoutMediaBinding.media.setLayoutParams(lp); layoutMediaBinding.media.setLayoutParams(lp);
float focusX = 0.f; float focusX = 0.f;
@ -2283,10 +2336,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
focusX = statusToDeal.media_attachments.get(0).meta.focus.x; focusX = statusToDeal.media_attachments.get(0).meta.focus.x;
focusY = statusToDeal.media_attachments.get(0).meta.focus.y; focusY = statusToDeal.media_attachments.get(0).meta.focus.y;
} }
layoutMediaBinding.count.setVisibility(View.VISIBLE);
if ((!fullAttachement || statusToDeal.sensitive) && !singleImage) {
layoutMediaBinding.count.setText(String.format(Locale.getDefault(), "%d/%d", mediaPosition, statusToDeal.media_attachments.size()));
}
if (attachment.description != null && attachment.description.trim().length() > 0) { if (attachment.description != null && attachment.description.trim().length() > 0) {
layoutMediaBinding.media.setContentDescription(attachment.description.trim()); layoutMediaBinding.media.setContentDescription(attachment.description.trim());
} }
@ -2366,7 +2416,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
adapter.notifyItemChanged(holder.getBindingAdapterPosition()); adapter.notifyItemChanged(holder.getBindingAdapterPosition());
}); });
if ((!statusToDeal.sensitive || expand_media) && (fullAttachement || singleImage)) { if ((!statusToDeal.sensitive || expand_media) && (fullAttachement)) {
layoutMediaBinding.getRoot().setPadding(0, 0, 0, 10); layoutMediaBinding.getRoot().setPadding(0, 0, 0, 10);
} else { } else {
layoutMediaBinding.getRoot().setPadding(0, 0, 10, 0); layoutMediaBinding.getRoot().setPadding(0, 0, 10, 0);

@ -15,26 +15,46 @@ package app.fedilab.android.mastodon.ui.drawer;
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.mastodon.ui.drawer.StatusAdapter.prepareRequestBuilder;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.core.app.ActivityOptionsCompat;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.RequestBuilder;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.activities.MainActivity; import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.databinding.DrawerStatusChatBinding; import app.fedilab.android.databinding.DrawerStatusChatBinding;
import app.fedilab.android.databinding.LayoutMediaBinding;
import app.fedilab.android.mastodon.activities.MediaActivity;
import app.fedilab.android.mastodon.client.entities.api.Attachment;
import app.fedilab.android.mastodon.client.entities.api.Status; import app.fedilab.android.mastodon.client.entities.api.Status;
import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.helper.MastodonHelper; import app.fedilab.android.mastodon.helper.MastodonHelper;
import app.fedilab.android.mastodon.helper.MediaHelper;
import app.fedilab.android.mastodon.helper.ThemeHelper; import app.fedilab.android.mastodon.helper.ThemeHelper;
public class StatusDirectMessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { public class StatusDirectMessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@ -42,7 +62,7 @@ public class StatusDirectMessageAdapter extends RecyclerView.Adapter<RecyclerVie
private final List<Status> statusList; private final List<Status> statusList;
private Context context; private Context context;
private RecyclerView mRecyclerView; private RecyclerView mRecyclerView;
private static float measuredWidth = -1;
public StatusDirectMessageAdapter(List<Status> data) { public StatusDirectMessageAdapter(List<Status> data) {
this.statusList = data; this.statusList = data;
} }
@ -55,6 +75,132 @@ public class StatusDirectMessageAdapter extends RecyclerView.Adapter<RecyclerVie
return new StatusChatViewHolder(itemBinding); return new StatusChatViewHolder(itemBinding);
} }
public static void loadAndAddAttachment(Context context, LayoutMediaBinding layoutMediaBinding,
StatusChatViewHolder holder,
RecyclerView.Adapter<RecyclerView.ViewHolder> adapter,
int mediaPosition, float mediaW, float mediaH, float ratio,
Status statusToDeal, Attachment attachment) {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
final int timeout = sharedpreferences.getInt(context.getString(R.string.SET_NSFW_TIMEOUT), 5);
boolean long_press_media = sharedpreferences.getBoolean(context.getString(R.string.SET_LONG_PRESS_STORE_MEDIA), false);
boolean expand_media = sharedpreferences.getBoolean(context.getString(R.string.SET_EXPAND_MEDIA), false);
LinearLayout.LayoutParams lp;
lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
layoutMediaBinding.media.setScaleType(ImageView.ScaleType.CENTER_CROP);
layoutMediaBinding.media.setLayoutParams(lp);
float focusX = 0.f;
float focusY = 0.f;
if (statusToDeal.media_attachments.get(0).meta != null && statusToDeal.media_attachments.get(0).meta.focus != null) {
focusX = statusToDeal.media_attachments.get(0).meta.focus.x;
focusY = statusToDeal.media_attachments.get(0).meta.focus.y;
}
if (attachment.description != null && attachment.description.trim().length() > 0) {
layoutMediaBinding.media.setContentDescription(attachment.description.trim());
}
String finalUrl;
if (attachment.url == null) {
finalUrl = attachment.remote_url;
} else {
finalUrl = attachment.url;
}
layoutMediaBinding.media.setOnLongClickListener(v -> {
if (long_press_media) {
MediaHelper.manageMove(context, finalUrl, false);
}
return true;
});
if (attachment.type != null && (attachment.type.equalsIgnoreCase("video") || attachment.type.equalsIgnoreCase("gifv"))) {
layoutMediaBinding.playVideo.setVisibility(View.VISIBLE);
} else {
layoutMediaBinding.playVideo.setVisibility(View.GONE);
}
if (attachment.type != null && attachment.type.equalsIgnoreCase("audio")) {
layoutMediaBinding.playMusic.setVisibility(View.VISIBLE);
} else {
layoutMediaBinding.playMusic.setVisibility(View.GONE);
}
if (attachment.description != null && !attachment.description.isEmpty()) {
layoutMediaBinding.viewDescription.setVisibility(View.VISIBLE);
} else {
layoutMediaBinding.viewDescription.setVisibility(View.GONE);
}
RequestBuilder<Drawable> requestBuilder = prepareRequestBuilder(context, attachment, mediaW * ratio, mediaH * ratio, focusX, focusY, statusToDeal.sensitive, false);
if (!statusToDeal.sensitive || expand_media) {
layoutMediaBinding.viewHide.setImageResource(R.drawable.ic_baseline_visibility_24);
} else {
layoutMediaBinding.viewHide.setImageResource(R.drawable.ic_baseline_visibility_off_24);
}
requestBuilder.load(attachment.preview_url).into(layoutMediaBinding.media);
if (statusToDeal.sensitive) {
Helper.changeDrawableColor(context, layoutMediaBinding.viewHide, ThemeHelper.getAttColor(context, R.attr.colorError));
} else {
Helper.changeDrawableColor(context, layoutMediaBinding.viewHide, R.color.white);
}
layoutMediaBinding.media.setOnClickListener(v -> {
if (statusToDeal.sensitive && !expand_media) {
statusToDeal.sensitive = false;
int position = holder.getBindingAdapterPosition();
adapter.notifyItemChanged(position);
if (timeout > 0) {
new CountDownTimer((timeout * 1000L), 1000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
statusToDeal.sensitive = true;
adapter.notifyItemChanged(position);
}
}.start();
}
return;
}
Intent mediaIntent = new Intent(context, MediaActivity.class);
Bundle b = new Bundle();
b.putInt(Helper.ARG_MEDIA_POSITION, mediaPosition);
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);
// start the new activity
context.startActivity(mediaIntent, options.toBundle());
});
layoutMediaBinding.viewHide.setOnClickListener(v -> {
statusToDeal.sensitive = !statusToDeal.sensitive;
adapter.notifyItemChanged(holder.getBindingAdapterPosition());
});
}
@Override
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
mRecyclerView = recyclerView;
}
@Override
public int getItemCount() {
return statusList.size();
}
public static class StatusChatViewHolder extends RecyclerView.ViewHolder {
DrawerStatusChatBinding binding;
StatusChatViewHolder(DrawerStatusChatBinding itemView) {
super(itemView.getRoot());
binding = itemView;
}
}
@Override @Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) { public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
@ -66,7 +212,16 @@ public class StatusDirectMessageAdapter extends RecyclerView.Adapter<RecyclerVie
new WeakReference<>(holder.binding.messageContent), new WeakReference<>(holder.binding.messageContent),
() -> mRecyclerView.post(() -> notifyItemChanged(holder.getBindingAdapterPosition()))), () -> mRecyclerView.post(() -> notifyItemChanged(holder.getBindingAdapterPosition()))),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
if (measuredWidth <= 0 && status.media_attachments != null && status.media_attachments.size() > 0) {
holder.binding.media.mediaContainer.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
holder.binding.media.mediaContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this);
measuredWidth = holder.binding.media.mediaContainer.getWidth();
notifyItemChanged(0, statusList.size());
}
});
}
MastodonHelper.loadPPMastodon(holder.binding.userPp, status.account); MastodonHelper.loadPPMastodon(holder.binding.userPp, status.account);
holder.binding.date.setText(Helper.longDateToString(status.created_at)); holder.binding.date.setText(Helper.longDateToString(status.created_at));
//Owner account //Owner account
@ -83,42 +238,70 @@ public class StatusDirectMessageAdapter extends RecyclerView.Adapter<RecyclerVie
holder.binding.userName.setTextColor(ThemeHelper.getAttColor(context, textColor)); holder.binding.userName.setTextColor(ThemeHelper.getAttColor(context, textColor));
if (status.media_attachments != null && status.media_attachments.size() > 0) { if (status.media_attachments != null && status.media_attachments.size() > 0) {
holder.binding.media.container.setVisibility(View.VISIBLE); holder.binding.media.mediaContainer.setVisibility(View.VISIBLE);
if (status.media_attachments.size() == 1) { int mediaPosition = 1;
int defaultHeight = (int) Helper.convertDpToPixel(300, context);
if (measuredWidth > 0) {
defaultHeight = (int) (measuredWidth * 3) / 4;
}
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, defaultHeight);
holder.binding.media.mediaContainer.setLayoutParams(lp);
if (status.media_attachments.size() == 1) {
holder.binding.media.media1Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.media2Container.mediaRoot.setVisibility(View.GONE);
holder.binding.media.media3Container.mediaRoot.setVisibility(View.GONE);
holder.binding.media.media4Container.mediaRoot.setVisibility(View.GONE);
holder.binding.media.moreMedia.setVisibility(View.GONE);
} else if (status.media_attachments.size() == 2) { } else if (status.media_attachments.size() == 2) {
holder.binding.media.media1Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.media2Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.media3Container.mediaRoot.setVisibility(View.GONE);
holder.binding.media.media4Container.mediaRoot.setVisibility(View.GONE);
holder.binding.media.moreMedia.setVisibility(View.GONE);
} else if (status.media_attachments.size() == 3) { } else if (status.media_attachments.size() == 3) {
holder.binding.media.media1Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.media2Container.mediaRoot.setVisibility(View.GONE);
holder.binding.media.media3Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.media4Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.moreMedia.setVisibility(View.GONE);
} else if (status.media_attachments.size() == 4) { } else if (status.media_attachments.size() == 4) {
holder.binding.media.media1Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.media2Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.media3Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.media4Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.moreMedia.setVisibility(View.GONE);
} else if (status.media_attachments.size() > 4) {
holder.binding.media.media1Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.media2Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.media3Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.media4Container.mediaRoot.setVisibility(View.VISIBLE);
holder.binding.media.moreMedia.setVisibility(View.VISIBLE);
}
for (Attachment attachment : status.media_attachments) {
LayoutMediaBinding layoutMediaBinding = null;
if (mediaPosition == 1) {
layoutMediaBinding = holder.binding.media.media1Container;
} else if (mediaPosition == 2 && status.media_attachments.size() == 3) {
layoutMediaBinding = holder.binding.media.media3Container;
} else if (mediaPosition == 2) {
layoutMediaBinding = holder.binding.media.media2Container;
} else if (mediaPosition == 3 && status.media_attachments.size() == 3) {
layoutMediaBinding = holder.binding.media.media4Container;
} else if (mediaPosition == 3) {
layoutMediaBinding = holder.binding.media.media3Container;
} else if (mediaPosition == 4) {
layoutMediaBinding = holder.binding.media.media4Container;
}
if (layoutMediaBinding != null) {
loadAndAddAttachment(context, layoutMediaBinding, holder, this, mediaPosition, -1.f, -1.f, -1.f, status, attachment);
}
} else {
mediaPosition++;
} }
} else { } else {
holder.binding.media.container.setVisibility(View.GONE); holder.binding.media.mediaContainer.setVisibility(View.GONE);
}
}
@Override
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
mRecyclerView = recyclerView;
}
@Override
public int getItemCount() {
return statusList.size();
}
public static class StatusChatViewHolder extends RecyclerView.ViewHolder {
DrawerStatusChatBinding binding;
StatusChatViewHolder(DrawerStatusChatBinding itemView) {
super(itemView.getRoot());
binding = itemView;
} }
} }
} }

@ -55,6 +55,7 @@
tools:text="@tools:sample/lorem/random" /> tools:text="@tools:sample/lorem/random" />
<include <include
android:id="@+id/media"
layout="@layout/layout_drawer_attachments" layout="@layout/layout_drawer_attachments"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

@ -1,75 +1,70 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"> xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/media_container"
android:layout_height="300dp">
<androidx.appcompat.widget.LinearLayoutCompat <include
android:layout_width="match_parent" android:id="@+id/media1_container"
layout="@layout/layout_media"
android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1"> android:layout_margin="1dp"
app:layout_constraintBottom_toTopOf="@+id/media3_container"
<androidx.appcompat.widget.AppCompatImageView app:layout_constraintEnd_toStartOf="@+id/media2_container"
android:id="@+id/media1" app:layout_constraintStart_toStartOf="parent"
android:layout_width="0dp" app:layout_constraintTop_toTopOf="parent" />
android:layout_height="150dp"
android:layout_weight="1"
android:scaleType="centerCrop"
tools:src="@tools:sample/backgrounds/scenic" />
<androidx.appcompat.widget.AppCompatImageView <include
android:id="@+id/media2" android:id="@+id/media2_container"
android:layout_width="0dp" layout="@layout/layout_media"
android:layout_height="150dp" android:layout_width="0dp"
android:layout_marginStart="6dp" android:layout_margin="1dp"
android:layout_weight="1"
android:scaleType="centerCrop"
tools:src="@tools:sample/backgrounds/scenic" />
</androidx.appcompat.widget.LinearLayoutCompat>
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_marginTop="6dp" android:visibility="gone"
android:layout_weight="1"> app:layout_constraintBottom_toTopOf="@+id/media4_container"
app:layout_constraintEnd_toEndOf="parent"
<androidx.appcompat.widget.AppCompatImageView app:layout_constraintStart_toEndOf="@id/media1_container"
android:id="@+id/media3" app:layout_constraintTop_toTopOf="parent" />
android:layout_width="0dp"
android:layout_height="150dp"
android:layout_weight="1"
android:scaleType="centerCrop"
tools:src="@tools:sample/backgrounds/scenic" />
<RelativeLayout <include
android:id="@+id/media4_container" android:id="@+id/media3_container"
android:layout_width="0dp" layout="@layout/layout_media"
android:layout_height="150dp" android:layout_width="0dp"
android:layout_marginStart="6dp" android:layout_height="0dp"
android:layout_weight="1"> android:layout_margin="1dp"
android:visibility="gone"
<androidx.appcompat.widget.AppCompatImageView app:layout_constraintBottom_toBottomOf="parent"
android:id="@+id/media4" app:layout_constraintEnd_toStartOf="@+id/media4_container"
android:layout_width="match_parent" app:layout_constraintStart_toStartOf="parent"
android:layout_height="match_parent" app:layout_constraintTop_toBottomOf="@+id/media1_container" />
android:scaleType="centerCrop"
tools:src="@tools:sample/backgrounds/scenic" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/more_media"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#88000000"
android:gravity="center"
android:scaleType="centerCrop"
android:textColor="@color/white"
tools:text="+7 more media" />
</RelativeLayout>
</androidx.appcompat.widget.LinearLayoutCompat> <include
android:id="@+id/media4_container"
layout="@layout/layout_media"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="1dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/media3_container"
app:layout_constraintTop_toBottomOf="@id/media2_container" />
</androidx.appcompat.widget.LinearLayoutCompat> <androidx.appcompat.widget.AppCompatTextView
android:id="@+id/more_media"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#88000000"
android:gravity="center"
android:textColor="@color/white"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/media4_container"
app:layout_constraintTop_toTopOf="@+id/media4_container"
tools:text="+7 more media" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -4,13 +4,15 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/media_root" android:id="@+id/media_root"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="match_parent">
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/media" android:id="@+id/media"
android:adjustViewBounds="true" android:adjustViewBounds="true"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" tools:src="@tools:sample/backgrounds/scenic"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
@ -67,19 +69,4 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
tools:visibility="visible" /> tools:visibility="visible" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="5dp"
android:layout_marginBottom="5dp"
android:textSize="16sp"
android:textStyle="bold"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/media"
app:layout_constraintStart_toStartOf="parent"
tools:text="2/4"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save