Skip to content

Commit

Permalink
Improved the initializing of Bookmarks.
Browse files Browse the repository at this point in the history
  • Loading branch information
MohitMaliDeveloper committed Dec 6, 2024
1 parent 99bbc34 commit af4924a
Showing 1 changed file with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import io.reactivex.schedulers.Schedulers
import io.reactivex.subjects.BehaviorSubject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.rx3.rxSingle
import org.kiwix.kiwixmobile.core.CoreApp
import org.kiwix.kiwixmobile.core.DarkModeConfig
Expand Down Expand Up @@ -70,7 +70,6 @@ class LibkiwixBookmarks @Inject constructor(
private var bookmarksChanged: Boolean = false
private var bookmarkList: List<LibkiwixBookmarkItem> = arrayListOf()
private var libraryBooksList: List<String> = arrayListOf()
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)

@Suppress("CheckResult")
private val bookmarkListBehaviour: BehaviorSubject<List<LibkiwixBookmarkItem>>? by lazy {
Expand Down Expand Up @@ -101,18 +100,16 @@ class LibkiwixBookmarks @Inject constructor(
}

init {
coroutineScope.launch {
// Check if bookmark folder exist if not then create the folder first.
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.
if (!libraryFile.isFileExist()) libraryFile.createNewFile()
// set up manager to read the library from this file
manager.readFile(libraryFile.canonicalPath)
// Check if bookmark file exist if not then create the file to save the bookmarks.
if (!bookmarkFile.isFileExist()) bookmarkFile.createNewFile()
// set up manager to read the bookmarks from this file
manager.readBookmarkFile(bookmarkFile.canonicalPath)
}
// Check if bookmark folder exist if not then create the folder first.
if (runBlocking { !File(bookmarksFolderPath).isFileExist() }) File(bookmarksFolderPath).mkdir()
// Check if library file exist if not then create the file to save the library with book information.
if (runBlocking { !libraryFile.isFileExist() }) libraryFile.createNewFile()
// set up manager to read the library from this file
manager.readFile(libraryFile.canonicalPath)
// Check if bookmark file exist if not then create the file to save the bookmarks.
if (runBlocking { !bookmarkFile.isFileExist() }) bookmarkFile.createNewFile()
// set up manager to read the bookmarks from this file
manager.readBookmarkFile(bookmarkFile.canonicalPath)
}

fun bookmarks(): Flowable<List<Page>> =
Expand Down

0 comments on commit af4924a

Please sign in to comment.