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) => {
|
2023-06-30 14:26:46 +00:00
|
|
|
const { netInfoState } = store.getState().app;
|
|
|
|
const mediaDownloadPreference = userPreferences.getString(mediaType) as MediaDownloadOption;
|
2023-06-09 15:16:09 +00:00
|
|
|
|
2023-07-03 17:28:22 +00:00
|
|
|
if (mediaDownloadPreference === 'wifi_mobile_data') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mediaDownloadPreference === 'wifi' && netInfoState === NetInfoStateType.wifi) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-06-09 15:16:09 +00:00
|
|
|
if (mediaDownloadPreference === null) {
|
|
|
|
if (mediaType === 'imagesPreferenceDownload') {
|
2023-07-03 17:28:22 +00:00
|
|
|
return true;
|
2023-06-09 15:16:09 +00:00
|
|
|
}
|
|
|
|
if (mediaType === 'audioPreferenceDownload' || mediaType === 'videoPreferenceDownload') {
|
2023-07-03 17:28:22 +00:00
|
|
|
return netInfoState === NetInfoStateType.wifi;
|
2023-06-09 15:16:09 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-11 23:20:48 +00:00
|
|
|
|
2023-07-03 17:28:22 +00:00
|
|
|
return false;
|
2023-05-11 23:20:48 +00:00
|
|
|
};
|