mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-18 11:55:38 -04:00
Improved the initializing of Bookmarks.
This commit is contained in:
parent
4c1c40a536
commit
9f84a38e7d
@ -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,19 +100,17 @@ 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 (!File(bookmarksFolderPath).isFileExist()) File(bookmarksFolderPath).mkdir()
|
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.
|
// Check if library file exist if not then create the file to save the library with book information.
|
||||||
if (!libraryFile.isFileExist()) libraryFile.createNewFile()
|
if (runBlocking { !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 (!bookmarkFile.isFileExist()) bookmarkFile.createNewFile()
|
if (runBlocking { !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>> =
|
||||||
flowableBookmarkList()
|
flowableBookmarkList()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user