diff --git a/.gitignore b/.gitignore index eff32d4..fdaf87a 100644 --- a/.gitignore +++ b/.gitignore @@ -101,4 +101,6 @@ android/app/release-key.jks !.yarn/releases !.yarn/sdks !.yarn/versions -yarn.lock \ No newline at end of file +yarn.lock + +.env \ No newline at end of file diff --git a/src/screens/user-settings/SettingsScreen.tsx b/src/screens/user-settings/SettingsScreen.tsx index a2779e4..52ec35f 100644 --- a/src/screens/user-settings/SettingsScreen.tsx +++ b/src/screens/user-settings/SettingsScreen.tsx @@ -357,7 +357,7 @@ const SettingsScreen: React.FC = () => { /> Save Schedule to Device - Save your schedule as CSV to Downloads + Save your schedule as CSV diff --git a/src/utils/exportSchedule.ts b/src/utils/exportSchedule.ts index 00b83b3..41824ce 100644 --- a/src/utils/exportSchedule.ts +++ b/src/utils/exportSchedule.ts @@ -40,12 +40,7 @@ export class ExportScheduleUtility { console.log('Starting export with selectedRegisters:', this.selectedRegisters); console.log('Available registers:', Object.keys(this.registers)); - // Check storage permission first - const hasPermission = await this.checkStoragePermission(); - if (!hasPermission) { - Alert.alert('Permission Denied', 'Storage permission is required to save CSV files.'); - return null; - } + // No permission needed for app-specific external storage on Android 13+ if (this.selectedRegisters.length === 0) { Alert.alert('Export Failed', 'No registers selected for export.'); @@ -86,16 +81,20 @@ export class ExportScheduleUtility { return null; } - const path = `${RNFS.DownloadDirectoryPath}/${fileName}`; - console.log('Export path:', path); - - // Ensure the directory exists - const dirPath = RNFS.DownloadDirectoryPath; - const dirExists = await RNFS.exists(dirPath); + // WhatsApp-like: Save in Android/media/com.schedulex/ScheduleX + console.log('RNFS.ExternalStorageDirectoryPath:', RNFS.ExternalStorageDirectoryPath); + const scheduleXDir = `${RNFS.ExternalStorageDirectoryPath}/Android/media/com.schedulex/ScheduleX`; + const dirExists = await RNFS.exists(scheduleXDir); if (!dirExists) { - await RNFS.mkdir(dirPath); + try { + await RNFS.mkdir(scheduleXDir); + console.log('Created folder:', scheduleXDir); + } catch (e) { + console.error('Error creating folder:', e); + } } - + const path = `${scheduleXDir}/${fileName}`; + console.log('Export path:', path); const exists = await RNFS.exists(path); if (checkOnly && exists) { @@ -125,7 +124,7 @@ export class ExportScheduleUtility { if (result && result.exists) { Alert.alert( 'File Exists', - `File already exists in Downloads as ${result.fileName}. Download again?`, + `File already exists as ${result.fileName}. Download again?`, [ { text: 'Cancel', style: 'cancel' }, { @@ -133,16 +132,16 @@ export class ExportScheduleUtility { onPress: async () => { await this.exportSelectedRegistersCSV(false, true, customFileName); // force overwrite ToastAndroid.show( - `Saved to Downloads: ${result.fileName}`, - ToastAndroid.SHORT - ); + `Saved: ${result.fileName}\nPath: ${result.path}`, + ToastAndroid.LONG + ); } } ] ); } else if (result) { ToastAndroid.show( - `Saved to Downloads: ${result.fileName}`, + `Saved: ${result.fileName}\nPath: ${result.path}`, ToastAndroid.SHORT ); }