mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-17 03:16:27 -04:00
Save bookmark when it does not exist in the file since bookmarks is now written in a file with libkiwix
This commit is contained in:
parent
88e30e19fd
commit
d68c890e8f
@ -56,15 +56,11 @@ class LibkiwixBookmarks @Inject constructor(
|
|||||||
manager.readBookmarkFile(bookmarkFile.canonicalPath)
|
manager.readBookmarkFile(bookmarkFile.canonicalPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun bookmarks(): Flowable<List<Page>> {
|
fun bookmarks(): Flowable<List<Page>> =
|
||||||
val bookMarksArray: Array<out Bookmark>? = library.getBookmarks(true)
|
Flowable.fromIterable(getBookmarksList())
|
||||||
val bookmarkList = bookMarksArray?.toList() ?: emptyList()
|
|
||||||
|
|
||||||
return Flowable.fromIterable(bookmarkList)
|
|
||||||
.map(::LibkiwixBookmarkItem)
|
.map(::LibkiwixBookmarkItem)
|
||||||
.toList()
|
.toList()
|
||||||
.toFlowable() as Flowable<List<Page>>
|
.toFlowable() as Flowable<List<Page>>
|
||||||
}
|
|
||||||
|
|
||||||
override fun pages(): Flowable<List<Page>> = bookmarks()
|
override fun pages(): Flowable<List<Page>> = bookmarks()
|
||||||
|
|
||||||
@ -86,12 +82,7 @@ class LibkiwixBookmarks @Inject constructor(
|
|||||||
update(zimFileReader.jniKiwixReader)
|
update(zimFileReader.jniKiwixReader)
|
||||||
}
|
}
|
||||||
addBookToLibrary(book)
|
addBookToLibrary(book)
|
||||||
|
val urls = getBookmarksList().map { it.url }
|
||||||
// Retrieve bookmarks from the library
|
|
||||||
val bookmarks = library.getBookmarks(true)
|
|
||||||
|
|
||||||
// Extract URLs from bookmarks
|
|
||||||
val urls = bookmarks.map { it.url }
|
|
||||||
|
|
||||||
// Emit the list of URLs
|
// Emit the list of URLs
|
||||||
emitter.onNext(urls)
|
emitter.onNext(urls)
|
||||||
@ -101,15 +92,17 @@ class LibkiwixBookmarks @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun saveBookmark(libkiwixBookmarkItem: LibkiwixBookmarkItem) {
|
fun saveBookmark(libkiwixBookmarkItem: LibkiwixBookmarkItem) {
|
||||||
addBookToLibrary(libkiwixBookmarkItem.libKiwixBook)
|
if (!isBookMarkExist(libkiwixBookmarkItem)) {
|
||||||
val bookmark = Bookmark().apply {
|
addBookToLibrary(libkiwixBookmarkItem.libKiwixBook)
|
||||||
bookId = libkiwixBookmarkItem.zimId
|
val bookmark = Bookmark().apply {
|
||||||
title = libkiwixBookmarkItem.title
|
bookId = libkiwixBookmarkItem.zimId
|
||||||
url = libkiwixBookmarkItem.url
|
title = libkiwixBookmarkItem.title
|
||||||
bookTitle = libkiwixBookmarkItem.libKiwixBook?.title ?: libkiwixBookmarkItem.zimId
|
url = libkiwixBookmarkItem.url
|
||||||
}
|
bookTitle = libkiwixBookmarkItem.libKiwixBook?.title ?: libkiwixBookmarkItem.zimId
|
||||||
library.addBookmark(bookmark).also {
|
}
|
||||||
writeBookMarksToFile()
|
library.addBookmark(bookmark).also {
|
||||||
|
writeBookMarksToFile()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,4 +123,11 @@ class LibkiwixBookmarks @Inject constructor(
|
|||||||
private fun writeBookMarksToFile() {
|
private fun writeBookMarksToFile() {
|
||||||
library.writeBookmarksToFile(bookmarkFile.canonicalPath)
|
library.writeBookmarksToFile(bookmarkFile.canonicalPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getBookmarksList() =
|
||||||
|
library.getBookmarks(true)?.toList() ?: emptyList()
|
||||||
|
|
||||||
|
private fun isBookMarkExist(libkiwixBookmarkItem: LibkiwixBookmarkItem): Boolean =
|
||||||
|
getBookmarksList()
|
||||||
|
.any { it.url == libkiwixBookmarkItem.bookmarkUrl && it.bookId == libkiwixBookmarkItem.zimId }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user