#1042 Add automatic backup option#1043
Merged
michaldrabik merged 8 commits intoSep 26, 2025
Merged
Conversation
This commit introduces the ability to schedule automatic backup exports. Key changes: - Added UI elements for selecting backup export schedule options (e.g., Every Hour, Every Day, Every Week). - Implemented `BackupExportScheduleWorker` to handle automatic backup creation based on the selected schedule. - Introduced use cases for reading and writing backup JSON to files (`ReadBackupJsonFromFileUseCase`, `WriteBackupJsonToFileUseCase`). - Added a use case for creating `BackupScheme` from JSON (`CreateBackupSchemeFromJsonUseCase`). - Added a use case for creating backup JSON string (`CreateBackupJsonUseCase`). - Implemented logic in `BackupExportViewModel` to manage export scheduling and one-off exports. - Updated `MainViewModel` and `MainActivity` to refresh the backup export schedule on app start. - Added `BackupFileName` object to generate standardized backup file names. - Updated string resources for new schedule options and messages. - Added necessary WorkManager and Hilt dependencies.
This commit introduces a mechanism to limit the number of automatic backup files stored. The system will now: - Retain only the 5 most recent backup files. - Automatically delete older backup files to manage storage space. - Backup files are identified by a specific prefix and file type (`showly_export_*.json`) and sorted by the timestamp embedded in their filenames for deletion priority. Additionally, constants related to backup file naming (prefix, file type, date/time pattern, and MIME type) have been centralized in `BackupFileName.kt`.
The initial delay for the `BackupExportScheduleWorker` was previously commented out. This commit re-enables the initial delay, ensuring that the periodic work request respects the scheduled duration and unit before its first execution.
michaldrabik
requested changes
Jun 29, 2025
michaldrabik
left a comment
Collaborator
There was a problem hiding this comment.
One thing I noticed now is that folder selection is popping up even if you turn the schedule off.
Contributor
Author
|
Good point, I'll fix that. |
This commit refactors the backup export scheduling logic: - Directly saves "OFF" schedule without requiring folder selection. - Shows confirmation snackbar after successfully selecting a schedule and folder. - Introduces `saveExportBackupScheduleOff()` in `BackupExportViewModel` for explicitly setting the schedule to OFF.
Contributor
Author
|
I've made the change to only ask for folder picker when the schedule is not OFF. Also moved around the snackbar message a little as I noticed that the message was not showing with the folder picker correctly. |
Collaborator
There was a problem hiding this comment.
Overall thanks for great job. Commented on 1 thing and it might be ready to ship. @marstaj
This commit updates the backup deletion logic in `BackupExportScheduleWorker`. Instead of relying on the filename (which includes a timestamp) for sorting, backups are now sorted by their actual last modified timestamp. This ensures more accurate deletion of the oldest backups when exceeding `MAX_BACKUPS`. - Modified `deleteOldBackups` to query `DocumentsContract.Document.COLUMN_LAST_MODIFIED`. - Changed `backupFiles` list to store a `Triple` including the last modified timestamp. - Updated sorting logic to use the last modified timestamp.
Contributor
Author
|
@michaldrabik sorry for the delay, I fixed this when I read your comment but then tested for a few days and forgot that I never pushed the code 🤦♂️. Hopefully everything is in order now. |
Collaborator
|
Ok thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#1042 Add automatic backup option