pull/1395/head
gedoor 3 years ago
parent 4c26190740
commit dc9798b847
  1. 10
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 9
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  3. 40
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  4. 29
      app/src/main/res/layout/view_read_menu.xml
  5. 9
      app/src/main/res/menu/book_read.xml
  6. 17
      app/src/main/res/menu/book_read_source.xml

@ -195,8 +195,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
for (i in 0 until menu.size) {
val item = menu[i]
when (item.groupId) {
R.id.menu_group_on_line,
R.id.menu_group_on_line_ns -> item.isVisible = onLine
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.isLocalTxt()
else -> when (item.itemId) {
@ -758,6 +757,13 @@ class ReadBookActivity : ReadBookBaseActivity(),
}
}
/**
* 禁用书源
*/
override fun disableSource() {
viewModel.disableSource()
}
/**
* 显示阅读样式配置
*/

@ -335,6 +335,15 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
}
}
fun disableSource() {
execute {
BookRead.bookSource?.let {
it.enabled = false
appDb.bookSourceDao.update(it)
}
}
}
override fun onCleared() {
super.onCleared()
if (BaseReadAloudService.pause) {

@ -5,10 +5,13 @@ import android.content.res.ColorStateList
import android.graphics.drawable.GradientDrawable
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View.OnClickListener
import android.view.View.OnLongClickListener
import android.view.WindowManager
import android.view.animation.Animation
import android.widget.FrameLayout
import android.widget.SeekBar
import androidx.appcompat.widget.PopupMenu
import androidx.core.view.isGone
import androidx.core.view.isVisible
import io.legado.app.R
@ -21,6 +24,7 @@ import io.legado.app.model.BookRead
import io.legado.app.ui.web.WebViewActivity
import io.legado.app.ui.widget.seekbar.SeekBarChangeListener
import io.legado.app.utils.*
import splitties.views.onClick
import splitties.views.onLongClick
/**
@ -44,7 +48,23 @@ class ReadMenu @JvmOverloads constructor(
.setPressedColor(ColorUtils.darkenColor(bgColor))
.create()
private var onMenuOutEnd: (() -> Unit)? = null
val showBrightnessView get() = context.getPrefBoolean(PreferKey.showBrightnessView, true)
private val showBrightnessView
get() = context.getPrefBoolean(
PreferKey.showBrightnessView,
true
)
private val sourceMenu by lazy {
PopupMenu(context, binding.tvSourceAction).apply {
inflate(R.menu.book_read_source)
setOnMenuItemClickListener {
when (it.itemId) {
R.id.menu_edit_source -> callBack.openSourceEditActivity()
R.id.menu_disable_source -> callBack.disableSource()
}
true
}
}
}
init {
initView()
@ -138,10 +158,7 @@ class ReadMenu @JvmOverloads constructor(
}
private fun bindEvent() = binding.run {
tvChapterName.setOnClickListener {
callBack.openSourceEditActivity()
}
tvChapterUrl.setOnClickListener {
val chapterViewClickListener = OnClickListener {
if (AppConfig.readUrlInBrowser) {
context.openUrl(tvChapterUrl.text.toString().substringBefore(",{"))
} else {
@ -153,7 +170,7 @@ class ReadMenu @JvmOverloads constructor(
}
}
}
tvChapterUrl.onLongClick {
val chapterViewLongClickListener = OnLongClickListener {
context.alert(R.string.Open_fan) {
setMessage(R.string.use_browser_open)
okButton {
@ -163,14 +180,24 @@ class ReadMenu @JvmOverloads constructor(
AppConfig.readUrlInBrowser = false
}
}
true
}
tvChapterName.setOnClickListener(chapterViewClickListener)
tvChapterName.setOnLongClickListener(chapterViewLongClickListener)
tvChapterUrl.setOnClickListener(chapterViewClickListener)
tvChapterUrl.setOnLongClickListener(chapterViewLongClickListener)
//登录
tvLogin.setOnClickListener {
callBack.showLogin()
}
//购买
tvPay.setOnClickListener {
callBack.payAction()
}
//书源操作
tvSourceAction.onClick {
sourceMenu.show()
}
//亮度跟随
ivBrightnessAuto.setOnClickListener {
context.putPrefBoolean("brightnessAuto", !brightnessAuto())
@ -365,6 +392,7 @@ class ReadMenu @JvmOverloads constructor(
fun showReadMenuHelp()
fun showLogin()
fun payAction()
fun disableSource()
}
}

@ -32,7 +32,6 @@
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textSize="12sp"
android:visibility="gone"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/tv_login"
@ -45,7 +44,6 @@
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textSize="12sp"
android:visibility="gone"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/tv_login"
@ -55,29 +53,46 @@
android:id="@+id/tv_login"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_margin="1dp"
android:gravity="center"
android:maxWidth="80dp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:text="@string/login"
android:layout_margin="1dp"
app:radius="1dp"
app:layout_constraintBottom_toBottomOf="@+id/tv_chapter_url"
app:layout_constraintRight_toLeftOf="@+id/tv_pay"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
app:radius="1dp" />
<io.legado.app.ui.widget.text.AccentBgTextView
android:id="@+id/tv_pay"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_margin="1dp"
android:gravity="center"
android:maxWidth="80dp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:text="@string/chapter_pay"
app:layout_constraintBottom_toBottomOf="@+id/tv_chapter_url"
app:layout_constraintRight_toLeftOf="@id/tv_source_action"
app:layout_constraintTop_toTopOf="parent"
app:radius="1dp" />
<io.legado.app.ui.widget.text.AccentBgTextView
android:id="@+id/tv_source_action"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_margin="1dp"
app:radius="1dp"
android:gravity="center"
android:maxWidth="80dp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:text="@string/book_source"
app:layout_constraintBottom_toBottomOf="@+id/tv_chapter_url"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
app:radius="1dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -49,15 +49,6 @@
android:title="@string/bookmark_add"
app:showAsAction="never" />
<group android:id="@+id/menu_group_on_line_ns">
<item
android:id="@+id/menu_disable_book_source"
android:title="@string/disable_book_source"
app:showAsAction="never" />
</group>
<item
android:id="@+id/menu_copy_text"
android:title="@string/copy_text"

@ -0,0 +1,17 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".ui.main.MainActivity"
tools:ignore="AlwaysShowAction">
<item
android:id="@+id/menu_edit_source"
android:title="@string/edit_book_source"
app:showAsAction="never" />
<item
android:id="@+id/menu_disable_source"
android:title="@string/disable_book_source"
app:showAsAction="never" />
</menu>
Loading…
Cancel
Save