mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-22 16:50:04 +02:00
Fix issue #815 - Bad behavior with gif
This commit is contained in:
parent
dc9b31b4eb
commit
6fb6d295d4
4 changed files with 276 additions and 86 deletions
|
@ -65,6 +65,7 @@ import android.widget.GridView;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
@ -96,6 +97,7 @@ import com.google.android.exoplayer2.ExoPlayer;
|
|||
import com.google.android.exoplayer2.MediaItem;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
|
||||
import com.google.android.exoplayer2.ui.PlayerView;
|
||||
import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import com.google.android.exoplayer2.upstream.DefaultDataSource;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
|
@ -1429,12 +1431,32 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
});
|
||||
}
|
||||
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
|
||||
holder.binding.mediaContainer.removeAllViews();
|
||||
PlayerView video = holder.binding.media.media1Container.findViewById(R.id.media_video);
|
||||
if (video != null && video.getPlayer() != null) {
|
||||
video.getPlayer().release();
|
||||
}
|
||||
holder.binding.media.media1Container.removeAllViews();
|
||||
video = holder.binding.media.media2Container.findViewById(R.id.media_video);
|
||||
if (video != null && video.getPlayer() != null) {
|
||||
video.getPlayer().release();
|
||||
}
|
||||
holder.binding.media.media2Container.removeAllViews();
|
||||
video = holder.binding.media.media3Container.findViewById(R.id.media_video);
|
||||
if (video != null && video.getPlayer() != null) {
|
||||
video.getPlayer().release();
|
||||
}
|
||||
holder.binding.media.media3Container.removeAllViews();
|
||||
video = holder.binding.media.media4Container.findViewById(R.id.media_video);
|
||||
if (video != null && video.getPlayer() != null) {
|
||||
video.getPlayer().release();
|
||||
}
|
||||
holder.binding.media.media4Container.removeAllViews();
|
||||
|
||||
//--- MEDIA ATTACHMENT ---
|
||||
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)) {
|
||||
|
||||
|
||||
holder.binding.mediaContainer.removeAllViews();
|
||||
if ((loadMediaType.equals("ASK") || (loadMediaType.equals("WIFI") && !TimelineHelper.isOnWIFI(context))) && !statusToDeal.canLoadMedia) {
|
||||
holder.binding.mediaContainer.setVisibility(View.GONE);
|
||||
holder.binding.displayMedia.setVisibility(View.VISIBLE);
|
||||
|
@ -1455,76 +1477,75 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
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.media1Container.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media2Container.setVisibility(View.GONE);
|
||||
holder.binding.media.media3Container.setVisibility(View.GONE);
|
||||
holder.binding.media.media4Container.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.media1Container.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media2Container.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media3Container.setVisibility(View.GONE);
|
||||
holder.binding.media.media4Container.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.media1Container.setVisibility(View.VISIBLE);
|
||||
if (statusToDeal.media_attachments.get(0).meta != null && statusToDeal.media_attachments.get(0).meta.small != null && statusToDeal.media_attachments.get(0).meta.small.width < statusToDeal.media_attachments.get(0).meta.small.height) {
|
||||
ConstraintSet constraintSet = new ConstraintSet();
|
||||
constraintSet.clone(holder.binding.media.mediaContainer);
|
||||
constraintSet.connect(holder.binding.media.media4Container.getRoot().getId(), ConstraintSet.START, holder.binding.media.media1Container.getRoot().getId(), ConstraintSet.END);
|
||||
constraintSet.connect(holder.binding.media.media4Container.getRoot().getId(), ConstraintSet.TOP, holder.binding.media.media2Container.getRoot().getId(), ConstraintSet.BOTTOM);
|
||||
constraintSet.connect(holder.binding.media.media4Container.getId(), ConstraintSet.START, holder.binding.media.media1Container.getId(), ConstraintSet.END);
|
||||
constraintSet.connect(holder.binding.media.media4Container.getId(), ConstraintSet.TOP, holder.binding.media.media2Container.getId(), ConstraintSet.BOTTOM);
|
||||
constraintSet.applyTo(holder.binding.media.mediaContainer);
|
||||
holder.binding.media.media2Container.mediaRoot.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media3Container.mediaRoot.setVisibility(View.GONE);
|
||||
holder.binding.media.media2Container.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media3Container.setVisibility(View.GONE);
|
||||
} else {
|
||||
ConstraintSet constraintSet = new ConstraintSet();
|
||||
constraintSet.clone(holder.binding.media.mediaContainer);
|
||||
constraintSet.connect(holder.binding.media.media4Container.getRoot().getId(), ConstraintSet.START, holder.binding.media.media3Container.getRoot().getId(), ConstraintSet.END);
|
||||
constraintSet.connect(holder.binding.media.media4Container.getRoot().getId(), ConstraintSet.TOP, holder.binding.media.media1Container.getRoot().getId(), ConstraintSet.BOTTOM);
|
||||
constraintSet.connect(holder.binding.media.media4Container.getId(), ConstraintSet.START, holder.binding.media.media3Container.getId(), ConstraintSet.END);
|
||||
constraintSet.connect(holder.binding.media.media4Container.getId(), ConstraintSet.TOP, holder.binding.media.media1Container.getId(), ConstraintSet.BOTTOM);
|
||||
constraintSet.applyTo(holder.binding.media.mediaContainer);
|
||||
holder.binding.media.media2Container.mediaRoot.setVisibility(View.GONE);
|
||||
holder.binding.media.media3Container.mediaRoot.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media2Container.setVisibility(View.GONE);
|
||||
holder.binding.media.media3Container.setVisibility(View.VISIBLE);
|
||||
}
|
||||
holder.binding.media.media4Container.mediaRoot.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media4Container.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.media1Container.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media2Container.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media3Container.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media4Container.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.media1Container.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media2Container.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media3Container.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media4Container.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.moreMedia.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.moreMedia.setText(context.getString(R.string.more_media, "+" + (statusToDeal.media_attachments.size() - 4)));
|
||||
}
|
||||
}
|
||||
for (Attachment attachment : statusToDeal.media_attachments) {
|
||||
|
||||
LayoutMediaBinding layoutMediaBinding = null;
|
||||
for (Attachment attachment : statusToDeal.media_attachments) {
|
||||
LayoutMediaBinding layoutMediaBinding = LayoutMediaBinding.inflate(LayoutInflater.from(context));
|
||||
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;
|
||||
holder.binding.media.media1Container.addView(layoutMediaBinding.getRoot());
|
||||
} else if (mediaPosition == 2 && statusToDeal.media_attachments.size() == 3) {
|
||||
if (statusToDeal.media_attachments.get(0).meta != null && statusToDeal.media_attachments.get(0).meta.small != null && statusToDeal.media_attachments.get(0).meta.small.width < statusToDeal.media_attachments.get(0).meta.small.height) {
|
||||
layoutMediaBinding = holder.binding.media.media2Container;
|
||||
holder.binding.media.media2Container.addView(layoutMediaBinding.getRoot());
|
||||
} else {
|
||||
layoutMediaBinding = holder.binding.media.media3Container;
|
||||
holder.binding.media.media3Container.addView(layoutMediaBinding.getRoot());
|
||||
}
|
||||
} else if (mediaPosition == 2) {
|
||||
layoutMediaBinding = holder.binding.media.media2Container;
|
||||
holder.binding.media.media2Container.addView(layoutMediaBinding.getRoot());
|
||||
} else if (mediaPosition == 3 && statusToDeal.media_attachments.size() == 3) {
|
||||
layoutMediaBinding = holder.binding.media.media4Container;
|
||||
holder.binding.media.media4Container.addView(layoutMediaBinding.getRoot());
|
||||
} else if (mediaPosition == 3) {
|
||||
layoutMediaBinding = holder.binding.media.media3Container;
|
||||
holder.binding.media.media3Container.addView(layoutMediaBinding.getRoot());
|
||||
} else if (mediaPosition == 4) {
|
||||
layoutMediaBinding = holder.binding.media.media4Container;
|
||||
holder.binding.media.media4Container.addView(layoutMediaBinding.getRoot());
|
||||
}
|
||||
}
|
||||
if (fullAttachement && (!statusToDeal.sensitive || expand_media)) {
|
||||
|
@ -1544,15 +1565,13 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
layoutMediaBinding.media.setVisibility(View.GONE);
|
||||
layoutMediaBinding.mediaVideo.setVisibility(View.VISIBLE);
|
||||
LinearLayout.LayoutParams lp;
|
||||
if (fullAttachement && mediaH > 0 && (!statusToDeal.sensitive || expand_media)) {
|
||||
if (mediaH > 0 && (!statusToDeal.sensitive || expand_media)) {
|
||||
lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (int) (mediaH * ratio));
|
||||
} else {
|
||||
lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
}
|
||||
layoutMediaBinding.mediaVideo.setLayoutParams(lp);
|
||||
|
||||
|
||||
layoutMediaBinding.mediaVideo.onResume();
|
||||
Uri uri = Uri.parse(attachment.url);
|
||||
int video_cache = sharedpreferences.getInt(context.getString(R.string.SET_VIDEO_CACHE), Helper.DEFAULT_VIDEO_CACHE_MB);
|
||||
ProgressiveMediaSource videoSource;
|
||||
|
@ -1572,11 +1591,48 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
player.setMediaSource(videoSource);
|
||||
player.prepare();
|
||||
player.setPlayWhenReady(true);
|
||||
|
||||
int finalMediaPosition = mediaPosition;
|
||||
layoutMediaBinding.mediaVideo.setOnClickListener(v -> {
|
||||
final int timeout = sharedpreferences.getInt(context.getString(R.string.SET_NSFW_TIMEOUT), 5);
|
||||
if (status.sensitive && !expand_media) {
|
||||
status.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() {
|
||||
status.sensitive = true;
|
||||
adapter.notifyItemChanged(position);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
return;
|
||||
}
|
||||
Intent mediaIntent = new Intent(context, MediaActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
b.putInt(Helper.ARG_MEDIA_POSITION, finalMediaPosition);
|
||||
b.putSerializable(Helper.ARG_MEDIA_ARRAY, new ArrayList<>(status.media_attachments));
|
||||
mediaIntent.putExtras(b);
|
||||
ActivityOptionsCompat options = ActivityOptionsCompat
|
||||
.makeSceneTransitionAnimation((Activity) context, layoutMediaBinding.media, status.media_attachments.get(0).url);
|
||||
// start the new activity
|
||||
context.startActivity(mediaIntent, options.toBundle());
|
||||
});
|
||||
layoutMediaBinding.viewHide.setOnClickListener(v -> {
|
||||
status.sensitive = !status.sensitive;
|
||||
adapter.notifyItemChanged(holder.getBindingAdapterPosition());
|
||||
});
|
||||
} else {
|
||||
loadAndAddAttachment(context, layoutMediaBinding, holder, adapter, mediaPosition, mediaW, mediaH, ratio, statusToDeal, attachment);
|
||||
}
|
||||
|
||||
} else if (layoutMediaBinding != null) {
|
||||
} else {
|
||||
layoutMediaBinding.mediaRoot.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
|
||||
if (autoplaygif && attachment.type.equalsIgnoreCase("gifv")) {
|
||||
layoutMediaBinding.media.setVisibility(View.GONE);
|
||||
layoutMediaBinding.mediaVideo.setVisibility(View.VISIBLE);
|
||||
|
@ -1600,7 +1656,41 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
player.setMediaSource(videoSource);
|
||||
player.prepare();
|
||||
player.setPlayWhenReady(true);
|
||||
int finalMediaPosition = mediaPosition;
|
||||
layoutMediaBinding.mediaVideo.setOnClickListener(v -> {
|
||||
final int timeout = sharedpreferences.getInt(context.getString(R.string.SET_NSFW_TIMEOUT), 5);
|
||||
if (status.sensitive && !expand_media) {
|
||||
status.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() {
|
||||
status.sensitive = true;
|
||||
adapter.notifyItemChanged(position);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
return;
|
||||
}
|
||||
Intent mediaIntent = new Intent(context, MediaActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
b.putInt(Helper.ARG_MEDIA_POSITION, finalMediaPosition);
|
||||
b.putSerializable(Helper.ARG_MEDIA_ARRAY, new ArrayList<>(status.media_attachments));
|
||||
mediaIntent.putExtras(b);
|
||||
ActivityOptionsCompat options = ActivityOptionsCompat
|
||||
.makeSceneTransitionAnimation((Activity) context, layoutMediaBinding.media, status.media_attachments.get(0).url);
|
||||
// start the new activity
|
||||
context.startActivity(mediaIntent, options.toBundle());
|
||||
});
|
||||
layoutMediaBinding.viewHide.setOnClickListener(v -> {
|
||||
status.sensitive = !status.sensitive;
|
||||
adapter.notifyItemChanged(holder.getBindingAdapterPosition());
|
||||
});
|
||||
} else {
|
||||
loadAndAddAttachment(context, layoutMediaBinding, holder, adapter, mediaPosition, -1.f, -1.f, -1.f, statusToDeal, attachment);
|
||||
}
|
||||
|
@ -2465,6 +2555,10 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
layoutMediaBinding.media.setVisibility(View.VISIBLE);
|
||||
layoutMediaBinding.mediaVideo.setVisibility(View.GONE);
|
||||
layoutMediaBinding.mediaVideo.onPause();
|
||||
Player player = layoutMediaBinding.mediaVideo.getPlayer();
|
||||
if (player != null) {
|
||||
player.release();
|
||||
}
|
||||
layoutMediaBinding.media.setLayoutParams(lp);
|
||||
|
||||
float focusX = 0.f;
|
||||
|
|
|
@ -24,6 +24,7 @@ import android.content.SharedPreferences;
|
|||
import android.graphics.PorterDuff;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.text.SpannableString;
|
||||
|
@ -36,6 +37,7 @@ import android.widget.CheckBox;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -50,6 +52,13 @@ import androidx.preference.PreferenceManager;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.RequestBuilder;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.MediaItem;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
|
||||
import com.google.android.exoplayer2.ui.PlayerView;
|
||||
import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import com.google.android.exoplayer2.upstream.DefaultDataSource;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -68,6 +77,7 @@ import app.fedilab.android.mastodon.activities.MediaActivity;
|
|||
import app.fedilab.android.mastodon.client.entities.api.Attachment;
|
||||
import app.fedilab.android.mastodon.client.entities.api.Poll;
|
||||
import app.fedilab.android.mastodon.client.entities.api.Status;
|
||||
import app.fedilab.android.mastodon.helper.CacheDataSourceFactory;
|
||||
import app.fedilab.android.mastodon.helper.Helper;
|
||||
import app.fedilab.android.mastodon.helper.LongClickLinkMovementMethod;
|
||||
import app.fedilab.android.mastodon.helper.MastodonHelper;
|
||||
|
@ -109,7 +119,13 @@ public class StatusDirectMessageAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||
layoutMediaBinding.media.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
|
||||
layoutMediaBinding.media.setLayoutParams(lp);
|
||||
|
||||
layoutMediaBinding.media.setVisibility(View.VISIBLE);
|
||||
layoutMediaBinding.mediaVideo.setVisibility(View.GONE);
|
||||
layoutMediaBinding.mediaVideo.onPause();
|
||||
Player player = layoutMediaBinding.mediaVideo.getPlayer();
|
||||
if (player != null) {
|
||||
player.release();
|
||||
}
|
||||
float focusX = 0.f;
|
||||
float focusY = 0.f;
|
||||
if (status.media_attachments.get(0).meta != null && status.media_attachments.get(0).meta.focus != null) {
|
||||
|
@ -148,6 +164,7 @@ public class StatusDirectMessageAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||
layoutMediaBinding.viewDescription.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
||||
RequestBuilder<Drawable> requestBuilder = prepareRequestBuilder(context, attachment, mediaW * ratio, mediaH * ratio, focusX, focusY, status.sensitive, false);
|
||||
if (!status.sensitive || expand_media) {
|
||||
layoutMediaBinding.viewHide.setImageResource(R.drawable.ic_baseline_visibility_24);
|
||||
|
@ -482,72 +499,152 @@ public class StatusDirectMessageAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||
LinearLayoutCompat.LayoutParams lp = new LinearLayoutCompat.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.media1Container.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media2Container.setVisibility(View.GONE);
|
||||
holder.binding.media.media3Container.setVisibility(View.GONE);
|
||||
holder.binding.media.media4Container.setVisibility(View.GONE);
|
||||
holder.binding.media.moreMedia.setVisibility(View.GONE);
|
||||
} 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.media1Container.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media2Container.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media3Container.setVisibility(View.GONE);
|
||||
holder.binding.media.media4Container.setVisibility(View.GONE);
|
||||
holder.binding.media.moreMedia.setVisibility(View.GONE);
|
||||
} else if (status.media_attachments.size() == 3) {
|
||||
holder.binding.media.media1Container.mediaRoot.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media1Container.setVisibility(View.VISIBLE);
|
||||
if (status.media_attachments.get(0).meta != null && status.media_attachments.get(0).meta.small.width < status.media_attachments.get(0).meta.small.height) {
|
||||
ConstraintSet constraintSet = new ConstraintSet();
|
||||
constraintSet.clone(holder.binding.media.mediaContainer);
|
||||
constraintSet.connect(holder.binding.media.media4Container.getRoot().getId(), ConstraintSet.START, holder.binding.media.media1Container.getRoot().getId(), ConstraintSet.END);
|
||||
constraintSet.connect(holder.binding.media.media4Container.getRoot().getId(), ConstraintSet.TOP, holder.binding.media.media2Container.getRoot().getId(), ConstraintSet.BOTTOM);
|
||||
constraintSet.connect(holder.binding.media.media4Container.getId(), ConstraintSet.START, holder.binding.media.media1Container.getId(), ConstraintSet.END);
|
||||
constraintSet.connect(holder.binding.media.media4Container.getId(), ConstraintSet.TOP, holder.binding.media.media2Container.getId(), ConstraintSet.BOTTOM);
|
||||
constraintSet.applyTo(holder.binding.media.mediaContainer);
|
||||
holder.binding.media.media2Container.mediaRoot.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media3Container.mediaRoot.setVisibility(View.GONE);
|
||||
holder.binding.media.media2Container.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media3Container.setVisibility(View.GONE);
|
||||
} else {
|
||||
ConstraintSet constraintSet = new ConstraintSet();
|
||||
constraintSet.clone(holder.binding.media.mediaContainer);
|
||||
constraintSet.connect(holder.binding.media.media4Container.getRoot().getId(), ConstraintSet.START, holder.binding.media.media3Container.getRoot().getId(), ConstraintSet.END);
|
||||
constraintSet.connect(holder.binding.media.media4Container.getRoot().getId(), ConstraintSet.TOP, holder.binding.media.media1Container.getRoot().getId(), ConstraintSet.BOTTOM);
|
||||
constraintSet.connect(holder.binding.media.media4Container.getId(), ConstraintSet.START, holder.binding.media.media3Container.getId(), ConstraintSet.END);
|
||||
constraintSet.connect(holder.binding.media.media4Container.getId(), ConstraintSet.TOP, holder.binding.media.media1Container.getId(), ConstraintSet.BOTTOM);
|
||||
constraintSet.applyTo(holder.binding.media.mediaContainer);
|
||||
holder.binding.media.media2Container.mediaRoot.setVisibility(View.GONE);
|
||||
holder.binding.media.media3Container.mediaRoot.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media2Container.setVisibility(View.GONE);
|
||||
holder.binding.media.media3Container.setVisibility(View.VISIBLE);
|
||||
}
|
||||
holder.binding.media.media4Container.mediaRoot.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media4Container.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.media1Container.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media2Container.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media3Container.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media4Container.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.media1Container.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media2Container.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media3Container.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.media4Container.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.moreMedia.setVisibility(View.VISIBLE);
|
||||
holder.binding.media.moreMedia.setText(context.getString(R.string.more_media, "+" + (status.media_attachments.size() - 4)));
|
||||
}
|
||||
PlayerView video = holder.binding.media.media1Container.findViewById(R.id.media_video);
|
||||
if (video != null && video.getPlayer() != null) {
|
||||
video.getPlayer().release();
|
||||
}
|
||||
holder.binding.media.media1Container.removeAllViews();
|
||||
video = holder.binding.media.media2Container.findViewById(R.id.media_video);
|
||||
if (video != null && video.getPlayer() != null) {
|
||||
video.getPlayer().release();
|
||||
}
|
||||
holder.binding.media.media2Container.removeAllViews();
|
||||
video = holder.binding.media.media3Container.findViewById(R.id.media_video);
|
||||
if (video != null && video.getPlayer() != null) {
|
||||
video.getPlayer().release();
|
||||
}
|
||||
holder.binding.media.media3Container.removeAllViews();
|
||||
video = holder.binding.media.media4Container.findViewById(R.id.media_video);
|
||||
if (video != null && video.getPlayer() != null) {
|
||||
video.getPlayer().release();
|
||||
}
|
||||
holder.binding.media.media4Container.removeAllViews();
|
||||
boolean autoplaygif = sharedpreferences.getBoolean(context.getString(R.string.SET_AUTO_PLAY_GIG_MEDIA), true);
|
||||
for (Attachment attachment : status.media_attachments) {
|
||||
LayoutMediaBinding layoutMediaBinding = null;
|
||||
LayoutMediaBinding layoutMediaBinding = LayoutMediaBinding.inflate(LayoutInflater.from(context));
|
||||
layoutMediaBinding.mediaRoot.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
|
||||
if (mediaPosition == 1) {
|
||||
layoutMediaBinding = holder.binding.media.media1Container;
|
||||
holder.binding.media.media1Container.addView(layoutMediaBinding.getRoot());
|
||||
} else if (mediaPosition == 2 && status.media_attachments.size() == 3) {
|
||||
if (status.media_attachments.get(0).meta != null && status.media_attachments.get(0).meta.small.width < status.media_attachments.get(0).meta.small.height) {
|
||||
layoutMediaBinding = holder.binding.media.media2Container;
|
||||
holder.binding.media.media2Container.addView(layoutMediaBinding.getRoot());
|
||||
} else {
|
||||
layoutMediaBinding = holder.binding.media.media3Container;
|
||||
holder.binding.media.media3Container.addView(layoutMediaBinding.getRoot());
|
||||
}
|
||||
} else if (mediaPosition == 2) {
|
||||
layoutMediaBinding = holder.binding.media.media2Container;
|
||||
holder.binding.media.media2Container.addView(layoutMediaBinding.getRoot());
|
||||
} else if (mediaPosition == 3 && status.media_attachments.size() == 3) {
|
||||
layoutMediaBinding = holder.binding.media.media4Container;
|
||||
holder.binding.media.media4Container.addView(layoutMediaBinding.getRoot());
|
||||
} else if (mediaPosition == 3) {
|
||||
layoutMediaBinding = holder.binding.media.media3Container;
|
||||
holder.binding.media.media3Container.addView(layoutMediaBinding.getRoot());
|
||||
} else if (mediaPosition == 4) {
|
||||
layoutMediaBinding = holder.binding.media.media4Container;
|
||||
holder.binding.media.media4Container.addView(layoutMediaBinding.getRoot());
|
||||
}
|
||||
if (layoutMediaBinding != null) {
|
||||
boolean expand_media = sharedpreferences.getBoolean(context.getString(R.string.SET_EXPAND_MEDIA), false);
|
||||
if (autoplaygif && attachment.type.equalsIgnoreCase("gifv")) {
|
||||
layoutMediaBinding.media.setVisibility(View.GONE);
|
||||
layoutMediaBinding.mediaVideo.setVisibility(View.VISIBLE);
|
||||
layoutMediaBinding.mediaVideo.onResume();
|
||||
Uri uri = Uri.parse(attachment.url);
|
||||
int video_cache = sharedpreferences.getInt(context.getString(R.string.SET_VIDEO_CACHE), Helper.DEFAULT_VIDEO_CACHE_MB);
|
||||
ProgressiveMediaSource videoSource;
|
||||
MediaItem mediaItem = new MediaItem.Builder().setUri(uri).build();
|
||||
if (video_cache == 0) {
|
||||
DataSource.Factory dataSourceFactory = new DefaultDataSource.Factory(context);
|
||||
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
|
||||
.createMediaSource(mediaItem);
|
||||
} else {
|
||||
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(context);
|
||||
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
|
||||
.createMediaSource(mediaItem);
|
||||
}
|
||||
ExoPlayer player = new ExoPlayer.Builder(context).build();
|
||||
player.setRepeatMode(Player.REPEAT_MODE_ONE);
|
||||
layoutMediaBinding.mediaVideo.setPlayer(player);
|
||||
player.setMediaSource(videoSource);
|
||||
player.prepare();
|
||||
player.setPlayWhenReady(true);
|
||||
int finalMediaPosition = mediaPosition;
|
||||
layoutMediaBinding.mediaVideo.setOnClickListener(v -> {
|
||||
final int timeout = sharedpreferences.getInt(context.getString(R.string.SET_NSFW_TIMEOUT), 5);
|
||||
if (status.sensitive && !expand_media) {
|
||||
status.sensitive = false;
|
||||
int positionAP = holder.getBindingAdapterPosition();
|
||||
notifyItemChanged(positionAP);
|
||||
if (timeout > 0) {
|
||||
new CountDownTimer((timeout * 1000L), 1000) {
|
||||
public void onTick(long millisUntilFinished) {
|
||||
}
|
||||
|
||||
public void onFinish() {
|
||||
status.sensitive = true;
|
||||
notifyItemChanged(positionAP);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
return;
|
||||
}
|
||||
Intent mediaIntent = new Intent(context, MediaActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
b.putInt(Helper.ARG_MEDIA_POSITION, finalMediaPosition);
|
||||
b.putSerializable(Helper.ARG_MEDIA_ARRAY, new ArrayList<>(status.media_attachments));
|
||||
mediaIntent.putExtras(b);
|
||||
ActivityOptionsCompat options = ActivityOptionsCompat
|
||||
.makeSceneTransitionAnimation((Activity) context, layoutMediaBinding.media, status.media_attachments.get(0).url);
|
||||
// start the new activity
|
||||
context.startActivity(mediaIntent, options.toBundle());
|
||||
});
|
||||
layoutMediaBinding.viewHide.setOnClickListener(v -> {
|
||||
status.sensitive = !status.sensitive;
|
||||
notifyItemChanged(holder.getBindingAdapterPosition());
|
||||
});
|
||||
} else {
|
||||
loadAndAddAttachment(context, layoutMediaBinding, holder, this, mediaPosition, -1.f, -1.f, -1.f, status, attachment);
|
||||
}
|
||||
mediaPosition++;
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
android:id="@+id/media_container"
|
||||
android:layout_height="300dp">
|
||||
|
||||
<include
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/media1_container"
|
||||
layout="@layout/layout_media"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_margin="1dp"
|
||||
|
@ -17,9 +17,8 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<include
|
||||
<RelativeLayout
|
||||
android:id="@+id/media2_container"
|
||||
layout="@layout/layout_media"
|
||||
android:layout_width="0dp"
|
||||
android:layout_margin="1dp"
|
||||
android:layout_height="0dp"
|
||||
|
@ -30,9 +29,8 @@
|
|||
app:layout_constraintStart_toEndOf="@id/media1_container"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<include
|
||||
<RelativeLayout
|
||||
android:id="@+id/media3_container"
|
||||
layout="@layout/layout_media"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_margin="1dp"
|
||||
|
@ -44,9 +42,8 @@
|
|||
app:layout_constraintTop_toBottomOf="@+id/media1_container" />
|
||||
|
||||
|
||||
<include
|
||||
<RelativeLayout
|
||||
android:id="@+id/media4_container"
|
||||
layout="@layout/layout_media"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_margin="1dp"
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
<com.google.android.exoplayer2.ui.PlayerView
|
||||
android:id="@+id/media_video"
|
||||
app:shutter_background_color="@color/transparent"
|
||||
app:surface_type="texture_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_centerInParent="true"
|
||||
|
|
Loading…
Reference in a new issue