From 481d3c3768bc59780750a5364e5d215c82d031e2 Mon Sep 17 00:00:00 2001 From: "Wei.Liu" <141914274+WeiLiuSH@users.noreply.github.com> Date: Tue, 17 Dec 2024 19:21:13 +0800 Subject: [PATCH] Fix/doris 2687 player translation (#394) * bump doris-android to 3.11.18 * bump doris-android to 3.11.18, optimize player translation code, delete useless file --- .../com/brentvatne/entity/RNTranslations.java | 213 ------------------ .../exoplayer/ReactTVExoplayerView.java | 58 ++--- .../ReactTVExoplayerViewManager.java | 4 +- .../translations/DiceLocalizedStrings.java | 63 ------ package.json | 6 +- 5 files changed, 21 insertions(+), 323 deletions(-) delete mode 100644 android-exoplayer/src/main/java/com/brentvatne/entity/RNTranslations.java delete mode 100644 android-exoplayer/src/main/java/com/imggaming/translations/DiceLocalizedStrings.java diff --git a/android-exoplayer/src/main/java/com/brentvatne/entity/RNTranslations.java b/android-exoplayer/src/main/java/com/brentvatne/entity/RNTranslations.java deleted file mode 100644 index 54af122435..0000000000 --- a/android-exoplayer/src/main/java/com/brentvatne/entity/RNTranslations.java +++ /dev/null @@ -1,213 +0,0 @@ -package com.brentvatne.entity; - -import androidx.annotation.NonNull; - -import java.util.Map; - -public class RNTranslations { - - private static final String KEY_EPG_LABEL = "tvPlayerEPG"; - private static final String KEY_STATS_LABEL = "player_stats_button"; - private static final String KEY_PLAY_LABEL = "player_play_button"; - private static final String KEY_PAUSE_LABEL = "player_pause_button"; - private static final String KEY_LIVE_LABEL = "goLive"; - private static final String KEY_FAVORITE_LABEL = "favourite"; - private static final String KEY_WATCHLIST_LABEL = "addToWatchlist"; - private static final String KEY_MORE_VIDEOS_LABEL = "moreVideos"; - private static final String KEY_CAPTIONS_LABEL = "captions"; - private static final String KEY_REWIND_LABEL = "rewind"; - private static final String KEY_FAST_FORWARD_LABEL = "fastForward"; - private static final String KEY_AUDIO_TRACKS_LABEL = "audioTracks"; - private static final String KEY_INFO_LABEL = "info"; - private static final String KEY_ANNOTATIONS_LABEL = "annotations"; - private static final String KEY_LEARN_MORE_LABEL = "learnMore"; - private static final String KEY_ADS_COUNTDOWN_AD_LABEL = "adsCountdownAd"; - private static final String KEY_ADS_COUNTDOWN_OF_LABEL = "adsCountdownOf"; - private static final String KEY_SKIP_COUNTDOWN_LABEL = "skipAdIn"; - private static final String KEY_SKIP_LABEL = "skipAd"; - private static final String KEY_PLAYING_LIVE = "playingLive"; - private static final String KEY_NOW_PLAYING = "nowPlaying"; - private static final String KEY_AUDIO_AND_SUBTITLES_LABEL = "player_audio_and_subtitles_button"; - private static final String KEY_SKIP_INTRO = "skipIntro"; - private static final String KEY_SKIP_CREDITS = "skipCredits"; - - private static final String DEFAULT_EPG_LABEL = "Schedule"; - private static final String DEFAULT_STATS_LABEL = "Stats"; - private static final String DEFAULT_PLAY_LABEL = "Play"; - private static final String DEFAULT_PAUSE_LABEL = "Pause"; - private static final String DEFAULT_LIVE_LABEL = "Go Live"; - private static final String DEFAULT_FAVORITE_LABEL = "Favourite"; - private static final String DEFAULT_MORE_VIDEOS_LABEL = "More Videos"; - private static final String DEFAULT_WATCHLIST_LABEL = "Add to watchlist"; - private static final String DEFAULT_CAPTIONS_LABEL = "Subtitles"; - private static final String DEFAULT_REWIND_LABEL = "Rewind"; - private static final String DEFAULT_FAST_FORWARD_LABEL = "Fast Forward"; - private static final String DEFAULT_AUDIO_TRACKS_LABEL = "Audio Languages"; - private static final String DEFAULT_INFO_LABEL = "Information"; - private static final String DEFAULT_ANNOTATIONS_LABEL = "Annotations"; - private static final String DEFAULT_LEARN_MORE_LABEL = "More Info"; - private static final String DEFAULT_ADS_COUNTDOWN_AD_LABEL = "Ad"; - private static final String DEFAULT_ADS_COUNTDOWN_OF_LABEL = "Of"; - private static final String DEFAULT_SKIP_COUNTDOWN_LABEL = "Skip in"; - private static final String DEFAULT_SKIP_LABEL = "Skip Ad"; - private static final String DEFAULT_PLAYING_LIVE = "Playing Live"; - private static final String DEFAULT_NOW_PLAYING = "Now Playing"; - private static final String DEFAULT_AUDIO_AND_SUBTITLES = "Audio & Subtitles"; - private static final String DEFAULT_SKIP_INTRO = "Skip Intro"; - private static final String DEFAULT_SKIP_CREDITS = "Skip Credit"; - - private final Map translations; - private final String epgLabel; - private final String statsLabel; - private final String playLabel; - private final String pauseLabel; - private final String liveLabel; - private final String favoriteLabel; - private final String watchlistLabel; - private final String moreVideosLabel; - private final String captionsLabel; - private final String rewindLabel; - private final String fastForwardLabel; - private final String audioTracksLabel; - private final String infoLabel; - private final String annotationsLabel; - private final String learnMoreLabel; - private final String adsCountdownAdLabel; - private final String adsCountdownOfLabel; - private final String skipCountdownLabel; - private final String skipLabel; - private final String playingLiveLabel; - private final String nowPlayingLabel; - private final String audioAndSubtitlesLabel; - private final String skipIntro; - private final String skipCredits; - - public RNTranslations(@NonNull Map translations) { - this.translations = translations; - - this.epgLabel = getStringFromMap(KEY_EPG_LABEL, DEFAULT_EPG_LABEL); - this.statsLabel = getStringFromMap(KEY_STATS_LABEL, DEFAULT_STATS_LABEL); - this.playLabel = getStringFromMap(KEY_PLAY_LABEL, DEFAULT_PLAY_LABEL); - this.pauseLabel = getStringFromMap(KEY_PAUSE_LABEL, DEFAULT_PAUSE_LABEL); - this.liveLabel = getStringFromMap(KEY_LIVE_LABEL, DEFAULT_LIVE_LABEL); - this.favoriteLabel = getStringFromMap(KEY_FAVORITE_LABEL, DEFAULT_FAVORITE_LABEL); - this.watchlistLabel = getStringFromMap(KEY_WATCHLIST_LABEL, DEFAULT_WATCHLIST_LABEL); - this.moreVideosLabel = getStringFromMap(KEY_MORE_VIDEOS_LABEL, DEFAULT_MORE_VIDEOS_LABEL); - this.captionsLabel = getStringFromMap(KEY_CAPTIONS_LABEL, DEFAULT_CAPTIONS_LABEL); - this.rewindLabel = getStringFromMap(KEY_REWIND_LABEL, DEFAULT_REWIND_LABEL); - this.fastForwardLabel = getStringFromMap(KEY_FAST_FORWARD_LABEL, DEFAULT_FAST_FORWARD_LABEL); - this.audioTracksLabel = getStringFromMap(KEY_AUDIO_TRACKS_LABEL, DEFAULT_AUDIO_TRACKS_LABEL); - this.infoLabel = getStringFromMap(KEY_INFO_LABEL, DEFAULT_INFO_LABEL); - this.annotationsLabel = getStringFromMap(KEY_ANNOTATIONS_LABEL, DEFAULT_ANNOTATIONS_LABEL); - this.learnMoreLabel = getStringFromMap(KEY_LEARN_MORE_LABEL, DEFAULT_LEARN_MORE_LABEL); - this.adsCountdownAdLabel = getStringFromMap(KEY_ADS_COUNTDOWN_AD_LABEL, DEFAULT_ADS_COUNTDOWN_AD_LABEL); - this.adsCountdownOfLabel = getStringFromMap(KEY_ADS_COUNTDOWN_OF_LABEL, DEFAULT_ADS_COUNTDOWN_OF_LABEL); - this.skipCountdownLabel = getStringFromMap(KEY_SKIP_COUNTDOWN_LABEL, DEFAULT_SKIP_COUNTDOWN_LABEL); - this.skipLabel = getStringFromMap(KEY_SKIP_LABEL, DEFAULT_SKIP_LABEL); - this.playingLiveLabel = getStringFromMap(KEY_PLAYING_LIVE, DEFAULT_PLAYING_LIVE); - this.nowPlayingLabel = getStringFromMap(KEY_NOW_PLAYING, DEFAULT_NOW_PLAYING); - this.audioAndSubtitlesLabel = getStringFromMap(KEY_AUDIO_AND_SUBTITLES_LABEL, DEFAULT_AUDIO_AND_SUBTITLES); - this.skipIntro = getStringFromMap(KEY_SKIP_INTRO, DEFAULT_SKIP_INTRO); - this.skipCredits = getStringFromMap(KEY_SKIP_CREDITS, DEFAULT_SKIP_CREDITS); - } - - private String getStringFromMap(String key, String defaultValue) { - return translations.get(key) != null ? (String) translations.get(key) : defaultValue; - } - - public String getEpgLabel() { - return epgLabel; - } - - public String getStatsLabel() { - return statsLabel; - } - - public String getPlayLabel() { - return playLabel; - } - - public String getPauseLabel() { - return pauseLabel; - } - - public String getLiveLabel() { - return liveLabel; - } - - public String getFavoriteLabel() { - return favoriteLabel; - } - - public String getWatchlistLabel() { - return watchlistLabel; - } - - public String getMoreVideosLabel() { - return moreVideosLabel; - } - - public String getCaptionsLabel() { - return captionsLabel; - } - - public String getRewindLabel() { - return rewindLabel; - } - - public String getFastForwardLabel() { - return fastForwardLabel; - } - - public String getAudioTracksLabel() { - return audioTracksLabel; - } - - public String getInfoLabel() { - return infoLabel; - } - - public String getAnnotationsLabel() { - return annotationsLabel; - } - - public String getLearnMoreLabel() { - return learnMoreLabel; - } - - public String getAdsCountdownAdLabel() { - return adsCountdownAdLabel; - } - - public String getAdsCountdownOfLabel() { - return adsCountdownOfLabel; - } - - public String getSkipCountdownLabel() { - return skipCountdownLabel; - } - - public String getSkipLabel() { - return skipLabel; - } - - public String getPlayingLiveLabel() { - return playingLiveLabel; - } - - public String getNowPlayingLabel() { - return nowPlayingLabel; - } - - public String getAudioAndSubtitlesLabel() { - return audioAndSubtitlesLabel; - } - - public String getSkipIntroLabel() { - return skipIntro; - } - - public String getSkipCreditsLabel() { - return skipCredits; - } -} diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactTVExoplayerView.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactTVExoplayerView.java index 312f771a32..83d80ab951 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactTVExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactTVExoplayerView.java @@ -53,7 +53,6 @@ import com.brentvatne.entity.RNImaDaiSource; import com.brentvatne.entity.RNMetadata; import com.brentvatne.entity.RNSource; -import com.brentvatne.entity.RNTranslations; import com.brentvatne.entity.RelatedVideo; import com.brentvatne.entity.Watermark; import com.brentvatne.react.R; @@ -89,8 +88,7 @@ import com.diceplatform.doris.ui.ExoDorisPlayerView; import com.diceplatform.doris.ui.ExoDorisPlayerViewListener; import com.diceplatform.doris.ui.ExoDorisTvPlayerView; -import com.diceplatform.doris.ui.entity.Labels; -import com.diceplatform.doris.ui.entity.LabelsBuilder; +import com.diceplatform.doris.ui.entity.LabelsTranslation; import com.diceplatform.doris.ui.entity.VideoTile; import com.diceplatform.doris.ui.skipmarker.SkipMarker; import com.diceplatform.doris.util.DorisExceptionUtil; @@ -162,6 +160,12 @@ class ReactTVExoplayerView extends FrameLayout implements LifecycleEventListener private static final String KEY_START_DATE = "startDate"; private static final String KEY_END_DATE = "endDate"; + private static final String KEY_LABELS_LEARN_MORE = "learnMore"; + private static final String KEY_LABELS_COUNT_DOWN_AD = "adsCountdownAd"; + private static final String KEY_LABELS_COUNT_DOWN_OF = "adsCountdownOf"; + private static final String KEY_LABELS_SKIP_IN = "skipAdIn"; + private static final String KEY_LABELS_SKIP = "skipAd"; + private static final int MAX_LOAD_BUFFER_MS = 30_000; static { @@ -199,7 +203,6 @@ class ReactTVExoplayerView extends FrameLayout implements LifecycleEventListener // Props from React private RNSource src; private RNMetadata metadata; - private RNTranslations translations; private boolean repeat; private boolean disableFocus; private boolean isLive = false; @@ -524,12 +527,13 @@ private void doInitializePlayer(boolean force) { AdViewProvider adViewProvider = adType == AdType.IMA_CSAI_LIVE ? secondaryPlayerView : exoDorisPlayerView; + LabelsTranslation translations = exoDorisPlayerView.getLabelsTranslation(); AdLabels adLabels = translations == null ? null : new AdLabels( - translations.getLearnMoreLabel(), - translations.getAdsCountdownAdLabel(), - translations.getAdsCountdownOfLabel(), - translations.getSkipCountdownLabel(), - translations.getSkipLabel() + translations.get(KEY_LABELS_LEARN_MORE), + translations.get(KEY_LABELS_COUNT_DOWN_AD), + translations.get(KEY_LABELS_COUNT_DOWN_OF), + translations.get(KEY_LABELS_SKIP_IN), + translations.get(KEY_LABELS_SKIP) ); AdGlobalSettings adGlobalSettings = new AdGlobalSettings(hideAdUiElements, isWhyThisAdIconEnabled, adLabels); @@ -1852,9 +1856,10 @@ public void setOverlayAutoHideTimeout(Long hideTimeout) { controlsAutoHideTimeout = hideTimeout; } - public void applyTranslations(Map translations) { - this.translations = new RNTranslations(translations); - setLabelsOnPLayerUi(); + public void setTranslations(Map map) { + if (exoDorisPlayerView != null) { + exoDorisPlayerView.setTranslation(map); + } } public void applyPrimaryColor(@ColorInt int primaryColor) { @@ -1863,35 +1868,6 @@ public void applyPrimaryColor(@ColorInt int primaryColor) { } } - private void setLabelsOnPLayerUi() { - if (exoDorisPlayerView != null && translations != null) { - Labels labels = new LabelsBuilder() - .setEpgLabel(translations.getEpgLabel()) - .setStatsLabel(translations.getStatsLabel()) - .setPlayLabel(translations.getPlayLabel()) - .setPauseLabel(translations.getPauseLabel()) - .setLiveLabel(translations.getLiveLabel()) - .setFavoriteLabel(translations.getFavoriteLabel()) - .setWatchlistLabel(translations.getWatchlistLabel()) - .setMoreVideosLabel(translations.getMoreVideosLabel()) - .setSubtitlesLabel(translations.getCaptionsLabel()) - .setRewindLabel(translations.getRewindLabel()) - .setFastForwardLabel(translations.getFastForwardLabel()) - .setAudioLanguagesLabel(translations.getAudioTracksLabel()) - .setInfoLabel(translations.getInfoLabel()) - .setAnnotationsLabel(translations.getAnnotationsLabel()) - .setAdsCountdownAdLabel(translations.getAdsCountdownAdLabel()) - .setAdsCountdownOfLabel(translations.getAdsCountdownOfLabel()) - .setPlayingLiveLabel(translations.getPlayingLiveLabel()) - .setNowPlayingLabel(translations.getNowPlayingLabel()) - .setAudioAndSubtitlesLabel(translations.getAudioAndSubtitlesLabel()) - .setSkipCreditsLabel(translations.getSkipCreditsLabel()) - .setSkipIntroLabel(translations.getSkipIntroLabel()) - .build(); - exoDorisPlayerView.setLabels(labels); - } - } - public void setSkipMarkers(List skipMarkers) { exoDorisPlayerView.setSkipMarkList(skipMarkers); } diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactTVExoplayerViewManager.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactTVExoplayerViewManager.java index cbbd05e1b8..79b91a6b40 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactTVExoplayerViewManager.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactTVExoplayerViewManager.java @@ -37,7 +37,6 @@ import com.facebook.react.uimanager.ViewGroupManager; import com.facebook.react.uimanager.annotations.ReactProp; import com.google.gson.Gson; -import com.imggaming.translations.DiceLocalizedStrings; import java.util.ArrayList; import java.util.HashMap; @@ -577,8 +576,7 @@ public void setStateProgressBar(final ReactTVExoplayerView videoView, final Stri @ReactProp(name = PROP_TRANSLATIONS) public void setTranslations(final ReactTVExoplayerView videoView, @Nullable ReadableMap translations) { - DiceLocalizedStrings.getInstance().updateTranslations(toStringMap(translations)); - videoView.applyTranslations(translations != null ? translations.toHashMap() : null); + videoView.setTranslations(toStringMap(translations)); } @ReactProp(name = PROP_RELATED_VIDEOS) diff --git a/android-exoplayer/src/main/java/com/imggaming/translations/DiceLocalizedStrings.java b/android-exoplayer/src/main/java/com/imggaming/translations/DiceLocalizedStrings.java deleted file mode 100644 index 0e5f13be28..0000000000 --- a/android-exoplayer/src/main/java/com/imggaming/translations/DiceLocalizedStrings.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.imggaming.translations; - -import java.util.HashMap; -import java.util.Map; - -public class DiceLocalizedStrings { - - private static final Map fallbackTranslations = new HashMap() {{ - put(StringId.player_play_button.name(), "Play"); - put(StringId.player_pause_button.name(), "Pause"); - put(StringId.player_audio_and_subtitles_button.name(), "Audio & Subtitles"); - put(StringId.player_epg_button.name(), "Schedule"); - put(StringId.player_stats_button.name(), "Stats"); - put(StringId.epgProgrammeStartBeginning.name(), "Watch from Beginning"); - put(StringId.epgProgrammeStartLive.name(), "Watch from Live"); - }}; - - private static DiceLocalizedStrings sInstance; - - private Map map; - - public static synchronized DiceLocalizedStrings getInstance() { - if (sInstance == null) { - sInstance = new DiceLocalizedStrings(); - } - return sInstance; - } - - public void updateTranslations(Map map) { - this.map = map; - } - - public String string(StringId id) { - return string(id.name()); - } - - private String string(String id) { - String translation = null; - if (map != null) { - translation = map.get(id); - } - - if (translation == null) { - translation = fallbackTranslations.get(id); - } - - return translation; - } - - /** - * Keys for translations that need to be provided by JS. - */ - public enum StringId { - player_play_button, - player_pause_button, - player_audio_and_subtitles_button, - player_epg_button, - player_stats_button, - epgProgrammeStartBeginning, // Watch from beginning - epgProgrammeStartLive, // Watch from live - } - -} diff --git a/package.json b/package.json index 1aa9a2c8a4..fcf736d444 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "react-native-video", - "version": "7.5.42", - "dorisAndroidVersion": "3.11.17", + "version": "7.5.43", + "dorisAndroidVersion": "3.11.18", "description": "A