mirror of
https://github.com/yuliskov/SmartTube.git
synced 2026-01-05 21:40:47 -06:00
afr tweaks & refactor settings
This commit is contained in:
@@ -75,21 +75,6 @@ public class MainPlayerEventBridge implements PlayerEventListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setParentView(Object parentView) {
|
||||
if (parentView instanceof Fragment) {
|
||||
Fragment fragment = (Fragment) parentView;
|
||||
Activity parentActivity = fragment.getActivity();
|
||||
|
||||
if (mParentActivity != parentActivity) {
|
||||
mParentActivity = parentActivity;
|
||||
|
||||
process(listener -> {
|
||||
listener.onParentActivity(parentActivity);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openVideo(Video item) {
|
||||
|
||||
@@ -9,7 +9,6 @@ import com.liskovsoft.smartyoutubetv2.common.autoframerate.FormatItem;
|
||||
public abstract class PlayerEventListenerHelper implements PlayerHandlerEventListener {
|
||||
protected PlaybackController mController;
|
||||
protected Activity mActivity;
|
||||
protected Activity mParentActivity;
|
||||
|
||||
@Override
|
||||
public void onController(PlaybackController controller) {
|
||||
@@ -21,11 +20,6 @@ public abstract class PlayerEventListenerHelper implements PlayerHandlerEventLis
|
||||
mActivity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onParentActivity(Activity activity) {
|
||||
mParentActivity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openVideo(Video item) {
|
||||
// NOP
|
||||
|
||||
@@ -10,5 +10,4 @@ public interface PlayerHandlerEventListener extends PlayerUiEventListener, Playe
|
||||
void openVideo(Video item);
|
||||
void onController(PlaybackController controller);
|
||||
void onActivity(Activity activity);
|
||||
void onParentActivity(Activity activity);
|
||||
}
|
||||
|
||||
@@ -14,18 +14,19 @@ import java.util.List;
|
||||
|
||||
public class AutoFrameRateManager extends PlayerEventListenerHelper {
|
||||
private final HqDialogManager mUiManager;
|
||||
private AutoFrameRateHelper mAutoFrameRateHelper;
|
||||
private boolean mAfrEnabled;
|
||||
private boolean mCorrectionEnabled;
|
||||
private boolean mSwitchEnabled;
|
||||
private boolean mMainActivityRunOnce;
|
||||
//private boolean mParentActivityRunOnce;
|
||||
private FormatItem mSelectedVideoTrack;
|
||||
//private AutoFrameRateHelper mParentAutoFrameRateHelper;
|
||||
private ModeSyncManager mModeSyncManager;
|
||||
private final AutoFrameRateHelper mAutoFrameRateHelper;
|
||||
private final ModeSyncManager mModeSyncManager;
|
||||
|
||||
public AutoFrameRateManager(HqDialogManager uiManager) {
|
||||
mUiManager = uiManager;
|
||||
mAutoFrameRateHelper = new AutoFrameRateHelper();
|
||||
mModeSyncManager = ModeSyncManager.instance();
|
||||
mModeSyncManager.setAfrHelper(mAutoFrameRateHelper);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -33,49 +34,23 @@ public class AutoFrameRateManager extends PlayerEventListenerHelper {
|
||||
super.onActivity(activity);
|
||||
|
||||
if (!mMainActivityRunOnce) {
|
||||
mAutoFrameRateHelper = new AutoFrameRateHelper(mActivity);
|
||||
mModeSyncManager = ModeSyncManager.instance(activity);
|
||||
|
||||
addUiOptions();
|
||||
|
||||
mAutoFrameRateHelper.saveOriginalState(activity);
|
||||
mMainActivityRunOnce = true;
|
||||
} else {
|
||||
mAutoFrameRateHelper.setActivity(mActivity);
|
||||
}
|
||||
}
|
||||
|
||||
//@Override
|
||||
//public void onParentActivity(Activity activity) {
|
||||
// super.onParentActivity(activity);
|
||||
//
|
||||
// if (!mParentActivityRunOnce) {
|
||||
// mParentAutoFrameRateHelper = new AutoFrameRateHelper(mParentActivity);
|
||||
//
|
||||
// mParentActivityRunOnce = true;
|
||||
// } else {
|
||||
// mParentAutoFrameRateHelper.setActivity(mParentActivity);
|
||||
// }
|
||||
//}
|
||||
|
||||
@Override
|
||||
public void onTrackChanged(FormatItem track) {
|
||||
if (track.getType() == FormatItem.TYPE_VIDEO) {
|
||||
mSelectedVideoTrack = track;
|
||||
|
||||
if (mAfrEnabled) {
|
||||
applyAfr(track);
|
||||
}
|
||||
applyAfr();
|
||||
}
|
||||
}
|
||||
|
||||
private void onAfrOptionClick(OptionItem optionItem) {
|
||||
mAfrEnabled = optionItem.isSelected();
|
||||
|
||||
if (mAfrEnabled) {
|
||||
applyAfr(mSelectedVideoTrack);
|
||||
} else {
|
||||
restoreAfr();
|
||||
}
|
||||
}
|
||||
|
||||
private void onFpsCorrectionClick(OptionItem optionItem) {
|
||||
@@ -86,19 +61,24 @@ public class AutoFrameRateManager extends PlayerEventListenerHelper {
|
||||
private void onResolutionSwitchClick(OptionItem optionItem) {
|
||||
mSwitchEnabled = optionItem.isSelected();
|
||||
mAutoFrameRateHelper.setResolutionSwitchEnabled(mSwitchEnabled);
|
||||
applyAfr(mSelectedVideoTrack);
|
||||
}
|
||||
|
||||
private void restoreAfr() {
|
||||
mAutoFrameRateHelper.restoreOriginalState();
|
||||
//mParentAutoFrameRateHelper.restoreOriginalState();
|
||||
mAutoFrameRateHelper.restoreOriginalState(mActivity);
|
||||
mModeSyncManager.save(null);
|
||||
}
|
||||
|
||||
private void applyAfr() {
|
||||
if (mAfrEnabled) {
|
||||
applyAfr(mSelectedVideoTrack);
|
||||
} else {
|
||||
restoreAfr();
|
||||
}
|
||||
}
|
||||
|
||||
private void applyAfr(FormatItem track) {
|
||||
if (track != null) {
|
||||
mAutoFrameRateHelper.apply(track);
|
||||
//mParentAutoFrameRateHelper.apply(track);
|
||||
mAutoFrameRateHelper.apply(track, mActivity);
|
||||
mModeSyncManager.save(track);
|
||||
}
|
||||
}
|
||||
@@ -113,5 +93,7 @@ public class AutoFrameRateManager extends PlayerEventListenerHelper {
|
||||
options.add(UiOptionItem.from(fpsCorrection, this::onFpsCorrectionClick, mCorrectionEnabled));
|
||||
|
||||
mUiManager.addCheckedCategory(title, options);
|
||||
|
||||
mUiManager.setOnDialogHide(this::applyAfr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ public class HqDialogManager extends PlayerEventListenerHelper {
|
||||
private final Map<CharSequence, OptionItem> mSingleOptions = new LinkedHashMap<>();
|
||||
private boolean mBlockEngine;
|
||||
private boolean mEnablePIP;
|
||||
private final List<Runnable> mHideListeners = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void onActivity(Activity activity) {
|
||||
@@ -70,7 +71,15 @@ public class HqDialogManager extends PlayerEventListenerHelper {
|
||||
createCheckedOptions();
|
||||
createSingleOptions();
|
||||
|
||||
mSettingsPresenter.showDialog(mActivity.getString(R.string.playback_settings), this::updateBackgroundPlayback);
|
||||
mSettingsPresenter.showDialog(mActivity.getString(R.string.playback_settings), this::onDialogHide);
|
||||
}
|
||||
|
||||
private void onDialogHide() {
|
||||
updateBackgroundPlayback();
|
||||
|
||||
for (Runnable listener : mHideListeners) {
|
||||
listener.run();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateBackgroundPlayback() {
|
||||
@@ -123,6 +132,10 @@ public class HqDialogManager extends PlayerEventListenerHelper {
|
||||
mRadioCategories.put(categoryTitle, options);
|
||||
}
|
||||
|
||||
public void setOnDialogHide(Runnable listener) {
|
||||
mHideListeners.add(listener);
|
||||
}
|
||||
|
||||
private void createSingleOptions() {
|
||||
for (OptionItem option : mSingleOptions.values()) {
|
||||
mSettingsPresenter.appendSingleSwitch(option);
|
||||
|
||||
@@ -83,7 +83,6 @@ public class AppSettingsPresenter implements Presenter<AppSettingsView> {
|
||||
@Override
|
||||
public void unregister(AppSettingsView view) {
|
||||
mView = null;
|
||||
onClose();
|
||||
}
|
||||
|
||||
public void onClose() {
|
||||
|
||||
@@ -107,7 +107,7 @@ public class BrowsePresenter implements HeaderPresenter<BrowseView> {
|
||||
}
|
||||
|
||||
if (item.isVideo()) {
|
||||
mPlaybackPresenter.openVideo(mView, item);
|
||||
mPlaybackPresenter.openVideo(item);
|
||||
} else if (item.isChannel()) {
|
||||
ChannelPresenter.instance(mContext).openChannel(item);
|
||||
}
|
||||
|
||||
@@ -48,19 +48,15 @@ public class PlaybackPresenter implements Presenter<PlaybackView> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens video item from browser or search views<br/>
|
||||
* Parent view needed to properly handle auto frame rate changes
|
||||
* Opens video item from browser, search or channel views
|
||||
*/
|
||||
public void openVideo(Object parentView, Video item) {
|
||||
mMainPlayerEventBridge.setParentView(parentView);
|
||||
|
||||
openVideo(item);
|
||||
}
|
||||
|
||||
public void openVideo(String videoId) {
|
||||
openVideo(Video.from(videoId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens video item from browser, search or channel views
|
||||
*/
|
||||
public void openVideo(Video item) {
|
||||
mMainPlayerEventBridge.openVideo(item);
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ public class SearchPresenter implements VideoGroupPresenter<SearchView> {
|
||||
}
|
||||
|
||||
if (item.isVideo()) {
|
||||
mPlaybackPresenter.openVideo(mView, item);
|
||||
mPlaybackPresenter.openVideo(item);
|
||||
} else if (item.isChannel()) {
|
||||
ChannelPresenter.instance(mContext).openChannel(item);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.liskovsoft.smartyoutubetv2.common.app.views;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.liskovsoft.sharedutils.mylogger.Log;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -14,6 +14,7 @@ import java.util.Stack;
|
||||
|
||||
public class ViewManager {
|
||||
private static final String TAG = ViewManager.class.getSimpleName();
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static ViewManager sInstance;
|
||||
private final Context mContext;
|
||||
private final Map<Class<?>, Class<? extends Activity>> mViewMapping;
|
||||
@@ -150,7 +151,6 @@ public class ViewManager {
|
||||
Class<?> activityClass = activity.getClass();
|
||||
|
||||
// reorder activity
|
||||
|
||||
mActivityStack.remove(activityClass);
|
||||
mActivityStack.push(activityClass);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
package com.liskovsoft.smartyoutubetv2.common.app.views;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.liskovsoft.sharedutils.mylogger.Log;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
public class ViewManager {
|
||||
private static final String TAG = ViewManager.class.getSimpleName();
|
||||
private static ViewManager sInstance;
|
||||
private final Context mContext;
|
||||
private final Map<Class<?>, Class<? extends Activity>> mViewMapping;
|
||||
private final Map<Class<? extends Activity>, Class<? extends Activity>> mParentMapping;
|
||||
private final Stack<Activity> mActivityStack;
|
||||
private Class<?> mRootActivityClass;
|
||||
private Class<?> mDefaultTopActivityClass;
|
||||
private long mPrevThrottleTimeMS;
|
||||
private boolean mMoveTaskToBack;
|
||||
|
||||
private ViewManager(Context context) {
|
||||
mContext = context;
|
||||
mViewMapping = new HashMap<>();
|
||||
mParentMapping = new HashMap<>();
|
||||
mActivityStack = new Stack<>();
|
||||
}
|
||||
|
||||
public static ViewManager instance(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new ViewManager(context.getApplicationContext());
|
||||
}
|
||||
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public void register(Class<?> viewClass, Class<? extends Activity> activityClass) {
|
||||
register(viewClass, activityClass, null);
|
||||
}
|
||||
|
||||
public void register(Class<?> viewClass, Class<? extends Activity> activityClass, Class<? extends Activity> parentActivityClass) {
|
||||
mViewMapping.put(viewClass, activityClass);
|
||||
|
||||
if (parentActivityClass != null) {
|
||||
mParentMapping.put(activityClass, parentActivityClass);
|
||||
}
|
||||
}
|
||||
|
||||
public void unregister(Class<?> viewClass) {
|
||||
mViewMapping.remove(viewClass);
|
||||
}
|
||||
|
||||
public void startView(Class<?> viewClass) {
|
||||
if (doThrottle()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Class<?> activityClass = mViewMapping.get(viewClass);
|
||||
|
||||
if (activityClass != null) {
|
||||
Intent intent = new Intent(mContext, activityClass);
|
||||
|
||||
// Fix: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
||||
Log.d(TAG, "Launching activity view: " + activityClass.getSimpleName());
|
||||
mContext.startActivity(intent);
|
||||
} else {
|
||||
Log.e(TAG, "Activity not registered for view " + viewClass.getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
public void startParentView(Activity activity) {
|
||||
if (doThrottle()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (activity.getIntent() != null) {
|
||||
removeTopActivity();
|
||||
|
||||
Class<?> parentActivity = getTopActivityClass();
|
||||
|
||||
if (parentActivity == null) {
|
||||
parentActivity = getDefaultParent(activity);
|
||||
}
|
||||
|
||||
if (parentActivity == null) {
|
||||
Log.d(TAG, "Parent activity name doesn't stored in registry. Exiting to Home...");
|
||||
mMoveTaskToBack = true;
|
||||
activity.moveTaskToBack(true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Log.d(TAG, "Launching parent activity: " + parentActivity.getSimpleName());
|
||||
Intent intent = new Intent(activity, parentActivity);
|
||||
|
||||
activity.startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "Parent activity not found.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void startDefaultView(Context context) {
|
||||
mMoveTaskToBack = false;
|
||||
|
||||
if (doThrottle()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Class<?> lastActivity;
|
||||
|
||||
if (mDefaultTopActivityClass != null) {
|
||||
lastActivity = mDefaultTopActivityClass;
|
||||
} else if (!mActivityStack.isEmpty()) {
|
||||
lastActivity = mActivityStack.peek().getClass();
|
||||
} else {
|
||||
lastActivity = mRootActivityClass;
|
||||
}
|
||||
|
||||
Log.d(TAG, "Launching default activity: " + lastActivity.getSimpleName());
|
||||
|
||||
Intent intent = new Intent(context, lastActivity);
|
||||
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
private boolean doThrottle() {
|
||||
long currentTimeMS = System.currentTimeMillis();
|
||||
boolean skipEvent = currentTimeMS - mPrevThrottleTimeMS < 1_000;
|
||||
|
||||
mPrevThrottleTimeMS = currentTimeMS;
|
||||
|
||||
return skipEvent;
|
||||
}
|
||||
|
||||
public void addTop(Activity activity) {
|
||||
if (checkMoveTaskToBack(activity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// reorder activity
|
||||
mActivityStack.remove(activity);
|
||||
mActivityStack.push(activity);
|
||||
}
|
||||
|
||||
public Activity getTop() {
|
||||
if (!mActivityStack.isEmpty()) {
|
||||
return mActivityStack.peek();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Activity getParent() {
|
||||
if (mActivityStack.size() >= 2) {
|
||||
return mActivityStack.get(mActivityStack.size() - 2);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void removeTopActivity() {
|
||||
if (!mActivityStack.isEmpty()) {
|
||||
mActivityStack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
private Class<?> getTopActivityClass() {
|
||||
Class<?> result = null;
|
||||
|
||||
if (!mActivityStack.isEmpty()) {
|
||||
result = mActivityStack.peek().getClass();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setRoot(@NonNull Class<?> rootActivity) {
|
||||
mRootActivityClass = rootActivity;
|
||||
}
|
||||
|
||||
private Class<?> getDefaultParent(Activity activity) {
|
||||
Class<?> parentActivity = null;
|
||||
|
||||
for (Class<?> activityClass : mParentMapping.keySet()) {
|
||||
if (activityClass.isInstance(activity)) {
|
||||
parentActivity = mParentMapping.get(activityClass);
|
||||
}
|
||||
}
|
||||
|
||||
return parentActivity;
|
||||
}
|
||||
|
||||
public void blockTop(Activity activity) {
|
||||
mDefaultTopActivityClass = activity == null ? null : activity.getClass();
|
||||
}
|
||||
|
||||
private boolean checkMoveTaskToBack(Activity activity) {
|
||||
if (mMoveTaskToBack) {
|
||||
activity.moveTaskToBack(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,165 +0,0 @@
|
||||
package com.liskovsoft.smartyoutubetv2.common.app.views;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import com.liskovsoft.sharedutils.mylogger.Log;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ViewManagerOld {
|
||||
private static final String PARENT_ACTIVITY = "PARENT_ACTIVITY";
|
||||
private static final String TAG = ViewManagerOld.class.getSimpleName();
|
||||
private static ViewManagerOld sInstance;
|
||||
private final Context mContext;
|
||||
private final Map<Class<?>, Class<? extends Activity>> mViewMapping;
|
||||
private final Map<Class<? extends Activity>, Class<? extends Activity>> mParentMapping;
|
||||
private Class<?> mDefaultActivity;
|
||||
private Class<?> mRootActivity;
|
||||
|
||||
private ViewManagerOld(Context context) {
|
||||
mContext = context;
|
||||
mViewMapping = new HashMap<>();
|
||||
mParentMapping = new HashMap<>();
|
||||
}
|
||||
|
||||
public static ViewManagerOld instance(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new ViewManagerOld(context.getApplicationContext());
|
||||
}
|
||||
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public void register(Class<?> viewClass, Class<? extends Activity> activityClass) {
|
||||
register(viewClass, activityClass, null);
|
||||
}
|
||||
|
||||
public void register(Class<?> viewClass, Class<? extends Activity> activityClass, Class<? extends Activity> parentActivityClass) {
|
||||
mViewMapping.put(viewClass, activityClass);
|
||||
|
||||
if (parentActivityClass != null) {
|
||||
mParentMapping.put(activityClass, parentActivityClass);
|
||||
}
|
||||
}
|
||||
|
||||
public void unregister(Class<?> viewClass) {
|
||||
mViewMapping.remove(viewClass);
|
||||
}
|
||||
|
||||
public void startView(Class<?> viewClass) {
|
||||
Class<?> activityClass = mViewMapping.get(viewClass);
|
||||
|
||||
if (activityClass != null) {
|
||||
Intent intent = new Intent(mContext, activityClass);
|
||||
|
||||
// Fix: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
||||
mContext.startActivity(intent);
|
||||
} else {
|
||||
Log.e(TAG, "Activity not registered for view " + viewClass.getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
public void startView(Object parentView, Class<?> viewClass) {
|
||||
if (parentView instanceof Fragment) {
|
||||
Fragment fragment = (Fragment) parentView;
|
||||
|
||||
Class<?> activityClass = mViewMapping.get(viewClass);
|
||||
|
||||
if (activityClass != null) {
|
||||
Intent intent = new Intent(fragment.getActivity(), activityClass);
|
||||
intent.putExtra(PARENT_ACTIVITY, fragment.getActivity().getClass().getName());
|
||||
|
||||
fragment.startActivity(intent);
|
||||
} else {
|
||||
Log.e(TAG, "Activity not registered for view " + viewClass.getSimpleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void startParentView(Activity activity) {
|
||||
if (activity.getIntent() != null) {
|
||||
Class<?> parentActivity = getParent(activity);
|
||||
|
||||
if (parentActivity == null) {
|
||||
Log.d(TAG, "Parent activity name doesn't stored in registry. Exiting to Home...");
|
||||
activity.moveTaskToBack(true);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Log.d(TAG, "Launching parent activity...");
|
||||
setDefault(null); // current activity is finished, so do reset
|
||||
Intent intent = new Intent(activity, parentActivity);
|
||||
|
||||
activity.startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "Parent activity not found.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Class<?> getParent(Activity activity) {
|
||||
Class<?> parentActivity = null;
|
||||
String parentActivityName = null;
|
||||
|
||||
if (activity.getIntent() != null) {
|
||||
parentActivityName = activity.getIntent().getStringExtra(PARENT_ACTIVITY);
|
||||
}
|
||||
|
||||
if (parentActivityName != null) {
|
||||
try {
|
||||
parentActivity = Class.forName(parentActivityName);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "Activity class not found.");
|
||||
}
|
||||
} else {
|
||||
parentActivity = getDefaultParent(activity);
|
||||
}
|
||||
|
||||
return parentActivity;
|
||||
}
|
||||
|
||||
private Class<?> getDefaultParent(Activity activity) {
|
||||
Class<?> parentActivity = null;
|
||||
|
||||
for (Class<?> activityClass : mParentMapping.keySet()) {
|
||||
if (activityClass.isInstance(activity)) {
|
||||
parentActivity = mParentMapping.get(activityClass);
|
||||
}
|
||||
}
|
||||
|
||||
return parentActivity;
|
||||
}
|
||||
|
||||
public void startDefaultView(Activity activity) {
|
||||
Class<?> lastActivity = mDefaultActivity;
|
||||
|
||||
if (lastActivity == null) {
|
||||
lastActivity = mRootActivity;
|
||||
}
|
||||
|
||||
Log.d(TAG, "Starting activity: " + lastActivity.getSimpleName());
|
||||
|
||||
Intent intent = new Intent(activity, lastActivity);
|
||||
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
|
||||
public void setDefault(@Nullable Class<?> defaultActivity) {
|
||||
mDefaultActivity = defaultActivity;
|
||||
}
|
||||
|
||||
public void setRoot(@NonNull Class<?> rootActivity) {
|
||||
mRootActivity = rootActivity;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,11 @@ public class AutoFrameRateHelper {
|
||||
private HashMap<Float, Float> mFrameRateMapping;
|
||||
private boolean mIsFpsCorrectionEnabled;
|
||||
|
||||
public AutoFrameRateHelper(Activity activity) {
|
||||
public AutoFrameRateHelper() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
private AutoFrameRateHelper(Activity activity) {
|
||||
mActivity = activity;
|
||||
mSyncHelper = new DisplaySyncHelperAlt(activity);
|
||||
|
||||
@@ -32,7 +36,7 @@ public class AutoFrameRateHelper {
|
||||
mFrameRateMapping.put(60f, 59.94f);
|
||||
}
|
||||
|
||||
public void apply(FormatItem format, boolean force) {
|
||||
private void apply(FormatItem format, boolean force) {
|
||||
if (mActivity == null) {
|
||||
Log.e(TAG, "Activity in null. exiting...");
|
||||
return;
|
||||
@@ -62,7 +66,12 @@ public class AutoFrameRateHelper {
|
||||
mSyncHelper.syncDisplayMode(mActivity.getWindow(), width, frameRate, force);
|
||||
}
|
||||
|
||||
public void apply(FormatItem format) {
|
||||
public void apply(FormatItem format, Activity activity) {
|
||||
setActivity(activity);
|
||||
apply(format);
|
||||
}
|
||||
|
||||
private void apply(FormatItem format) {
|
||||
apply(format, false);
|
||||
}
|
||||
|
||||
@@ -78,6 +87,11 @@ public class AutoFrameRateHelper {
|
||||
mSyncHelper.setResolutionSwitchEnabled(enabled);
|
||||
}
|
||||
|
||||
public void saveOriginalState(Activity activity) {
|
||||
setActivity(activity);
|
||||
saveOriginalState();
|
||||
}
|
||||
|
||||
private void saveOriginalState() {
|
||||
if (mActivity == null) {
|
||||
Log.e(TAG, "Activity in null. exiting...");
|
||||
@@ -91,7 +105,16 @@ public class AutoFrameRateHelper {
|
||||
mSyncHelper.saveOriginalState();
|
||||
}
|
||||
|
||||
public void restoreOriginalState(boolean force) {
|
||||
public void restoreOriginalState(Activity activity) {
|
||||
setActivity(activity);
|
||||
restoreOriginalState();
|
||||
}
|
||||
|
||||
private void restoreOriginalState() {
|
||||
restoreOriginalState(false);
|
||||
}
|
||||
|
||||
private void restoreOriginalState(boolean force) {
|
||||
if (!isSupported()) {
|
||||
Log.d(TAG, "restoreOriginalState: autoframerate not enabled... exiting...");
|
||||
return;
|
||||
@@ -104,10 +127,6 @@ public class AutoFrameRateHelper {
|
||||
Log.d(TAG, "Restore mode result: " + result);
|
||||
}
|
||||
|
||||
public void restoreOriginalState() {
|
||||
restoreOriginalState(false);
|
||||
}
|
||||
|
||||
public void setListener(AutoFrameRateListener listener) {
|
||||
mSyncHelper.setListener(listener);
|
||||
}
|
||||
@@ -143,12 +162,12 @@ public class AutoFrameRateHelper {
|
||||
mSyncHelper.applyModeChangeFix(mActivity.getWindow());
|
||||
}
|
||||
|
||||
public void setActivity(Activity activity) {
|
||||
private void resetState() {
|
||||
mSyncHelper.resetMode(mActivity.getWindow());
|
||||
}
|
||||
|
||||
private void setActivity(Activity activity) {
|
||||
mActivity = activity;
|
||||
mSyncHelper.setContext(activity);
|
||||
}
|
||||
|
||||
public void resetState() {
|
||||
mSyncHelper.resetMode(mActivity.getWindow());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,16 +6,16 @@ import android.os.Looper;
|
||||
|
||||
public class ModeSyncManager {
|
||||
private static ModeSyncManager sInstance;
|
||||
private final AutoFrameRateHelper mAutoFrameRateHelper;
|
||||
private FormatItem mFormatItem;
|
||||
private AutoFrameRateHelper mFrameRateHelper;
|
||||
|
||||
public ModeSyncManager(Activity activity) {
|
||||
mAutoFrameRateHelper = new AutoFrameRateHelper(activity);
|
||||
private ModeSyncManager() {
|
||||
// NOP
|
||||
}
|
||||
|
||||
public static ModeSyncManager instance(Activity activity) {
|
||||
public static ModeSyncManager instance() {
|
||||
if (sInstance == null) {
|
||||
sInstance = new ModeSyncManager(activity);
|
||||
sInstance = new ModeSyncManager();
|
||||
}
|
||||
|
||||
return sInstance;
|
||||
@@ -26,11 +26,22 @@ public class ModeSyncManager {
|
||||
}
|
||||
|
||||
public void restore(Activity activity) {
|
||||
if (mFormatItem != null) {
|
||||
mAutoFrameRateHelper.setActivity(activity);
|
||||
mAutoFrameRateHelper.apply(mFormatItem);
|
||||
if (mFrameRateHelper == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
//new Handler(Looper.myLooper()).postDelayed(() -> mAutoFrameRateHelper.apply(mFormatItem), 5_000);
|
||||
new Handler(Looper.myLooper()).postDelayed(() -> applyAfr(activity), 1_000);
|
||||
}
|
||||
|
||||
private void applyAfr(Activity activity) {
|
||||
if (mFormatItem != null) {
|
||||
mFrameRateHelper.apply(mFormatItem, activity);
|
||||
} else {
|
||||
mFrameRateHelper.restoreOriginalState(activity);
|
||||
}
|
||||
}
|
||||
|
||||
public void setAfrHelper(AutoFrameRateHelper frameRateHelper) {
|
||||
mFrameRateHelper = frameRateHelper;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public abstract class LeanbackActivity extends FragmentActivity {
|
||||
mLongClickManager = new LongClickManager();
|
||||
mBackgroundManager = new UriBackgroundManager(this);
|
||||
mViewManager = ViewManager.instance(this);
|
||||
mModeSyncManager = ModeSyncManager.instance(this);
|
||||
mModeSyncManager = ModeSyncManager.instance();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,14 +4,19 @@ import android.content.pm.ActivityInfo;
|
||||
import android.os.Build.VERSION;
|
||||
import android.os.Bundle;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import com.liskovsoft.sharedutils.mylogger.Log;
|
||||
import com.liskovsoft.smartyoutubetv2.tv.R;
|
||||
|
||||
public class AppSettingsActivity extends FragmentActivity {
|
||||
private static final String TAG = AppSettingsActivity.class.getSimpleName();
|
||||
private AppSettingsFragment mFragment;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
setupActivity();
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.fragment_video_settings);
|
||||
setContentView(R.layout.fragment_app_settings);
|
||||
mFragment = (AppSettingsFragment) getFragmentManager().findFragmentById(R.id.app_settings_fragment);
|
||||
}
|
||||
|
||||
private void setupActivity() {
|
||||
@@ -23,4 +28,13 @@ public class AppSettingsActivity extends FragmentActivity {
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
// NOTE: Fragment's onDestroy/onDestroyView are not reliable way to catch dialog finish
|
||||
Log.d(TAG, "Dialog finish");
|
||||
mFragment.onFinish();
|
||||
|
||||
super.finish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceFragment;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import com.liskovsoft.sharedutils.helpers.Helpers;
|
||||
import com.liskovsoft.sharedutils.mylogger.Log;
|
||||
import com.liskovsoft.smartyoutubetv2.common.app.presenters.AppSettingsPresenter;
|
||||
import com.liskovsoft.smartyoutubetv2.common.app.presenters.AppSettingsPresenter.SettingsCategory;
|
||||
import com.liskovsoft.smartyoutubetv2.common.app.views.AppSettingsView;
|
||||
@@ -24,6 +25,7 @@ import java.util.List;
|
||||
|
||||
public class AppSettingsFragment extends LeanbackSettingsFragment
|
||||
implements DialogPreference.TargetFragment, AppSettingsView {
|
||||
private static final String TAG = AppSettingsFragment.class.getSimpleName();
|
||||
private AppPreferenceFragment mPreferenceFragment;
|
||||
private AppSettingsPresenter mSettingsPresenter;
|
||||
|
||||
@@ -45,6 +47,7 @@ public class AppSettingsFragment extends LeanbackSettingsFragment
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
Log.d(TAG, "onDestroy");
|
||||
mSettingsPresenter.unregister(this);
|
||||
}
|
||||
|
||||
@@ -108,6 +111,10 @@ public class AppSettingsFragment extends LeanbackSettingsFragment
|
||||
return super.onPreferenceDisplayDialog(caller, pref);
|
||||
}
|
||||
|
||||
public void onFinish() {
|
||||
mSettingsPresenter.onClose();
|
||||
}
|
||||
|
||||
public static class AppPreferenceFragment extends LeanbackPreferenceFragment {
|
||||
private static final String TAG = AppPreferenceFragment.class.getSimpleName();
|
||||
private List<SettingsCategory> mCategories;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<fragment
|
||||
android:id="@+id/videoSettingsFragment"
|
||||
android:id="@+id/app_settings_fragment"
|
||||
android:name="com.liskovsoft.smartyoutubetv2.tv.ui.settings.AppSettingsFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
Reference in New Issue
Block a user