pull/84/head
kunfei 5 years ago
parent d353007988
commit 7824d93855
  1. 4
      app/src/main/java/io/legado/app/data/entities/Book.kt
  2. 1
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  3. 37
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  4. 2
      app/src/main/res/menu/read_book.xml

@ -53,6 +53,10 @@ data class Book(
return origin == BookType.local
}
fun isTxt(): Boolean {
return isLocalBook() && originName.endsWith(".txt", true)
}
@Ignore
@IgnoredOnParcel
override var variableMap: HashMap<String, String>? = null

@ -39,6 +39,7 @@ object ReadBook {
durChapterIndex = book.durChapterIndex
durPageIndex = book.durChapterPos
isLocalBook = book.origin == BookType.local
webBook = null
App.db.bookSourceDao().getBookSource(book.origin)?.let {
webBook = WebBook(it)
}

@ -13,7 +13,9 @@ import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.EditText
import androidx.core.view.get
import androidx.core.view.isVisible
import androidx.core.view.size
import androidx.lifecycle.Observer
import com.jaredrummler.android.colorpicker.ColorPickerDialogListener
import io.legado.app.App
@ -67,7 +69,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
private val requestCodeChapterList = 568
private val requestCodeEditSource = 111
private val requestCodeReplace = 312
private var replaceUseMenu: MenuItem? = null
private var menu: Menu? = null
override val viewModel: ReadBookViewModel
get() = getViewModel(ReadBookViewModel::class.java)
@ -147,16 +149,34 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.read_book, menu)
replaceUseMenu = menu.findItem(R.id.menu_enable_replace)
upMenu()
return super.onCompatCreateOptionsMenu(menu)
}
override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
this.menu = menu
upMenu()
return super.onPrepareOptionsMenu(menu)
}
private fun upMenu() {
ReadBook.book?.let {
replaceUseMenu?.isChecked = it.useReplaceRule
menu?.let { menu ->
ReadBook.book?.let { book ->
val onLine = !book.isLocalBook()
for (i in 0 until menu.size) {
val item = menu[i]
when (item.groupId) {
R.id.menu_group_on_line -> item.isVisible = onLine
R.id.menu_group_local -> item.isVisible = !onLine
R.id.menu_group_text -> item.isVisible = book.isTxt()
R.id.menu_group_login ->
item.isVisible = !ReadBook.webBook?.bookSource?.loginUrl.isNullOrEmpty()
else -> if (item.itemId == R.id.menu_enable_replace) {
item.isChecked = book.useReplaceRule
}
}
}
}
}
}
/**
@ -221,7 +241,8 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
ReadBook.durChapterIndex,
ReadBook.durPageIndex,
textChapter!!.title,
editContent)
editContent
)
App.db.bookmarkDao().insert(bookmark)
}
}
@ -237,7 +258,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
}
R.id.menu_enable_replace -> ReadBook.book?.let {
it.useReplaceRule = !it.useReplaceRule
replaceUseMenu?.isChecked = it.useReplaceRule
menu?.findItem(R.id.menu_enable_replace)?.isChecked = it.useReplaceRule
}
}
return super.onCompatOptionsItemSelected(item)

@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
tools:context=".ui.main.MainActivity">
<group android:id="@+id/menuOnLine">
<group android:id="@+id/menu_group_on_line">
<item
android:id="@+id/menu_change_source"
android:icon="@drawable/ic_exchange"

Loading…
Cancel
Save