fix: rename auto rotate to follow device orientation

This commit is contained in:
Fredrik Burmester
2025-03-07 07:54:13 +01:00
parent 3d7889e19a
commit 887f30e739
14 changed files with 98 additions and 116 deletions

View File

@@ -279,7 +279,7 @@ function Layout() {
useEffect(() => {
// If the user has auto rotate enabled, unlock the orientation
if (Platform.isTV) return;
if (settings.autoRotate === true) {
if (settings.followDeviceOrientation === true) {
ScreenOrientation.unlockAsync();
} else {
// If the user has auto rotate disabled, lock the orientation to portrait

View File

@@ -60,7 +60,7 @@ export const OtherSettings: React.FC = () => {
const disabled = useMemo(
() =>
pluginSettings?.autoRotate?.locked === true &&
pluginSettings?.followDeviceOrientation?.locked === true &&
pluginSettings?.defaultVideoOrientation?.locked === true &&
pluginSettings?.safeAreaInControlsEnabled?.locked === true &&
pluginSettings?.showCustomMenuLinks?.locked === true &&
@@ -76,32 +76,47 @@ export const OtherSettings: React.FC = () => {
ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT,
];
const orientationTranslations = useMemo(
() => ({
[ScreenOrientation.OrientationLock.DEFAULT]: "home.settings.other.orientations.DEFAULT",
[ScreenOrientation.OrientationLock.PORTRAIT_UP]: "home.settings.other.orientations.PORTRAIT_UP",
[ScreenOrientation.OrientationLock.LANDSCAPE_LEFT]: "home.settings.other.orientations.LANDSCAPE_LEFT",
[ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT]: "home.settings.other.orientations.LANDSCAPE_RIGHT",
}),
[]
);
if (!settings) return null;
return (
<DisabledSetting disabled={disabled}>
<ListGroup title={t("home.settings.other.other_title")} className="">
<ListItem title={t("home.settings.other.auto_rotate")} disabled={pluginSettings?.autoRotate?.locked}>
<ListItem
title={t("home.settings.other.follow_device_orientation")}
disabled={pluginSettings?.followDeviceOrientation?.locked}
>
<Switch
value={settings.autoRotate}
disabled={pluginSettings?.autoRotate?.locked}
onValueChange={(value) => updateSettings({ autoRotate: value })}
value={settings.followDeviceOrientation}
disabled={pluginSettings?.followDeviceOrientation?.locked}
onValueChange={(value) => updateSettings({ followDeviceOrientation: value })}
/>
</ListItem>
<ListItem
title={t("home.settings.other.video_orientation")}
disabled={pluginSettings?.defaultVideoOrientation?.locked || settings.autoRotate}
disabled={pluginSettings?.defaultVideoOrientation?.locked || settings.followDeviceOrientation}
>
<Dropdown
data={orientations}
disabled={pluginSettings?.defaultVideoOrientation?.locked || settings.autoRotate}
disabled={pluginSettings?.defaultVideoOrientation?.locked || settings.followDeviceOrientation}
keyExtractor={String}
titleExtractor={(item) => ScreenOrientationEnum[item]}
titleExtractor={(item) => t(ScreenOrientationEnum[item])}
title={
<TouchableOpacity className="flex flex-row items-center justify-between py-3 pl-3">
<Text className="mr-1 text-[#8E8D91]">
{t(ScreenOrientationEnum[settings.defaultVideoOrientation])}
{t(
orientationTranslations[settings.defaultVideoOrientation as keyof typeof orientationTranslations]
) || "Unknown Orientation"}
</Text>
<Ionicons name="chevron-expand-sharp" size={18} color="#5A5960" />
</TouchableOpacity>

View File

@@ -9,21 +9,17 @@ export const useOrientationSettings = () => {
const [settings] = useSettings();
useEffect(() => {
if (settings?.autoRotate) {
ScreenOrientation.lockAsync(
ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT
);
if (settings?.followDeviceOrientation) {
ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT);
} else if (settings?.defaultVideoOrientation) {
ScreenOrientation.lockAsync(settings.defaultVideoOrientation);
}
return () => {
if (settings?.autoRotate) {
if (settings?.followDeviceOrientation) {
ScreenOrientation.unlockAsync();
} else {
ScreenOrientation.lockAsync(
ScreenOrientation.OrientationLock.PORTRAIT_UP
);
ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT_UP);
}
};
}, [settings]);

View File

@@ -113,7 +113,7 @@
},
"other": {
"other_title": "Sonstiges",
"auto_rotate": "Automatische Drehung",
"follow_device_orientation": "Automatische Drehung",
"video_orientation": "Videoausrichtung",
"orientation": "Ausrichtung",
"orientations": {

View File

@@ -113,7 +113,7 @@
},
"other": {
"other_title": "Other",
"auto_rotate": "Auto rotate",
"follow_device_orientation": "Follow device orientation",
"video_orientation": "Video orientation",
"orientation": "Orientation",
"orientations": {
@@ -138,7 +138,7 @@
"hide_libraries": "Hide Libraries",
"select_liraries_you_want_to_hide": "Select the libraries you want to hide from the Library tab and home page sections.",
"disable_haptic_feedback": "Disable Haptic Feedback",
"default_quality": "Default quality",
"default_quality": "Default quality"
},
"downloads": {
"downloads_title": "Downloads",
@@ -222,7 +222,7 @@
"connected": "Connected",
"could_not_connect": "Could not connect",
"invalid_url": "Invalid URL"
},
}
},
"sessions": {
"title": "Sessions",

View File

@@ -113,7 +113,7 @@
},
"other": {
"other_title": "Otros",
"auto_rotate": "Rotación automática",
"follow_device_orientation": "Rotación automática",
"video_orientation": "Orientación de vídeo",
"orientation": "Orientación",
"orientations": {

View File

@@ -113,7 +113,7 @@
},
"other": {
"other_title": "Autres",
"auto_rotate": "Rotation automatique",
"follow_device_orientation": "Rotation automatique",
"video_orientation": "Orientation vidéo",
"orientation": "Orientation",
"orientations": {
@@ -139,7 +139,6 @@
"select_liraries_you_want_to_hide": "Sélectionnez les bibliothèques que vous souhaitez masquer dans longlet Bibliothèque et les sections de la page daccueil.",
"disable_haptic_feedback": "Désactiver le retour haptique",
"default_quality": "Qualité par défaut"
},
"downloads": {
"downloads_title": "Téléchargements",

View File

@@ -113,7 +113,7 @@
},
"other": {
"other_title": "Altro",
"auto_rotate": "Rotazione automatica",
"follow_device_orientation": "Rotazione automatica",
"video_orientation": "Orientamento del video",
"orientation": "Orientamento",
"orientations": {

View File

@@ -113,7 +113,7 @@
},
"other": {
"other_title": "その他",
"auto_rotate": "画面の自動回転",
"follow_device_orientation": "画面の自動回転",
"video_orientation": "動画の向き",
"orientation": "向き",
"orientations": {

View File

@@ -113,7 +113,7 @@
},
"other": {
"other_title": "Andere",
"auto_rotate": "Automatisch draaien",
"follow_device_orientation": "Automatisch draaien",
"video_orientation": "Video oriëntatie",
"orientation": "Oriëntatie",
"orientations": {

View File

@@ -113,7 +113,7 @@
},
"other": {
"other_title": "Diğer",
"auto_rotate": "Otomatik Döndürme",
"follow_device_orientation": "Otomatik Döndürme",
"video_orientation": "Video Yönü",
"orientation": "Yön",
"orientations": {

View File

@@ -113,7 +113,7 @@
},
"other": {
"other_title": "其他",
"auto_rotate": "自动旋转",
"follow_device_orientation": "自动旋转",
"video_orientation": "视频方向",
"orientation": "方向",
"orientations": {

View File

@@ -113,7 +113,7 @@
},
"other": {
"other_title": "其他",
"auto_rotate": "自動旋轉",
"follow_device_orientation": "自動旋轉",
"video_orientation": "影片方向",
"orientation": "方向",
"orientations": {

View File

@@ -26,30 +26,17 @@ export type DownloadOption = {
value: DownloadQuality;
};
export const ScreenOrientationEnum: Record<
ScreenOrientation.OrientationLock,
string
> = {
[ScreenOrientation.OrientationLock.DEFAULT]:
"home.settings.other.orientations.DEFAULT",
[ScreenOrientation.OrientationLock.ALL]:
"home.settings.other.orientations.ALL",
[ScreenOrientation.OrientationLock.PORTRAIT]:
"home.settings.other.orientations.PORTRAIT",
[ScreenOrientation.OrientationLock.PORTRAIT_UP]:
"home.settings.other.orientations.PORTRAIT_UP",
[ScreenOrientation.OrientationLock.PORTRAIT_DOWN]:
"home.settings.other.orientations.PORTRAIT_DOWN",
[ScreenOrientation.OrientationLock.LANDSCAPE]:
"home.settings.other.orientations.LANDSCAPE",
[ScreenOrientation.OrientationLock.LANDSCAPE_LEFT]:
"home.settings.other.orientations.LANDSCAPE_LEFT",
[ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT]:
"home.settings.other.orientations.LANDSCAPE_RIGHT",
[ScreenOrientation.OrientationLock.OTHER]:
"home.settings.other.orientations.OTHER",
[ScreenOrientation.OrientationLock.UNKNOWN]:
"home.settings.other.orientations.UNKNOWN",
export const ScreenOrientationEnum: Record<ScreenOrientation.OrientationLock, string> = {
[ScreenOrientation.OrientationLock.DEFAULT]: "home.settings.other.orientations.DEFAULT",
[ScreenOrientation.OrientationLock.ALL]: "home.settings.other.orientations.ALL",
[ScreenOrientation.OrientationLock.PORTRAIT]: "home.settings.other.orientations.PORTRAIT",
[ScreenOrientation.OrientationLock.PORTRAIT_UP]: "home.settings.other.orientations.PORTRAIT_UP",
[ScreenOrientation.OrientationLock.PORTRAIT_DOWN]: "home.settings.other.orientations.PORTRAIT_DOWN",
[ScreenOrientation.OrientationLock.LANDSCAPE]: "home.settings.other.orientations.LANDSCAPE",
[ScreenOrientation.OrientationLock.LANDSCAPE_LEFT]: "home.settings.other.orientations.LANDSCAPE_LEFT",
[ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT]: "home.settings.other.orientations.LANDSCAPE_RIGHT",
[ScreenOrientation.OrientationLock.OTHER]: "home.settings.other.orientations.OTHER",
[ScreenOrientation.OrientationLock.UNKNOWN]: "home.settings.other.orientations.UNKNOWN",
};
export const DownloadOptions: DownloadOption[] = [
@@ -116,12 +103,12 @@ export type HomeSectionNextUpResolver = {
export enum VideoPlayer {
// NATIVE, //todo: changes will make this a lot more easier to implement if we want. delete if not wanted
VLC_3,
VLC_4
VLC_4,
}
export type Settings = {
home?: Home | null;
autoRotate?: boolean;
followDeviceOrientation?: boolean;
forceLandscapeInVideoPlayer?: boolean;
deviceProfile?: "Expo" | "Native" | "Old";
mediaListCollectionIds?: string[];
@@ -170,7 +157,7 @@ export type StreamyfinPluginConfig = {
const defaultValues: Settings = {
home: null,
autoRotate: true,
followDeviceOrientation: true,
forceLandscapeInVideoPlayer: false,
deviceProfile: "Expo",
mediaListCollectionIds: [],
@@ -214,8 +201,7 @@ const defaultValues: Settings = {
const loadSettings = (): Partial<Settings> => {
try {
const jsonValue = storage.getString("settings");
const loadedValues: Partial<Settings> =
jsonValue != null ? JSON.parse(jsonValue) : {};
const loadedValues: Partial<Settings> = jsonValue != null ? JSON.parse(jsonValue) : {};
return loadedValues;
} catch (error) {
@@ -237,9 +223,7 @@ const saveSettings = (settings: Settings) => {
};
export const settingsAtom = atom<Partial<Settings> | null>(null);
export const pluginSettingsAtom = atom(
storage.get<PluginLockableSettings>(STREAMYFIN_PLUGIN_SETTINGS)
);
export const pluginSettingsAtom = atom(storage.get<PluginLockableSettings>(STREAMYFIN_PLUGIN_SETTINGS));
export const useSettings = () => {
const [api] = useAtom(apiAtom);
@@ -275,12 +259,13 @@ export const useSettings = () => {
}, [api]);
const updateSettings = (update: Partial<Settings>) => {
if (settings) {
const newSettings = { ..._settings, ...update };
if (!_settings) return;
const hasChanges = Object.entries(update).some(([key, value]) => _settings[key as keyof Settings] !== value);
if (hasChanges) {
// Merge default settings, current settings, and updates to ensure all required properties exist
const newSettings = { ...defaultValues, ..._settings, ...update } as Settings;
setSettings(newSettings);
// @ts-expect-error
saveSettings(newSettings);
}
};
@@ -290,18 +275,13 @@ export const useSettings = () => {
// use user settings first and fallback on admin setting if required.
const settings: Settings = useMemo(() => {
let unlockedPluginDefaults = {} as Settings;
const overrideSettings = Object.entries(pluginSettings || {}).reduce(
(acc, [key, setting]) => {
const overrideSettings = Object.entries(pluginSettings || {}).reduce((acc, [key, setting]) => {
if (setting) {
const { value, locked } = setting;
// Make sure we override default settings with plugin settings when they are not locked.
// Admin decided what users defaults should be and grants them the ability to change them too.
if (
locked === false &&
value &&
_settings?.[key as keyof Settings] !== value
) {
if (locked === false && value && _settings?.[key as keyof Settings] !== value) {
unlockedPluginDefaults = Object.assign(unlockedPluginDefaults, {
[key as keyof Settings]: value,
});
@@ -312,9 +292,7 @@ export const useSettings = () => {
});
}
return acc;
},
{} as Settings
);
}, {} as Settings);
return {
...defaultValues,
@@ -323,11 +301,5 @@ export const useSettings = () => {
};
}, [_settings, pluginSettings]);
return [
settings,
updateSettings,
pluginSettings,
setPluginSettings,
refreshStreamyfinPluginSettings,
] as const;
return [settings, updateSettings, pluginSettings, setPluginSettings, refreshStreamyfinPluginSettings] as const;
};