pull/67/head
Administrator 5 years ago
commit cd9dd9132c
  1. 3
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  3. 8
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  4. 2
      app/src/main/java/io/legado/app/ui/widget/page/DataSource.kt
  5. 2
      app/src/main/java/io/legado/app/ui/widget/page/PageFactory.kt
  6. 11
      app/src/main/java/io/legado/app/ui/widget/page/PageView.kt
  7. 5
      app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt

@ -60,6 +60,9 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
override val viewModel: ReadBookViewModel
get() = getViewModel(ReadBookViewModel::class.java)
override val isInitFinish: Boolean
get() = viewModel.isInitFinish
private val requestCodeChapterList = 568
private val requestCodeEditSource = 111
private val requestCodeReplace = 31242

@ -19,6 +19,8 @@ import kotlinx.coroutines.withContext
class ReadBookViewModel(application: Application) : BaseViewModel(application) {
var isInitFinish = false
fun initData(intent: Intent) {
execute {
ReadBook.inBookshelf = intent.getBooleanExtra("inBookshelf", true)
@ -37,6 +39,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
private fun initBook(book: Book) {
if (ReadBook.book?.bookUrl != book.bookUrl) {
ReadBook.resetData(book)
isInitFinish = true
val count = App.db.bookChapterDao().getChapterCount(book.bookUrl)
if (count == 0) {
if (book.tocUrl.isEmpty()) {
@ -55,6 +58,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
ReadBook.saveRead()
}
} else {
isInitFinish = true
ReadBook.titleDate.postValue(book.name)
if (ReadBook.chapterSize == 0) {
if (book.tocUrl.isEmpty()) {

@ -49,7 +49,6 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
private var menu: Menu? = null
private var precisionSearchMenuItem: MenuItem? = null
private var groups = hashSetOf<String>()
private var queryText: String? = null
override fun onActivityCreated(savedInstanceState: Bundle?) {
viewModel.callBack = this
@ -108,9 +107,8 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
}
override fun onQueryTextChange(newText: String?): Boolean {
queryText = newText
if (queryText.isNullOrBlank()) viewModel.stop()
upHistory(queryText)
if (newText.isNullOrBlank()) viewModel.stop()
upHistory(newText)
return false
}
})
@ -182,7 +180,7 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
private fun openOrCloseHistory(open: Boolean) {
if (open) {
upHistory(queryText)
upHistory(search_view.query.toString())
ll_history.visibility = VISIBLE
} else {
ll_history.visibility = GONE

@ -9,8 +9,6 @@ interface DataSource {
fun getChapterPosition(): Int
fun getChapter(position: Int): TextChapter?
fun getCurrentChapter(): TextChapter?
fun getNextChapter(): TextChapter?

@ -2,8 +2,6 @@ package io.legado.app.ui.widget.page
abstract class PageFactory<DATA>(protected val dataSource: DataSource) {
abstract fun pageAt(index: Int): DATA?
abstract fun moveToFirst()
abstract fun moveToLast()

@ -190,20 +190,16 @@ class PageView(context: Context, attrs: AttributeSet) :
return ReadBook.durChapterIndex
}
override fun getChapter(position: Int): TextChapter? {
return ReadBook.textChapter(position)
}
override fun getCurrentChapter(): TextChapter? {
return ReadBook.textChapter(0)
return if (callBack?.isInitFinish == true) ReadBook.textChapter(0) else null
}
override fun getNextChapter(): TextChapter? {
return ReadBook.textChapter(1)
return if (callBack?.isInitFinish == true) ReadBook.textChapter(1) else null
}
override fun getPreviousChapter(): TextChapter? {
return ReadBook.textChapter(-1)
return if (callBack?.isInitFinish == true) ReadBook.textChapter(-1) else null
}
override fun hasNextChapter(): Boolean {
@ -248,5 +244,6 @@ class PageView(context: Context, attrs: AttributeSet) :
*/
fun clickCenter()
val isInitFinish: Boolean
}
}

@ -21,11 +21,6 @@ class TextPageFactory(dataSource: DataSource) : PageFactory<TextPage>(dataSource
}
}
override fun pageAt(index: Int): TextPage {
return dataSource.getCurrentChapter()?.page(index)
?: TextPage(index = index, title = "index:$index")
}
override fun moveToFirst() {
dataSource.setPageIndex(0)
}

Loading…
Cancel
Save