mirror of
https://github.com/yuliskov/SmartTube.git
synced 2026-01-25 16:10:20 -06:00
refactor
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.liskovsoft.smartyoutubetv2.common.app.models.playback;
|
||||
|
||||
import android.app.Activity;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import com.liskovsoft.smartyoutubetv2.common.app.models.data.Video;
|
||||
import com.liskovsoft.smartyoutubetv2.common.app.models.playback.controller.PlaybackController;
|
||||
import com.liskovsoft.smartyoutubetv2.common.app.models.playback.listener.PlayerHandlerEventListener;
|
||||
@@ -21,6 +23,9 @@ public class MainPlayerEventBridge implements PlayerEventListener {
|
||||
private static final String TAG = MainPlayerEventBridge.class.getSimpleName();
|
||||
private final ArrayList<PlayerHandlerEventListener> mEventListeners;
|
||||
private static MainPlayerEventBridge sInstance;
|
||||
private PlaybackController mController;
|
||||
private Activity mMainActivity;
|
||||
private Activity mParentActivity;
|
||||
|
||||
public MainPlayerEventBridge() {
|
||||
mEventListeners = new ArrayList<>();
|
||||
@@ -46,20 +51,35 @@ public class MainPlayerEventBridge implements PlayerEventListener {
|
||||
|
||||
public void setController(PlaybackController controller) {
|
||||
if (controller != null) {
|
||||
process(listener -> listener.onController(controller));
|
||||
process(listener -> {
|
||||
Fragment fragment = (Fragment) controller;
|
||||
listener.onMainActivity(fragment.getActivity());
|
||||
});
|
||||
Fragment fragment = (Fragment) controller;
|
||||
Activity mainActivity = fragment.getActivity();
|
||||
|
||||
if (mController != controller) {
|
||||
mController = controller;
|
||||
|
||||
process(listener -> listener.onController(controller));
|
||||
}
|
||||
|
||||
if (mMainActivity != mainActivity) {
|
||||
mMainActivity = mainActivity;
|
||||
|
||||
process(listener -> listener.onMainActivity(mainActivity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setParentView(Object parentView) {
|
||||
if (parentView instanceof Fragment) {
|
||||
process(listener -> {
|
||||
Fragment fragment = (Fragment) parentView;
|
||||
listener.onParentActivity(fragment.getActivity());
|
||||
});
|
||||
Fragment fragment = (Fragment) parentView;
|
||||
Activity parentActivity = fragment.getActivity();
|
||||
|
||||
if (mParentActivity != parentActivity) {
|
||||
mParentActivity = parentActivity;
|
||||
|
||||
process(listener -> {
|
||||
listener.onParentActivity(parentActivity);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ public class AutoFrameRateManager extends PlayerEventListenerHelper {
|
||||
|
||||
mMainActivityRunOnce = true;
|
||||
} else {
|
||||
mAutoFrameRateHelper.updateActivity(mMainActivity);
|
||||
mAutoFrameRateHelper.setActivity(mMainActivity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class AutoFrameRateManager extends PlayerEventListenerHelper {
|
||||
|
||||
mParentActivityRunOnce = true;
|
||||
} else {
|
||||
mParentAutoFrameRateHelper.updateActivity(mParentActivity);
|
||||
mParentAutoFrameRateHelper.setActivity(mParentActivity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -143,8 +143,12 @@ public class AutoFrameRateHelper {
|
||||
mSyncHelper.applyModeChangeFix(mActivity.getWindow());
|
||||
}
|
||||
|
||||
public void updateActivity(Activity activity) {
|
||||
public void setActivity(Activity activity) {
|
||||
mActivity = activity;
|
||||
mSyncHelper.setContext(activity);
|
||||
}
|
||||
|
||||
public void resetState() {
|
||||
mSyncHelper.resetMode(mActivity.getWindow());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,6 +334,10 @@ public class DisplaySyncHelper implements UhdHelperListener {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void resetMode(Window window) {
|
||||
getUhdHelper().setPreferredDisplayModeId(window, 0, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazy init of uhd helper.<br/>
|
||||
* Convenient when user doesn't use a afr at all.
|
||||
|
||||
@@ -337,9 +337,9 @@ public class UhdHelper {
|
||||
*/
|
||||
@TargetApi(17)
|
||||
public void setPreferredDisplayModeId(Window targetWindow, int modeId, boolean allowOverlayDisplay) {
|
||||
if (modeId == 0) { // mode is not set
|
||||
return;
|
||||
}
|
||||
//if (modeId == 0) { // mode is not set
|
||||
// return;
|
||||
//}
|
||||
|
||||
/*
|
||||
* The Android M preview adds a preferredDisplayModeId to
|
||||
|
||||
Reference in New Issue
Block a user