mirror of
https://github.com/yuliskov/SmartTube.git
synced 2026-04-24 22:08:51 -05:00
pip fix
This commit is contained in:
+9
-9
@@ -25,7 +25,7 @@ public class HqDialogManager extends PlayerEventListenerHelper {
|
||||
private final Map<String, List<OptionItem>> mCheckedCategories = new LinkedHashMap<>();
|
||||
private final Map<String, List<OptionItem>> mRadioCategories = new LinkedHashMap<>();
|
||||
private final Map<CharSequence, OptionItem> mSingleOptions = new LinkedHashMap<>();
|
||||
private boolean mBlockEngine;
|
||||
private boolean mEnableBackgroundAudio;
|
||||
private boolean mEnablePIP;
|
||||
private final List<Runnable> mHideListeners = new ArrayList<>();
|
||||
|
||||
@@ -114,14 +114,14 @@ public class HqDialogManager extends PlayerEventListenerHelper {
|
||||
}
|
||||
|
||||
private void updateBackgroundPlayback() {
|
||||
if (mBlockEngine) {
|
||||
if (mEnableBackgroundAudio || mEnablePIP) {
|
||||
// return to the player regardless the last activity user watched in moment exiting to HOME
|
||||
ViewManager.instance(mActivity).blockTop(mActivity);
|
||||
} else {
|
||||
ViewManager.instance(mActivity).blockTop(null);
|
||||
}
|
||||
|
||||
mController.blockEngine(mBlockEngine);
|
||||
mController.blockEngine(mEnableBackgroundAudio);
|
||||
mController.enablePIP(mEnablePIP);
|
||||
}
|
||||
|
||||
@@ -131,22 +131,22 @@ public class HqDialogManager extends PlayerEventListenerHelper {
|
||||
List<OptionItem> options = new ArrayList<>();
|
||||
options.add(UiOptionItem.from(mActivity.getString(R.string.option_background_playback_off),
|
||||
optionItem -> {
|
||||
mBlockEngine = false;
|
||||
mEnableBackgroundAudio = false;
|
||||
mEnablePIP = false;
|
||||
updateBackgroundPlayback();
|
||||
}, !mBlockEngine && !mEnablePIP));
|
||||
}, !mEnableBackgroundAudio && !mEnablePIP));
|
||||
options.add(UiOptionItem.from(mActivity.getString(R.string.option_background_playback_all),
|
||||
optionItem -> {
|
||||
mBlockEngine = true;
|
||||
mEnableBackgroundAudio = false;
|
||||
mEnablePIP = true;
|
||||
updateBackgroundPlayback();
|
||||
}, mEnablePIP && mBlockEngine));
|
||||
}, mEnablePIP && !mEnableBackgroundAudio));
|
||||
options.add(UiOptionItem.from(mActivity.getString(R.string.option_background_playback_only_audio),
|
||||
optionItem -> {
|
||||
mBlockEngine = true;
|
||||
mEnableBackgroundAudio = true;
|
||||
mEnablePIP = false;
|
||||
updateBackgroundPlayback();
|
||||
}, mBlockEngine && !mEnablePIP));
|
||||
}, mEnableBackgroundAudio && !mEnablePIP));
|
||||
|
||||
addRadioCategory(categoryTitle, options);
|
||||
}
|
||||
|
||||
+3
-1
@@ -146,7 +146,9 @@ public class StateUpdater extends PlayerEventListenerHelper {
|
||||
mSubtitleFormat = track;
|
||||
}
|
||||
|
||||
AppPrefs.instance(mActivity).setFormat(track);
|
||||
if (!mController.isInPIPMode()) {
|
||||
AppPrefs.instance(mActivity).setFormat(track);
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureVideoSize(Video item) {
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ public class PlaybackPresenter implements Presenter<PlaybackView> {
|
||||
}
|
||||
|
||||
private void focusView() {
|
||||
if (mView != null && mView.getController().isEngineBlocked()) {
|
||||
if (mView != null && (mView.getController().isInPIPMode() || mView.getController().isEngineBlocked())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,8 @@ android {
|
||||
applicationId "com.liskovsoft.smarttubetv"
|
||||
minSdkVersion project.properties.minSdkVersion
|
||||
targetSdkVersion project.properties.targetSdkVersion
|
||||
versionCode 40
|
||||
versionName "3.1"
|
||||
versionCode 42
|
||||
versionName "3.2"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
buildConfigField "long", "TIMESTAMP", System.currentTimeMillis() + "L"
|
||||
|
||||
|
||||
+20
-9
@@ -57,22 +57,33 @@ public abstract class LeanbackActivity extends FragmentActivity {
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
mModeSyncManager.restore(this);
|
||||
mBackgroundManager.onStart();
|
||||
|
||||
// we can't do it in the ViewManager because activity may be started from outside
|
||||
mViewManager.addTop(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
|
||||
super.onPictureInPictureModeChanged(isInPictureInPictureMode);
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (!isInPictureInPictureMode) {
|
||||
mViewManager.addTop(this); // user makes pip activity fullscreen
|
||||
}
|
||||
// While entering/exiting PIP mode only Pause/Resume is called
|
||||
|
||||
mModeSyncManager.restore(this);
|
||||
|
||||
// We can't do it in the ViewManager because activity may be started from outside
|
||||
mViewManager.addTop(this);
|
||||
}
|
||||
|
||||
//@Override
|
||||
//public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
|
||||
// super.onPictureInPictureModeChanged(isInPictureInPictureMode);
|
||||
//
|
||||
// // While entering/exiting PIP mode only Pause/Resume is called
|
||||
//
|
||||
// if (!isInPictureInPictureMode) {
|
||||
// mModeSyncManager.restore(this);
|
||||
// mViewManager.addTop(this); // user makes pip activity fullscreen
|
||||
// }
|
||||
//}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
|
||||
+9
-33
@@ -2,7 +2,6 @@ package com.liskovsoft.smartyoutubetv2.tv.ui.playback;
|
||||
|
||||
import android.app.PictureInPictureParams;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import androidx.fragment.app.Fragment;
|
||||
@@ -26,7 +25,6 @@ public class PlaybackActivity extends LeanbackActivity {
|
||||
private static final float GAMEPAD_TRIGGER_INTENSITY_OFF = 0.45f;
|
||||
private boolean gamepadTriggerPressed = false;
|
||||
private PlaybackFragment mPlaybackFragment;
|
||||
private boolean mIsInPIPMode;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -92,53 +90,31 @@ public class PlaybackActivity extends LeanbackActivity {
|
||||
}
|
||||
}
|
||||
|
||||
//@Override
|
||||
//protected void onUserLeaveHint() {
|
||||
// super.onUserLeaveHint();
|
||||
//
|
||||
// Log.d(TAG, "onUserLeaveHint");
|
||||
//}
|
||||
|
||||
@Override
|
||||
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
|
||||
super.onPictureInPictureModeChanged(isInPictureInPictureMode);
|
||||
|
||||
mIsInPIPMode = isInPictureInPictureMode;
|
||||
mPlaybackFragment.blockEngine(isInPictureInPictureMode);
|
||||
|
||||
mPlaybackFragment.restartEngine();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
// Avoid enter pip on stop!
|
||||
public void finish() {
|
||||
// NOTE: When exiting PIP mode onPause is called immediately after onResume
|
||||
|
||||
// Also, avoid enter pip on stop!
|
||||
// More info: https://developer.android.com/guide/topics/ui/picture-in-picture#continuing_playback
|
||||
|
||||
// User pressed home. Don't restore parent activity.
|
||||
if (!isFinishing() && mPlaybackFragment.isEngineBlocked() && mPlaybackFragment.isPIPEnabled()) {
|
||||
enterPIPMode();
|
||||
}
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
|
||||
Log.d(TAG, "Config changed: " + newConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
// User pressed back. We need to restore parent activity.
|
||||
if (mPlaybackFragment.isEngineBlocked() && mPlaybackFragment.isPIPEnabled()) {
|
||||
// User pressed back.
|
||||
if (wannaEnterToPIP()) {
|
||||
enterPIPMode();
|
||||
}
|
||||
|
||||
super.finish();
|
||||
}
|
||||
|
||||
public boolean isInPIPMode() {
|
||||
return mIsInPIPMode;
|
||||
private boolean wannaEnterToPIP() {
|
||||
return !isInPictureInPictureMode() && mPlaybackFragment.isPIPEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
+9
-7
@@ -166,12 +166,16 @@ public class PlaybackFragment extends VideoSupportFragment implements PlaybackVi
|
||||
|
||||
@Override
|
||||
public void restartEngine() {
|
||||
//if (mPlayer != null) {
|
||||
// mEventListener.onEngineReleased();
|
||||
//}
|
||||
//destroyPlayerObjects();
|
||||
//createPlayerObjects();
|
||||
|
||||
if (mPlayer != null) {
|
||||
mEventListener.onEngineReleased();
|
||||
mEventListener.onEngineInitialized();
|
||||
}
|
||||
destroyPlayerObjects();
|
||||
createPlayerObjects();
|
||||
mEventListener.onEngineInitialized();
|
||||
}
|
||||
|
||||
private void releasePlayer() {
|
||||
@@ -486,13 +490,11 @@ public class PlaybackFragment extends VideoSupportFragment implements PlaybackVi
|
||||
|
||||
@Override
|
||||
public boolean isInPIPMode() {
|
||||
PlaybackActivity playbackActivity = (PlaybackActivity) getActivity();
|
||||
|
||||
if (playbackActivity == null) {
|
||||
if (getActivity() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return playbackActivity.isInPIPMode();
|
||||
return getActivity().isInPictureInPictureMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user