video card: playback preview: upd 5

This commit is contained in:
Yuriy Liskov
2025-05-16 13:18:23 +03:00
parent a06eb90600
commit 98bc8e959c
6 changed files with 36 additions and 36 deletions

View File

@ -110,12 +110,12 @@ public class MainUISettingsPresenter extends BasePresenter<Void> {
List<OptionItem> options = new ArrayList<>();
for (int[] pair : new int[][] {
{R.string.option_disabled, MainUIData.ANIMATED_PREVIEW_DISABLED},
{R.string.card_preview_muted, MainUIData.ANIMATED_PREVIEW_MUTED},
{R.string.card_preview_full, MainUIData.ANIMATED_PREVIEW_FULL}}) {
{R.string.option_disabled, MainUIData.CARD_PREVIEW_DISABLED},
{R.string.card_preview_muted, MainUIData.CARD_PREVIEW_MUTED},
{R.string.card_preview_full, MainUIData.CARD_PREVIEW_FULL}}) {
options.add(UiOptionItem.from(getContext().getString(pair[0]), optionItem -> {
mMainUIData.setAnimatedPreviewType(pair[1]);
}, mMainUIData.getAnimatedPreviewType() == pair[1]));
mMainUIData.setCardPreviewType(pair[1]);
}, mMainUIData.getCardPreviewType() == pair[1]));
}
settingsPresenter.appendRadioCategory(getContext().getString(R.string.card_preview), options);

View File

