Skip to content

#1042 Add automatic backup option#1043

Merged
michaldrabik merged 8 commits into
trakt:masterfrom
marstaj:feature/1042_Add_automatic_backup_option
Sep 26, 2025
Merged

#1042 Add automatic backup option#1043
michaldrabik merged 8 commits into
trakt:masterfrom
marstaj:feature/1042_Add_automatic_backup_option

Conversation

@marstaj

@marstaj marstaj commented Jun 23, 2025

Copy link
Copy Markdown
Contributor

#1042 Add automatic backup option

marstaj added 4 commits June 22, 2025 15:22
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 michaldrabik self-requested a review June 29, 2025 09:08

@michaldrabik michaldrabik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I noticed now is that folder selection is popping up even if you turn the schedule off.

@marstaj

marstaj commented Jul 1, 2025

Copy link
Copy Markdown
Contributor Author

Good point, I'll fix that.

marstaj added 2 commits July 10, 2025 16:24
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.
@marstaj marstaj requested a review from michaldrabik July 10, 2025 22:54
@marstaj

marstaj commented Jul 10, 2025

Copy link
Copy Markdown
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.

@michaldrabik michaldrabik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@marstaj

marstaj commented Sep 19, 2025

Copy link
Copy Markdown
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.

@michaldrabik

Copy link
Copy Markdown
Collaborator

Ok thanks!

@michaldrabik michaldrabik merged commit 8305ffd into trakt:master Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants