Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,6 @@ android/app/release-key.jks
!.yarn/releases
!.yarn/sdks
!.yarn/versions
yarn.lock
yarn.lock

.env
2 changes: 1 addition & 1 deletion src/screens/user-settings/SettingsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ const SettingsScreen: React.FC = () => {
/>
<View style={styles.utilityTextContainer}>
<Text style={styles.utilityButtonText}>Save Schedule to Device</Text>
<Text style={styles.utilityButtonDescription}>Save your schedule as CSV to Downloads</Text>
<Text style={styles.utilityButtonDescription}>Save your schedule as CSV</Text>
</View>
</View>
</TouchableOpacity>
Expand Down
31 changes: 15 additions & 16 deletions src/utils/exportSchedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -125,15 +124,15 @@ 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' },
{
text: 'Yes',
onPress: async () => {
await this.exportSelectedRegistersCSV(false, true, customFileName); // force overwrite
ToastAndroid.show(
`Saved to Downloads: ${result.fileName}`,
`Saved to Storage: ${result.fileName}`,
ToastAndroid.SHORT
);
}
Expand Down