@ -3,6 +3,8 @@ package com.liskovsoft.smartyoutubetv2.common.prefs;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.os.Build.VERSION;
import com.liskovsoft.sharedutils.helpers.Helpers;
import com.liskovsoft.smartyoutubetv2.common.R;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.providers.ContextMenuManager;
@ -17,9 +19,9 @@ import java.util.List;
public class MainUIData extends DataChangeBase implements ProfileChangeListener {
private static final String MAIN_UI_DATA = "main_ui_data2";
public static final int ANIMATED_PREVIEW_DISABLED = 0;
public static final int ANIMATED_PREVIEW_MUTED = 1;
public static final int ANIMATED_PREVIEW_FULL = 2;
public static final int CARD_PREVIEW_DISABLED = 0;
public static final int CARD_PREVIEW_MUTED = 1;
public static final int CARD_PREVIEW_FULL = 2;
public static final int CHANNEL_SORTING_NEW_CONTENT = 0;
public static final int CHANNEL_SORTING_NAME = 1;
public static final int CHANNEL_SORTING_DEFAULT = 2;
@ -84,7 +86,6 @@ public class MainUIData extends DataChangeBase implements ProfileChangeListener
private static MainUIData sInstance;
private final Context mContext;
private final AppPrefs mPrefs;
private boolean mIsCardAnimatedPreviewsEnabled;
private boolean mIsCardMultilineTitleEnabled;
private boolean mIsCardMultilineSubtitleEnabled;
private boolean mIsCardTextAutoScrollEnabled;
@ -105,7 +106,7 @@ public class MainUIData extends DataChangeBase implements ProfileChangeListener
private boolean mIsChannelsFilterEnabled;
private boolean mIsChannelSearchBarEnabled;
private boolean mIsPinnedChannelRowsEnabled;
private int mAnimatedPreviewType;
private int mCardPreviewType;
private MainUIData(Context context) {
mContext = context;
@ -123,15 +124,6 @@ public class MainUIData extends DataChangeBase implements ProfileChangeListener
return sInstance;
}
public void enableCardAnimatedPreviews(boolean enable) {
mIsCardAnimatedPreviewsEnabled = enable;
persistState();
}
public boolean isCardAnimatedPreviewsEnabled() {
return mIsCardAnimatedPreviewsEnabled;
}
public void enableCardMultilineTitle(boolean enable) {
mIsCardMultilineTitleEnabled = enable;
persistState();
@ -337,12 +329,12 @@ public class MainUIData extends DataChangeBase implements ProfileChangeListener
return (mTopButtons & button) == button;
}
public int getAnimatedPreviewType() {
return mAnimatedPreviewType;
public int getCardPreviewType() {
return mCardPreviewType;
}
public void setAnimatedPreviewType(int type) {
mAnimatedPreviewType = type;
public void setCardPreviewType(int type) {
mCardPreviewType = type;
persistState();
}
@ -396,7 +388,7 @@ public class MainUIData extends DataChangeBase implements ProfileChangeListener
String[] split = Helpers.splitData(data);
mIsCardAnimatedPreviewsEnabled = Helpers.parseBoolean(split, 0, true);
//mIsCardAnimatedPreviewsEnabled = Helpers.parseBoolean(split, 0, true);
mVideoGridScale = Helpers.parseFloat(split, 1, 1.0f); // 4 cards in a row
mUIScale = Helpers.parseFloat(split, 2, 1.0f);
mColorSchemeIndex = Helpers.parseInt(split, 3, 1);
@ -417,7 +409,7 @@ public class MainUIData extends DataChangeBase implements ProfileChangeListener
mIsChannelsFilterEnabled = Helpers.parseBoolean(split, 18, true);
mIsChannelSearchBarEnabled = Helpers.parseBoolean(split, 19, true);
mIsPinnedChannelRowsEnabled = Helpers.parseBoolean(split, 20, true);
mAnimatedPreviewType = Helpers.parseInt(split, 21, ANIMATED_PREVIEW_FULL);
mCardPreviewType = Helpers.parseInt(split, 21, VERSION.SDK_INT > 19 ? CARD_PREVIEW_FULL : CARD_PREVIEW_DISABLED);
for (Long menuItem : MENU_ITEM_DEFAULT_ORDER) {
if (!mMenuItemsOrdered.contains(menuItem)) {
@ -435,12 +427,12 @@ public class MainUIData extends DataChangeBase implements ProfileChangeListener
}
private void persistState() {
mPrefs.setProfileData(MAIN_UI_DATA, Helpers.mergeData(mIsCardAnimatedPreviewsEnabled,
mPrefs.setProfileData(MAIN_UI_DATA, Helpers.mergeData(null,
mVideoGridScale, mUIScale, mColorSchemeIndex, mIsCardMultilineTitleEnabled,
mChannelCategorySorting, mPlaylistsStyle, mCardTitleLinesNum, mIsCardTextAutoScrollEnabled,
mIsUploadsOldLookEnabled, mIsUploadsAutoLoadEnabled, mCardTextScrollSpeed, mMenuItems, mTopButtons,
null, mThumbQuality, mIsCardMultilineSubtitleEnabled, Helpers.mergeList(mMenuItemsOrdered),
mIsChannelsFilterEnabled, mIsChannelSearchBarEnabled, mIsPinnedChannelRowsEnabled, mAnimatedPreviewType));
mIsChannelsFilterEnabled, mIsChannelSearchBarEnabled, mIsPinnedChannelRowsEnabled, mCardPreviewType));
onDataChange();
}

View File

@ -38,7 +38,7 @@ public class VideoCardPresenter extends LongClickPresenter {
private int mDefaultTextColor = -1;
private int mSelectedBackgroundColor = -1;
private int mSelectedTextColor = -1;
private boolean mIsAnimatedPreviewsEnabled;
private int mCardPreviewType;
private int mThumbQuality;
private int mWidth;
private int mHeight;
@ -56,7 +56,7 @@ public class VideoCardPresenter extends LongClickPresenter {
mSelectedTextColor =
ContextCompat.getColor(context, R.color.card_selected_text_grey);
mIsAnimatedPreviewsEnabled = isCardAnimatedPreviewsEnabled(context);
mCardPreviewType = getCardPreviewType(context);
mThumbQuality = getThumbQuality(context);
boolean isCardMultilineTitleEnabled = isCardMultilineTitleEnabled(context);
@ -131,8 +131,9 @@ public class VideoCardPresenter extends LongClickPresenter {
cardView.setBadgeColor(video.hasNewContent || video.isLive || video.isUpcoming ?
ContextCompat.getColor(context, R.color.dark_red) : ContextCompat.getColor(context, R.color.black));
if (mIsAnimatedPreviewsEnabled) {
if (mCardPreviewType != MainUIData.CARD_PREVIEW_DISABLED) {
cardView.setPreview(video);
cardView.setMute(mCardPreviewType == MainUIData.CARD_PREVIEW_MUTED);
}
cardView.setMainImageDimensions(mWidth, mHeight);
@ -189,8 +190,8 @@ public class VideoCardPresenter extends LongClickPresenter {
return MainUIData.instance(context).isCardTextAutoScrollEnabled();
}
protected boolean isCardAnimatedPreviewsEnabled(Context context) {
return MainUIData.instance(context).isCardAnimatedPreviewsEnabled();
protected int getCardPreviewType(Context context) {
return MainUIData.instance(context).getCardPreviewType();
}
protected boolean isCardMultilineTitleEnabled(Context context) {

View File

@ -4,7 +4,6 @@ import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView.ScaleType;
import android.widget.TextView;
import androidx.leanback.widget.ImageCardView;
@ -115,6 +114,10 @@ public class ComplexImageCardView extends ImageCardView {
mComplexImageView.setPreview(video);
}
public void setMute(boolean muted) {
mComplexImageView.setMute(muted);
}
public void setTitleLinesNum(int lines) {
TextView titleView = findViewById(R.id.title_text);

View File

@ -33,6 +33,7 @@ public class ComplexImageView extends RelativeLayout {
private Runnable mCreateAndStartPlayer;
private WeakReference<Video> mVideo;
private boolean mPreferSimplePreview;
private boolean mMute;
public ComplexImageView(Context context) {
super(context);
@ -123,6 +124,10 @@ public class ComplexImageView extends RelativeLayout {
}
}
public void setMute(boolean mute) {
mMute = mute;
}
public void startPlayback() {
if (getVideo() == null) {
return;
@ -159,7 +164,7 @@ public class ComplexImageView extends RelativeLayout {
mPreviewPlayer = new EmbedPlayerView(getContext());
mPreviewPlayer.setQuality(Math.min(mPreviewWidth, mPreviewHeight) < 300 ? EmbedPlayerView.QUALITY_LOW : EmbedPlayerView.QUALITY_NORMAL);
mPreviewPlayer.setUseController(false);
//mPreviewPlayer.setMute(true);
mPreviewPlayer.setMute(mMute);
mPreviewContainer.addView(mPreviewPlayer, new FrameLayout.LayoutParams(mPreviewWidth, mPreviewHeight));
mPreviewContainer.setVisibility(View.VISIBLE);
}

View File

@ -550,9 +550,8 @@ public class EmbedPlayerView extends PlayerView implements PlaybackView {
if (isEngineInitialized()) {
Utils.removeCallbacks(mShowView);
// Don't replace main player!
if (mPlaybackPresenter.getView() == this) {
if (mPlaybackPresenter.getView() == null || mPlaybackPresenter.getView() == this) {
mPlaybackPresenter.onEngineReleased();
mPlaybackPresenter.setView(null);
}
mExoPlayerController.setOnVideoLoaded(null);
// Fix access calls when player isn't initialized