- Updated `MainViewModel` to skip synchronization until folder migration is completed and added metadata syncing when opening books. - Modified folder migration to detach existing folder books (converting them to standard local files) before starting a fresh scan. - Added `detachAllFolderBooks` to `RecentFileDao` and `RecentFilesRepository` to facilitate the migration process. - Updated `MetadataExtractionWorker` to sync local metadata to the folder immediately after extraction. - Simplified `FolderSyncWorker` by removing legacy migration lookups and streamlining the reconciliation of local and remote metadata. - Updated `FolderMigrationDialog` UI text to reflect that books are now read directly from folders without duplication. - Fixed various indentation and formatting issues across several files.
93 lines
No EOL
4.5 KiB
Kotlin
93 lines
No EOL
4.5 KiB
Kotlin
/*
|
|
* Episteme Reader - A native Android document reader.
|
|
* Copyright (C) 2026 Episteme
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
* License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*
|
|
* mail: epistemereader@gmail.com
|
|
*/
|
|
// RecentFileDao.kt
|
|
package com.aryan.reader.data
|
|
|
|
import androidx.room.Dao
|
|
import androidx.room.Insert
|
|
import androidx.room.OnConflictStrategy
|
|
import androidx.room.Query
|
|
import kotlinx.coroutines.flow.Flow
|
|
|
|
@Dao
|
|
interface RecentFileDao {
|
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
suspend fun insertOrUpdateFile(file: RecentFileEntity)
|
|
|
|
@Query("SELECT * FROM recent_files WHERE isDeleted = 0 ORDER BY timestamp DESC")
|
|
fun getRecentFiles(): Flow<List<RecentFileEntity>>
|
|
|
|
@Query("SELECT * FROM recent_files WHERE sourceFolderUri = :sourceFolderUri AND isDeleted = 0")
|
|
suspend fun getFilesBySourceFolder(sourceFolderUri: String): List<RecentFileEntity>
|
|
|
|
@Query("SELECT * FROM recent_files")
|
|
suspend fun getAllFiles(): List<RecentFileEntity>
|
|
|
|
@Query("SELECT * FROM recent_files WHERE isDeleted = 0 ORDER BY timestamp DESC LIMIT :limit")
|
|
fun getRecentFilesList(limit: Int): List<RecentFileEntity>
|
|
|
|
@Query("DELETE FROM recent_files WHERE bookId IN (:bookIds)")
|
|
suspend fun deleteFilePermanently(bookIds: List<String>)
|
|
|
|
@Query("UPDATE recent_files SET isDeleted = 1, isAvailable = 0, lastModifiedTimestamp = :timestamp WHERE bookId IN (:bookIds)")
|
|
suspend fun markAsDeleted(bookIds: List<String>, timestamp: Long)
|
|
|
|
@Query("SELECT * FROM recent_files WHERE lastModifiedTimestamp > :sinceTimestamp")
|
|
suspend fun getModifiedSince(sinceTimestamp: Long): List<RecentFileEntity>
|
|
|
|
@Query("SELECT COUNT(*) FROM recent_files")
|
|
suspend fun count(): Int
|
|
|
|
@Query("SELECT * FROM recent_files WHERE bookId = :bookId")
|
|
suspend fun getFileByBookId(bookId: String): RecentFileEntity?
|
|
|
|
@Query("SELECT * FROM recent_files WHERE uriString = :uriString")
|
|
suspend fun getFileByUri(uriString: String): RecentFileEntity?
|
|
|
|
@Query("DELETE FROM recent_files WHERE sourceFolderUri = :sourceFolderUri")
|
|
suspend fun deleteFilesBySourceFolder(sourceFolderUri: String)
|
|
|
|
@Query("SELECT * FROM recent_files WHERE bookId LIKE :prefix || '%'")
|
|
suspend fun getFilesWithIdPrefix(prefix: String): List<RecentFileEntity>
|
|
|
|
@Query("DELETE FROM recent_files")
|
|
suspend fun clearAll()
|
|
|
|
@Query("UPDATE recent_files SET lastPositionCfi = :cfi, lastChapterIndex = :chapterIndex, locatorBlockIndex = :blockIndex, locatorCharOffset = :charOffset, progressPercentage = :progress, timestamp = :timestamp, lastModifiedTimestamp = :timestamp WHERE bookId = :bookId")
|
|
suspend fun updateEpubReadingPosition(bookId: String, cfi: String?, chapterIndex: Int, blockIndex: Int, charOffset: Int, progress: Float, timestamp: Long)
|
|
|
|
@Query("UPDATE recent_files SET lastPage = :page, progressPercentage = :progress, timestamp = :timestamp, lastModifiedTimestamp = :timestamp WHERE bookId = :bookId")
|
|
suspend fun updatePdfReadingPosition(bookId: String, page: Int, progress: Float, timestamp: Long)
|
|
|
|
@Query("UPDATE recent_files SET bookmarks = :bookmarksJson, lastModifiedTimestamp = :timestamp WHERE bookId = :bookId")
|
|
suspend fun updateBookmarks(bookId: String, bookmarksJson: String, timestamp: Long)
|
|
|
|
@Query("UPDATE recent_files SET isAvailable = 1, uriString = :uriString, timestamp = :timestamp, lastModifiedTimestamp = :timestamp WHERE bookId = :bookId")
|
|
suspend fun updateBookAvailability(bookId: String, uriString: String, timestamp: Long)
|
|
|
|
@Query("UPDATE recent_files SET isRecent = 0, lastModifiedTimestamp = :timestamp WHERE bookId IN (:bookIds)")
|
|
suspend fun markAsNotRecent(bookIds: List<String>, timestamp: Long)
|
|
|
|
@Query("SELECT * FROM recent_files WHERE sourceFolderUri IS NOT NULL AND coverImagePath IS NULL AND isDeleted = 0")
|
|
suspend fun getFolderBooksWithoutCovers(): List<RecentFileEntity>
|
|
|
|
@Query("UPDATE recent_files SET sourceFolderUri = NULL WHERE sourceFolderUri IS NOT NULL")
|
|
suspend fun detachAllFolderBooks()
|
|
} |