mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
添加单章换源
This commit is contained in:
@@ -35,10 +35,12 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
|
||||
Toolbar.OnMenuItemClickListener,
|
||||
ChangeChapterSourceAdapter.CallBack {
|
||||
|
||||
constructor(name: String, author: String) : this() {
|
||||
constructor(name: String, author: String, chapterIndex: Int, chapterTitle: String) : this() {
|
||||
arguments = Bundle().apply {
|
||||
putString("name", name)
|
||||
putString("author", author)
|
||||
putInt("chapterIndex", chapterIndex)
|
||||
putString("chapterTitle", chapterTitle)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,7 +199,7 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
|
||||
}
|
||||
|
||||
override fun openToc(searchBook: SearchBook) {
|
||||
|
||||
binding.clToc.visible()
|
||||
}
|
||||
|
||||
override val bookUrl: String?
|
||||
|
||||
@@ -41,6 +41,8 @@ class ChangeChapterSourceViewModel(application: Application) : BaseViewModel(app
|
||||
val searchStateData = MutableLiveData<Boolean>()
|
||||
var name: String = ""
|
||||
var author: String = ""
|
||||
var chapterIndex: Int = 0
|
||||
var chapterTitle: String = ""
|
||||
private var tasks = CompositeCoroutine()
|
||||
private var screenKey: String = ""
|
||||
private var bookSourceList = arrayListOf<BookSource>()
|
||||
@@ -96,6 +98,10 @@ class ChangeChapterSourceViewModel(application: Application) : BaseViewModel(app
|
||||
bundle.getString("author")?.let {
|
||||
author = it.replace(AppPattern.authorRegex, "")
|
||||
}
|
||||
bundle.getString("chapterTitle")?.let {
|
||||
chapterTitle = it
|
||||
}
|
||||
chapterIndex = bundle.getInt("chapterIndex")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package io.legado.app.ui.book.changesource
|
||||
|
||||
import android.content.Context
|
||||
import android.view.ViewGroup
|
||||
import io.legado.app.R
|
||||
import io.legado.app.base.adapter.ItemViewHolder
|
||||
import io.legado.app.base.adapter.RecyclerAdapter
|
||||
import io.legado.app.data.entities.Book
|
||||
import io.legado.app.data.entities.BookChapter
|
||||
import io.legado.app.databinding.ItemChapterListBinding
|
||||
import io.legado.app.lib.theme.ThemeUtils
|
||||
import io.legado.app.lib.theme.accentColor
|
||||
import io.legado.app.utils.getCompatColor
|
||||
import io.legado.app.utils.gone
|
||||
import io.legado.app.utils.visible
|
||||
|
||||
class ChangeChapterTocAdapter(context: Context, val callback: Callback) :
|
||||
RecyclerAdapter<BookChapter, ItemChapterListBinding>(context) {
|
||||
|
||||
override fun getViewBinding(parent: ViewGroup): ItemChapterListBinding {
|
||||
return ItemChapterListBinding.inflate(inflater, parent, false)
|
||||
}
|
||||
|
||||
override fun convert(
|
||||
holder: ItemViewHolder,
|
||||
binding: ItemChapterListBinding,
|
||||
item: BookChapter,
|
||||
payloads: MutableList<Any>
|
||||
) {
|
||||
binding.run {
|
||||
val isDur = callback.durChapterIndex() == item.index
|
||||
if (isDur) {
|
||||
tvChapterName.setTextColor(context.accentColor)
|
||||
} else {
|
||||
tvChapterName.setTextColor(context.getCompatColor(R.color.primaryText))
|
||||
}
|
||||
tvChapterName.text = item.title
|
||||
if (item.isVolume) {
|
||||
//卷名,如第一卷 突出显示
|
||||
tvChapterItem.setBackgroundColor(context.getCompatColor(R.color.btn_bg_press))
|
||||
} else {
|
||||
//普通章节 保持不变
|
||||
tvChapterItem.background =
|
||||
ThemeUtils.resolveDrawable(context, android.R.attr.selectableItemBackground)
|
||||
}
|
||||
if (!item.tag.isNullOrEmpty() && !item.isVolume) {
|
||||
//卷名不显示tag(更新时间规则)
|
||||
tvTag.text = item.tag
|
||||
tvTag.visible()
|
||||
} else {
|
||||
tvTag.gone()
|
||||
}
|
||||
ivChecked.setImageResource(R.drawable.ic_check)
|
||||
ivChecked.visible(isDur)
|
||||
}
|
||||
}
|
||||
|
||||
override fun registerListener(holder: ItemViewHolder, binding: ItemChapterListBinding) {
|
||||
holder.itemView.setOnClickListener {
|
||||
getItem(holder.layoutPosition)?.let {
|
||||
callback.openChapter(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface Callback {
|
||||
val book: Book?
|
||||
fun openChapter(bookChapter: BookChapter)
|
||||
fun durChapterIndex(): Int
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/background">
|
||||
android:background="@color/background"
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/tool_bar"
|
||||
@@ -13,11 +13,11 @@
|
||||
android:background="@color/background_menu"
|
||||
android:elevation="5dp"
|
||||
android:theme="?attr/actionBarStyle"
|
||||
app:titleTextAppearance="@style/ToolbarTitle"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay"
|
||||
app:displayHomeAsUp="false"
|
||||
app:fitStatusBar="false"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay"
|
||||
app:titleTextAppearance="@style/ToolbarTitle" />
|
||||
|
||||
<io.legado.app.ui.widget.anima.RefreshProgressBar
|
||||
android:id="@+id/refresh_progress_bar"
|
||||
@@ -29,30 +29,42 @@
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintTop_toBottomOf="@+id/refresh_progress_bar"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/refresh_progress_bar" />
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/cl_toc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:background="@color/background"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tool_bar"
|
||||
app:layout_constraintBottom_toBottomOf="parent">
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tool_bar">
|
||||
|
||||
<androidx.constraintlayout.utils.widget.ImageFilterView
|
||||
android:id="@+id/iv_hide_toc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="36dp"
|
||||
android:src="@drawable/ic_arrow_down"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:tint="@color/primaryText" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view_toc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/refresh_progress_bar"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/iv_hide_toc" />
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
<io.legado.app.ui.widget.anima.RotateLoading
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintTop_toTopOf="@+id/recycler_view_toc"
|
||||
app:layout_constraintLeft_toLeftOf="@+id/recycler_view_toc"
|
||||
app:layout_constraintRight_toRightOf="@+id/recycler_view_toc"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/recycler_view_toc" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Reference in New Issue
Block a user