2023-06-07 15:09:43 +00:00
|
|
|
import { NetInfoStateType } from '@react-native-community/netinfo';
|
2023-05-11 23:20:48 +00:00
|
|
|
|
|
|
|
import {
|
|
|
|
IMAGES_PREFERENCE_DOWNLOAD,
|
|
|
|
AUDIO_PREFERENCE_DOWNLOAD,
|
|
|
|
VIDEO_PREFERENCE_DOWNLOAD,
|
|
|
|
MediaDownloadOption
|
2023-05-30 14:07:34 +00:00
|
|
|
} from '../constants';
|
|
|
|
import userPreferences from './userPreferences';
|
2023-06-07 15:09:43 +00:00
|
|
|
import { store } from '../store/auxStore';
|
2023-05-11 23:20:48 +00:00
|
|
|
|
|
|
|
type TMediaType = typeof IMAGES_PREFERENCE_DOWNLOAD | typeof AUDIO_PREFERENCE_DOWNLOAD | typeof VIDEO_PREFERENCE_DOWNLOAD;
|
|
|
|
|
2023-06-07 15:09:43 +00:00
|
|
|
export const fetchAutoDownloadEnabled = (mediaType: TMediaType) => {
|
|
|
|
const { internetType } = store.getState().app;
|
2023-06-09 15:16:09 +00:00
|
|
|
const mediaDownloadPreference = userPreferences.getString<MediaDownloadOption>(mediaType);
|
|
|
|
|
|
|
|
let defaultValueByMediaType = false;
|
|
|
|
if (mediaDownloadPreference === null) {
|
|
|
|
if (mediaType === 'imagesPreferenceDownload') {
|
2023-06-27 15:28:09 +00:00
|
|
|
// The same as 'wifi_mobile_data'
|
2023-06-09 15:16:09 +00:00
|
|
|
defaultValueByMediaType = true;
|
|
|
|
}
|
|
|
|
if (mediaType === 'audioPreferenceDownload' || mediaType === 'videoPreferenceDownload') {
|
2023-06-27 15:28:09 +00:00
|
|
|
// The same as 'wifi'
|
2023-06-09 15:16:09 +00:00
|
|
|
defaultValueByMediaType = internetType === NetInfoStateType.wifi;
|
|
|
|
}
|
|
|
|
}
|
2023-05-11 23:20:48 +00:00
|
|
|
|
|
|
|
return (
|
2023-06-09 15:16:09 +00:00
|
|
|
(mediaDownloadPreference === 'wifi' && internetType === NetInfoStateType.wifi) ||
|
|
|
|
mediaDownloadPreference === 'wifi_mobile_data' ||
|
|
|
|
defaultValueByMediaType
|
2023-05-11 23:20:48 +00:00
|
|
|
);
|
|
|
|
};
|