Folder pdf annotation sync (#32)
* Implemented folder-based annotation synchronization and legacy book ID migration. - Added `syncLocalAnnotationsToFolder` and `importAnnotationBundle` to `RecentFilesRepository` to handle bundling ink, rich text, layouts, and text boxes into a single JSON sidecar file. - Introduced `saveAnnotationSidecar` and `getAnnotationSidecar` in `LocalSyncUtils` to manage hidden synchronization files in linked folders using SAF. - Updated `MainViewModel` to trigger annotation syncing on book close and added a migration utility for legacy book IDs. - Enhanced `FolderSyncWorker` to include a dedicated phase for importing newer annotation bundles from synchronized folders. - Fixed an ID mismatch edge case in `PdfViewerScreen` by initiating data migration when a legacy ID is detected. - Added `selectedBookId` to `ReaderScreenState` to better track the active document across the application. * fix(sync): resolve Syncthing file lock conflicts and annotation migration bug - Implement atomic saves (write-to-temp then rename) for annotation sidecars in `LocalSyncUtils` to prevent `.tmp` file locking and partial writes when using third-party sync tools like Syncthing. - Add robust conflict resolution for annotation sidecars (`resolveAndCleanAnnotationConflicts`) to automatically detect, keep the newest version, and clean up `.sync-conflict` files. - Fix a bug in `MainViewModel.checkAndMigrateLegacyBookId` where older legacy local files would blindly overwrite newly synced annotation files by adding a timestamp-based clobber check.
This commit is contained in:
parent
0b7bb53a28
commit
7e28c1c2b3
5 changed files with 464 additions and 57 deletions
|
|
@ -2255,7 +2255,15 @@ fun PdfViewerScreen(
|
|||
flatTableOfContents = emptyList()
|
||||
|
||||
val fastId = getFastFileId(context, pdfUri)
|
||||
currentBookId = fastId
|
||||
val selectedId = uiState.selectedBookId
|
||||
|
||||
if (selectedId != null && selectedId != fastId) {
|
||||
Timber.tag("FolderAnnotationSync").i("Detected ID mismatch. Legacy: $fastId, Selected: $selectedId. Initiating migration.")
|
||||
viewModel.checkAndMigrateLegacyBookId(fastId, selectedId)
|
||||
currentBookId = selectedId
|
||||
} else {
|
||||
currentBookId = fastId
|
||||
}
|
||||
|
||||
val oldDoc = pdfDocument
|
||||
val oldPfd = pfdState
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue