Improved the initializing of Bookmarks.

This commit is contained in:
MohitMaliFtechiz 2024-12-06 12:43:53 +05:30 committed by Kelson
parent 4c1c40a536
commit 9f84a38e7d

View File

@ -28,8 +28,8 @@ import io.reactivex.schedulers.Schedulers
import io.reactivex.subjects.BehaviorSubject import io.reactivex.subjects.BehaviorSubject
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.rx3.rxSingle import kotlinx.coroutines.rx3.rxSingle
import org.kiwix.kiwixmobile.core.CoreApp import org.kiwix.kiwixmobile.core.CoreApp
import org.kiwix.kiwixmobile.core.DarkModeConfig import org.kiwix.kiwixmobile.core.DarkModeConfig
@ -70,7 +70,6 @@ class LibkiwixBookmarks @Inject constructor(
private var bookmarksChanged: Boolean = false private var bookmarksChanged: Boolean = false
private var bookmarkList: List<LibkiwixBookmarkItem> = arrayListOf() private var bookmarkList: List<LibkiwixBookmarkItem> = arrayListOf()
private var libraryBooksList: List<String> = arrayListOf() private var libraryBooksList: List<String> = arrayListOf()
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
@Suppress("CheckResult") @Suppress("CheckResult")
private val bookmarkListBehaviour: BehaviorSubject<List<LibkiwixBookmarkItem>>? by lazy { private val bookmarkListBehaviour: BehaviorSubject<List<LibkiwixBookmarkItem>>? by lazy {
@ -101,18 +100,16 @@ class LibkiwixBookmarks @Inject constructor(
} }
init { init {
coroutineScope.launch { // Check if bookmark folder exist if not then create the folder first.
// Check if bookmark folder exist if not then create the folder first. if (runBlocking { !File(bookmarksFolderPath).isFileExist() }) File(bookmarksFolderPath).mkdir()
if (!File(bookmarksFolderPath).isFileExist()) File(bookmarksFolderPath).mkdir() // Check if library file exist if not then create the file to save the library with book information.
// Check if library file exist if not then create the file to save the library with book information. if (runBlocking { !libraryFile.isFileExist() }) libraryFile.createNewFile()
if (!libraryFile.isFileExist()) libraryFile.createNewFile() // set up manager to read the library from this file
// set up manager to read the library from this file manager.readFile(libraryFile.canonicalPath)
manager.readFile(libraryFile.canonicalPath) // Check if bookmark file exist if not then create the file to save the bookmarks.
// Check if bookmark file exist if not then create the file to save the bookmarks. if (runBlocking { !bookmarkFile.isFileExist() }) bookmarkFile.createNewFile()
if (!bookmarkFile.isFileExist()) bookmarkFile.createNewFile() // set up manager to read the bookmarks from this file
// set up manager to read the bookmarks from this file manager.readBookmarkFile(bookmarkFile.canonicalPath)
manager.readBookmarkFile(bookmarkFile.canonicalPath)
}
} }
fun bookmarks(): Flowable<List<Page>> = fun bookmarks(): Flowable<List<Page>> =