This commit is contained in:
ocean 2025-09-12 18:17:47 +08:00
parent 5f1990f830
commit a19d095346
3 changed files with 16 additions and 16 deletions

View File

@ -12,7 +12,7 @@ interface RecentReadDao {
suspend fun insertOrUpdate(recentRead: RecentReadEntity)
@Query("SELECT * FROM recently_read WHERE filePath = :filePath")
suspend fun getByPdfHash(filePath: String): RecentReadEntity?
suspend fun getByFilePath(filePath: String): RecentReadEntity?
@Query("""
SELECT pdf_documents.*

View File

@ -19,7 +19,7 @@ data class NoteEntity(
@PrimaryKey(autoGenerate = true)
val id: Long = 0,
val filePath: String, // 关联PdfDocumentEntity的fileHash
val filePath: String, // 关联PdfDocumentEntity的 filePath
val pageNumber: Int, // 页码(从0开始)
val noteType: String, // 注释类型: HIGHLIGHT, TEXT_NOTE, DRAWING
val content: String, // 注释内容(文本或序列化的绘制数据)

View File

@ -89,7 +89,7 @@ class PdfRepository private constructor(context: Context) {
// 最近阅读相关操作
suspend fun addToRecent(filePath: String, page: Int = 0) {
val existing = recentDao.getByPdfHash(filePath)
val existing = recentDao.getByFilePath(filePath)
if (existing != null) {
recentDao.updateOpenTime(filePath)
} else {
@ -107,29 +107,29 @@ class PdfRepository private constructor(context: Context) {
suspend fun addBookmark(bookmark: BookmarkEntity): Long = bookmarkDao.insert(bookmark)
suspend fun updateBookmark(bookmark: BookmarkEntity) = bookmarkDao.update(bookmark)
suspend fun deleteBookmark(bookmark: BookmarkEntity) = bookmarkDao.delete(bookmark)
fun getBookmarksByPdf(pdfHash: String): Flow<List<BookmarkEntity>> =
bookmarkDao.getBookmarksByPdf(pdfHash)
fun getBookmarksByPdf(filePath: String): Flow<List<BookmarkEntity>> =
bookmarkDao.getBookmarksByPdf(filePath)
suspend fun getBookmarksByPage(pdfHash: String, page: Int): List<BookmarkEntity> =
bookmarkDao.getBookmarksByPage(pdfHash, page)
suspend fun getBookmarksByPage(filePath: String, page: Int): List<BookmarkEntity> =
bookmarkDao.getBookmarksByPage(filePath, page)
// 注释相关操作
suspend fun addNote(note: NoteEntity): Long = noteDao.insert(note)
suspend fun updateNote(note: NoteEntity) = noteDao.update(note)
suspend fun deleteNote(note: NoteEntity) = noteDao.delete(note)
fun getNotesByPdf(pdfHash: String): Flow<List<NoteEntity>> = noteDao.getNotesByPdf(pdfHash)
suspend fun getNotesByPage(pdfHash: String, page: Int): List<NoteEntity> =
noteDao.getNotesByPage(pdfHash, page)
fun getNotesByPdf(filePath: String): Flow<List<NoteEntity>> = noteDao.getNotesByPdf(filePath)
suspend fun getNotesByPage(filePath: String, page: Int): List<NoteEntity> =
noteDao.getNotesByPage(filePath, page)
fun getNotesByType(pdfHash: String, noteType: String): Flow<List<NoteEntity>> =
noteDao.getNotesByType(pdfHash, noteType)
fun getNotesByType(filePath: String, noteType: String): Flow<List<NoteEntity>> =
noteDao.getNotesByType(filePath, noteType)
// 组合查询
suspend fun getPdfWithDetails(pdfHash: String): Flow<PdfDetails> {
return combine(pdfDao.getByHash(pdfHash)?.let { kotlinx.coroutines.flow.flowOf(it) }
suspend fun getPdfWithDetails(filePath: String): Flow<PdfDetails> {
return combine(pdfDao.getByPath(filePath)?.let { kotlinx.coroutines.flow.flowOf(it) }
?: kotlinx.coroutines.flow.flowOf(null),
bookmarkDao.getBookmarksByPdf(pdfHash),
noteDao.getNotesByPdf(pdfHash)) { document, bookmarks, notes ->
bookmarkDao.getBookmarksByPdf(filePath),
noteDao.getNotesByPdf(filePath)) { document, bookmarks, notes ->
PdfDetails(document, bookmarks, notes)
}
}