minor tweak, add the default behavior, add the OFF as label
This commit is contained in:
parent
e7244d9bbe
commit
ce48ef06a4
|
@ -113,7 +113,7 @@ const Video = React.memo(
|
|||
}
|
||||
|
||||
const handleAutoDownload = async () => {
|
||||
const isAutoDownloadEnabled = fetchAutoDownloadEnabled('imagesPreferenceDownload');
|
||||
const isAutoDownloadEnabled = fetchAutoDownloadEnabled('videoPreferenceDownload');
|
||||
if (isAutoDownloadEnabled) {
|
||||
await handleDownload();
|
||||
}
|
||||
|
|
|
@ -905,5 +905,6 @@
|
|||
"Images": "Images",
|
||||
"Video": "Video",
|
||||
"Wi_Fi_and_mobile_data":"Wi-Fi and mobile data",
|
||||
"Wi_Fi": "Wi-fi"
|
||||
"Wi_Fi": "Wi-fi",
|
||||
"Off": "Off"
|
||||
}
|
|
@ -891,5 +891,6 @@
|
|||
"Images": "Imagens",
|
||||
"Video": "Vídeo",
|
||||
"Wi_Fi_and_mobile_data":"Wi-Fi e dados móveis",
|
||||
"Wi_Fi": "Wi-fi"
|
||||
"Wi_Fi": "Wi-fi",
|
||||
"Off": "Desativado"
|
||||
}
|
|
@ -1,8 +1,4 @@
|
|||
export enum MediaDownloadOption {
|
||||
NEVER = 'never',
|
||||
WIFI_MOBILE_DATA = 'wifi_mobile_data',
|
||||
WIFI = 'wifi'
|
||||
}
|
||||
export type MediaDownloadOption = 'never' | 'wifi_mobile_data' | 'wifi';
|
||||
|
||||
export const IMAGES_PREFERENCE_DOWNLOAD = 'imagesPreferenceDownload';
|
||||
export const VIDEO_PREFERENCE_DOWNLOAD = 'videoPreferenceDownload';
|
||||
|
|
|
@ -13,10 +13,23 @@ type TMediaType = typeof IMAGES_PREFERENCE_DOWNLOAD | typeof AUDIO_PREFERENCE_DO
|
|||
|
||||
export const fetchAutoDownloadEnabled = (mediaType: TMediaType) => {
|
||||
const { internetType } = store.getState().app;
|
||||
const mediaDownloadPreference = userPreferences.getString(mediaType);
|
||||
const mediaDownloadPreference = userPreferences.getString<MediaDownloadOption>(mediaType);
|
||||
|
||||
let defaultValueByMediaType = false;
|
||||
if (mediaDownloadPreference === null) {
|
||||
if (mediaType === 'imagesPreferenceDownload') {
|
||||
// The same as MediaDownloadOption.WIFI_MOBILE_DATA
|
||||
defaultValueByMediaType = true;
|
||||
}
|
||||
if (mediaType === 'audioPreferenceDownload' || mediaType === 'videoPreferenceDownload') {
|
||||
// The same as MediaDownloadOption.WIFI
|
||||
defaultValueByMediaType = internetType === NetInfoStateType.wifi;
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
(mediaDownloadPreference === MediaDownloadOption.WIFI && internetType === NetInfoStateType.wifi) ||
|
||||
mediaDownloadPreference === MediaDownloadOption.WIFI_MOBILE_DATA
|
||||
(mediaDownloadPreference === 'wifi' && internetType === NetInfoStateType.wifi) ||
|
||||
mediaDownloadPreference === 'wifi_mobile_data' ||
|
||||
defaultValueByMediaType
|
||||
);
|
||||
};
|
||||
|
|
|
@ -110,22 +110,20 @@ export const searchMediaFileAsync = async ({
|
|||
mimeType?: string;
|
||||
urlToCache: string;
|
||||
}) => {
|
||||
let file;
|
||||
let filePath = '';
|
||||
|
||||
try {
|
||||
const serverUrl = store.getState().server.server;
|
||||
const serverUrlParsed = serverUrlParsedAsPath(serverUrl);
|
||||
const folderPath = `${LOCAL_DOCUMENT_PATH}${serverUrlParsed}${typeString[type]}`;
|
||||
const fileUrlSanitized = sanitizeString(urlToCache);
|
||||
const filename = `${fileUrlSanitized}.${getExtension(type, mimeType)}`;
|
||||
filePath = `${folderPath}${filename}`;
|
||||
const filePath = `${folderPath}${filename}`;
|
||||
await ensureDirAsync(folderPath);
|
||||
file = await FileSystem.getInfoAsync(filePath);
|
||||
} catch (e) {
|
||||
log(e);
|
||||
const file = await FileSystem.getInfoAsync(filePath);
|
||||
return { file, filePath };
|
||||
} catch (error) {
|
||||
log(error);
|
||||
return { file: null, filePath: '' };
|
||||
}
|
||||
return { file, filePath };
|
||||
};
|
||||
|
||||
export const deleteMediaFiles = async (serverUrl: string): Promise<void> => {
|
||||
|
|
|
@ -18,9 +18,9 @@ class UserPreferences {
|
|||
return this.mmkv;
|
||||
}
|
||||
|
||||
getString(key: string): string | null {
|
||||
getString<T = string>(key: string) {
|
||||
try {
|
||||
return this.mmkv.getString(key) ?? null;
|
||||
return (this.mmkv.getString(key) as T) ?? null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -13,18 +13,20 @@ const styles = StyleSheet.create({
|
|||
title: { ...sharedStyles.textRegular, fontSize: 16 }
|
||||
});
|
||||
|
||||
const OPTIONS: { label: string; value: MediaDownloadOption }[] = [
|
||||
type TOPTIONS = { label: string; value: MediaDownloadOption }[];
|
||||
|
||||
const OPTIONS: TOPTIONS = [
|
||||
{
|
||||
label: 'Wi_Fi_and_mobile_data',
|
||||
value: MediaDownloadOption.WIFI_MOBILE_DATA
|
||||
value: 'wifi_mobile_data'
|
||||
},
|
||||
{
|
||||
label: 'Wi_Fi',
|
||||
value: MediaDownloadOption.WIFI
|
||||
value: 'wifi'
|
||||
},
|
||||
{
|
||||
label: 'Never',
|
||||
value: MediaDownloadOption.NEVER
|
||||
value: 'never'
|
||||
}
|
||||
];
|
||||
|
||||
|
@ -44,7 +46,7 @@ const ListPicker = ({
|
|||
} & IBaseParams) => {
|
||||
const { showActionSheet, hideActionSheet } = useActionSheet();
|
||||
const { colors } = useTheme();
|
||||
const option = OPTIONS.find(option => option.value === value);
|
||||
const option = OPTIONS.find(option => option.value === value) || OPTIONS[2];
|
||||
|
||||
const getOptions = (): TActionSheetOptionsItem[] =>
|
||||
OPTIONS.map(i => ({
|
||||
|
@ -53,7 +55,7 @@ const ListPicker = ({
|
|||
hideActionSheet();
|
||||
onChangeValue(i.value);
|
||||
},
|
||||
right: option?.value === i.value ? () => <CustomIcon name={'check'} size={20} color={colors.tintActive} /> : undefined
|
||||
right: option.value === i.value ? () => <CustomIcon name={'check'} size={20} color={colors.tintActive} /> : undefined
|
||||
}));
|
||||
|
||||
return (
|
||||
|
@ -63,7 +65,7 @@ const ListPicker = ({
|
|||
onPress={() => showActionSheet({ options: getOptions() })}
|
||||
right={() => (
|
||||
<Text style={[styles.title, { color: colors.actionTintColor }]}>
|
||||
{option?.label ? I18n.t(option?.label, { defaultValue: option?.label }) : option?.label}
|
||||
{option.label === 'Never' ? I18n.t('Off') : I18n.t(option.label)}
|
||||
</Text>
|
||||
)}
|
||||
/>
|
||||
|
|
|
@ -15,16 +15,10 @@ import {
|
|||
const MediaAutoDownload = () => {
|
||||
const [imagesPreference, setImagesPreference] = useUserPreferences<MediaDownloadOption>(
|
||||
IMAGES_PREFERENCE_DOWNLOAD,
|
||||
MediaDownloadOption.NEVER
|
||||
);
|
||||
const [videoPreference, setVideoPreference] = useUserPreferences<MediaDownloadOption>(
|
||||
VIDEO_PREFERENCE_DOWNLOAD,
|
||||
MediaDownloadOption.NEVER
|
||||
);
|
||||
const [audioPreference, setAudioPreference] = useUserPreferences<MediaDownloadOption>(
|
||||
AUDIO_PREFERENCE_DOWNLOAD,
|
||||
MediaDownloadOption.NEVER
|
||||
'wifi_mobile_data'
|
||||
);
|
||||
const [videoPreference, setVideoPreference] = useUserPreferences<MediaDownloadOption>(VIDEO_PREFERENCE_DOWNLOAD, 'wifi');
|
||||
const [audioPreference, setAudioPreference] = useUserPreferences<MediaDownloadOption>(AUDIO_PREFERENCE_DOWNLOAD, 'wifi');
|
||||
|
||||
return (
|
||||
<SafeAreaView testID='security-privacy-view'>
|
||||
|
|
Loading…
Reference in New Issue