Skip to content

Commit bf14383

Browse files
committed
player fragment: add lazy init for subtitle/debug info
1 parent 262bba6 commit bf14383

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

common/src/main/java/com/liskovsoft/smartyoutubetv2/common/exoplayer/other/DebugInfoManager.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,13 @@ public final class DebugInfoManager implements Runnable, Player.EventListener {
7575
private final String mAppVersion;
7676

7777
/**
78-
* @param root root view
79-
* @param resLayoutId The {@link TextView} that should be updated to display the information.
78+
* @param debugViewGroup The container that should be updated to display the information.
8079
* @param player The {@link SimpleExoPlayer} from which debug information should be obtained.
8180
*/
82-
public DebugInfoManager(View root, int resLayoutId, SimpleExoPlayer player) {
81+
public DebugInfoManager(ViewGroup debugViewGroup, SimpleExoPlayer player) {
82+
mContext = debugViewGroup.getContext();
83+
mDebugViewGroup = debugViewGroup;
8384
mPlayer = player;
84-
mDebugViewGroup = root.findViewById(resLayoutId);
85-
mContext = root.getContext();
8685
mTextSize = mContext.getResources().getDimension(R.dimen.debug_text_size);
8786
mAppVersion = String.format("%s version", mContext.getString(R.string.app_name));
8887
inflate();

common/src/main/java/com/liskovsoft/smartyoutubetv2/common/exoplayer/other/SubtitleManager.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.liskovsoft.smartyoutubetv2.common.exoplayer.other;
22

3-
import android.app.Activity;
43
import android.content.Context;
54
import android.graphics.Color;
65
import android.graphics.Typeface;
@@ -56,9 +55,9 @@ public boolean isSystem() {
5655
}
5756
}
5857

59-
public SubtitleManager(View root, int subViewId) {
60-
mContext = root.getContext();
61-
mSubtitleView = root.findViewById(subViewId);
58+
public SubtitleManager(SubtitleView subtitleView) {
59+
mContext = subtitleView.getContext();
60+
mSubtitleView = subtitleView;
6261
mPrefs = AppPrefs.instance(mContext);
6362
mPlayerData = PlayerData.instance(mContext);
6463
mPlayerData.setOnChange(this);

smarttubetv/src/main/java/com/liskovsoft/smartyoutubetv2/tv/ui/playback/PlaybackFragment.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,9 @@ private void createPlayerObjects() {
444444

445445
createPlayerGlue();
446446

447-
createSubtitleManager();
447+
//createSubtitleManager();
448448

449-
createDebugManager();
449+
//createDebugManager();
450450

451451
createMediaSession();
452452

@@ -489,15 +489,17 @@ private void createPlayerGlue() {
489489
}
490490

491491
private void createSubtitleManager() {
492-
if (getView() == null) {
492+
if (getView() == null || mPlayer == null) {
493493
return;
494494
}
495495

496-
mSubtitleManager = new SubtitleManager(getView(), R.id.leanback_subtitles);
496+
if (mSubtitleManager == null) {
497+
mSubtitleManager = new SubtitleManager(getView().findViewById(R.id.leanback_subtitles));
497498

498-
// subs renderer
499-
if (mPlayer.getTextComponent() != null) {
500-
mPlayer.getTextComponent().addTextOutput(mSubtitleManager);
499+
// subs renderer
500+
if (mPlayer.getTextComponent() != null) {
501+
mPlayer.getTextComponent().addTextOutput(mSubtitleManager);
502+
}
501503
}
502504
}
503505

@@ -506,7 +508,9 @@ private void createDebugManager() {
506508
return;
507509
}
508510

509-
mDebugInfoManager = new DebugInfoManager(getView(), R.id.debug_view_group, mPlayer);
511+
if (mDebugInfoManager == null) {
512+
mDebugInfoManager = new DebugInfoManager(getView().findViewById(R.id.debug_view_group), mPlayer);
513+
}
510514
}
511515

512516
private void initializeGlobalClock() {
@@ -1326,19 +1330,22 @@ public void setNextTitle(Video nextVideo) {
13261330

13271331
@Override
13281332
public void showDebugInfo(boolean show) {
1333+
createDebugManager();
13291334
if (mDebugInfoManager != null) {
13301335
mDebugInfoManager.show(show);
13311336
}
13321337
}
13331338

13341339
@Override
13351340
public void showSubtitles(boolean show) {
1341+
createSubtitleManager();
13361342
if (mSubtitleManager != null) {
13371343
mSubtitleManager.show(show);
13381344
}
13391345
}
13401346

13411347
public boolean isDebugInfoShown() {
1348+
createDebugManager();
13421349
return mDebugInfoManager != null && mDebugInfoManager.isShown();
13431350
}
13441351

0 commit comments

Comments
 (0)