|
|
@ -19,6 +19,7 @@ import kotlinx.coroutines.Dispatchers.IO |
|
|
|
class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
var inBookshelf = false |
|
|
|
var inBookshelf = false |
|
|
|
var bookData = MutableLiveData<Book>() |
|
|
|
var bookData = MutableLiveData<Book>() |
|
|
|
|
|
|
|
val chapterListFinish = MutableLiveData<Boolean>() |
|
|
|
var chapterSize = 0 |
|
|
|
var chapterSize = 0 |
|
|
|
var bookSource: BookSource? = null |
|
|
|
var bookSource: BookSource? = null |
|
|
|
var webBook: WebBook? = null |
|
|
|
var webBook: WebBook? = null |
|
|
@ -58,7 +59,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
durChapterIndex = count - 1 |
|
|
|
durChapterIndex = count - 1 |
|
|
|
} |
|
|
|
} |
|
|
|
chapterSize = count |
|
|
|
chapterSize = count |
|
|
|
callBack?.bookLoadFinish() |
|
|
|
chapterListFinish.postValue(true) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -82,7 +83,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
if (!cList.isNullOrEmpty()) { |
|
|
|
if (!cList.isNullOrEmpty()) { |
|
|
|
App.db.bookChapterDao().insert(*cList.toTypedArray()) |
|
|
|
App.db.bookChapterDao().insert(*cList.toTypedArray()) |
|
|
|
chapterSize = cList.size |
|
|
|
chapterSize = cList.size |
|
|
|
callBack?.bookLoadFinish() |
|
|
|
chapterListFinish.postValue(true) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
toast(R.string.error_load_toc) |
|
|
|
toast(R.string.error_load_toc) |
|
|
|
} |
|
|
|
} |
|
|
@ -175,7 +176,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
durPageIndex = 0 |
|
|
|
durPageIndex = 0 |
|
|
|
} |
|
|
|
} |
|
|
|
saveRead() |
|
|
|
saveRead() |
|
|
|
callBack?.bookLoadFinish() |
|
|
|
chapterListFinish.postValue(true) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun saveRead() { |
|
|
|
fun saveRead() { |
|
|
@ -194,7 +195,6 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interface CallBack { |
|
|
|
interface CallBack { |
|
|
|
fun bookLoadFinish() |
|
|
|
|
|
|
|
fun contentLoadFinish(bookChapter: BookChapter, content: String) |
|
|
|
fun contentLoadFinish(bookChapter: BookChapter, content: String) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |