Compare commits

...

9 Commits

Author SHA1 Message Date
dependabot[bot]
4a957a8b6d
Merge 1535b668ae into 4c6ec35d95 2024-05-26 21:45:38 +08:00
Horis
4c6ec35d95 优化 2024-05-25 12:18:51 +08:00
Horis
b30680c02e
Merge pull request #3946 from mgz0227/master
替换被封域名
2024-05-24 11:09:29 +08:00
miaogongzi
a3685c4358 替换被封域名 2024-05-24 02:33:20 +08:00
Horis
a2cc621917 优化 2024-05-22 10:34:26 +08:00
Horis
27571f5b06 优化 2024-05-19 17:38:16 +08:00
Horis
0d63180dd0 优化 2024-05-18 00:04:54 +08:00
Horis
9e5cefc47c 优化 2024-05-17 21:57:15 +08:00
dependabot[bot]
1535b668ae
Bump org.apache.commons:commons-text from 1.11.0 to 1.12.0
Bumps org.apache.commons:commons-text from 1.11.0 to 1.12.0.

---
updated-dependencies:
- dependency-name: org.apache.commons:commons-text
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-05-06 04:22:15 +00:00
16 changed files with 107 additions and 96 deletions

View File

@ -1,7 +1,7 @@
[
{
"uploadUrl": "https://sy.mgz6.cc/shuyuan,{\"method\":\"POST\",\"body\": {\"file\": \"fileRequest\"},\"type\": \"multipart/form-data\"}",
"downloadUrlRule": "$.data@js:if (result == '') \n '' \n else \n 'https://shuyuan.mgz6.cc/shuyuan/' + result",
"uploadUrl": "https://sy.mgz6.com/shuyuan,{\"method\":\"POST\",\"body\": {\"file\": \"fileRequest\"},\"type\": \"multipart/form-data\"}",
"downloadUrlRule": "$.data@js:if (result == '') \n '' \n else \n 'https://shuyuan.mgz6.com/shuyuan/' + result",
"summary": "喵公子网盘①(有效期7天)",
"compress": false
},

View File

@ -93,7 +93,7 @@ object ReadBook : CoroutineScope by MainScope() {
readRecord.readTime = appDb.readRecordDao.getReadTime(book.name) ?: 0
chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl)
contentProcessor = ContentProcessor.get(book)
durChapterIndex = min(book.durChapterIndex, chapterSize - 1).coerceAtLeast(0)
durChapterIndex = book.durChapterIndex
durChapterPos = book.durChapterPos
isLocalBook = book.isLocal
clearTextChapter()

View File

@ -179,6 +179,14 @@ class EpubFile(var book: Book) {
elements.select("img[src=\"cover.jpeg\"]").forEachIndexed { i, it ->
if (i > 0) it.remove()
}
elements.select("img").forEach {
if (it.attributesSize() <= 1) {
return@forEach
}
val src = it.attr("src")
it.clearAttributes()
it.attr("src", src)
}
val tag = Book.rubyTag
if (book.getDelTag(tag)) {
elements.select("rp, rt").remove()

View File

@ -303,9 +303,7 @@ class ReadBookActivity : BaseReadBookActivity(),
if (bookChanged) {
bookChanged = false
ReadBook.callBack = this
viewModel.initData(intent) {
upMenu()
}
viewModel.initData(intent)
} else {
//web端阅读时app处于阅读界面本地记录会覆盖web保存的进度在此处恢复
ReadBook.webBookProgress?.let {

View File

@ -116,6 +116,9 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
ReadBook.loadOrUpContent()
checkLocalBookFileExist(book)
} else {
if (ReadBook.durChapterIndex > ReadBook.chapterSize - 1) {
ReadBook.durChapterIndex = ReadBook.chapterSize - 1
}
ReadBook.loadContent(resetPageOffset = false)
checkLocalBookFileExist(book)
}

View File

@ -159,6 +159,7 @@ class MoreConfigDialog : DialogFragment() {
}
PreferKey.optimizeRender -> {
ChapterProvider.upStyle()
ReadBook.callBack?.upPageAnim(true)
ReadBook.loadContent(false)
}

View File

@ -200,7 +200,7 @@ class ReadStyleDialog : BaseDialogFragment(R.layout.dialog_read_book_style),
override fun selectFont(path: String) {
if (path != ReadBookConfig.textFont) {
ReadBookConfig.textFont = path
postEvent(EventBus.UP_CONFIG, arrayListOf(8, 5))
postEvent(EventBus.UP_CONFIG, arrayListOf(2, 5))
}
}

View File

@ -278,17 +278,18 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
if (textPos.compare(selectEnd) <= 0) {
selectStart.upData(pos = textPos)
upSelectedStart(
if (textPos.isTouch) textColumn.start else textColumn.end,
if (textPos.columnIndex < textLine.columns.lastIndex) textColumn.start else textColumn.end,
textLine.lineBottom + relativeOffset,
textLine.lineTop + relativeOffset
)
} else {
reverseStartCursor = true
reverseEndCursor = false
selectEnd.columnIndex++
selectStartMoveIndex(selectEnd)
selectEnd.upData(textPos)
upSelectedEnd(
if (selectEnd.isTouch || selectEnd.isLast) textColumn.end else textColumn.start,
if (textPos.columnIndex > -1) textColumn.end else textColumn.start,
textLine.lineBottom + relativeOffset
)
}
@ -307,16 +308,17 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
if (textPos.compare(selectStart) >= 0) {
selectEnd.upData(textPos)
upSelectedEnd(
if (selectEnd.isTouch || selectEnd.isLast) textColumn.end else textColumn.start,
if (textPos.columnIndex > -1) textColumn.end else textColumn.start,
textLine.lineBottom + relativeOffset
)
} else {
reverseEndCursor = true
reverseStartCursor = false
selectStart.columnIndex--
selectEndMoveIndex(selectStart)
selectStart.upData(textPos)
upSelectedStart(
if (textPos.isTouch) textColumn.start else textColumn.end,
if (textPos.columnIndex < textLine.columns.lastIndex) textColumn.start else textColumn.end,
textLine.lineBottom + relativeOffset,
textLine.lineTop + relativeOffset
)
@ -418,11 +420,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
}
}
val isLast = columns.first().start < x
val charIndex = if (isLast) columns.lastIndex else 0
val charIndex = if (isLast) columns.lastIndex + 1 else -1
val textColumn = if (isLast) columns.last() else columns.first()
touched.invoke(
relativeOffset,
TextPos(relativePos, lineIndex, charIndex, false, isLast),
TextPos(relativePos, lineIndex, charIndex),
textPage, textLine, textColumn
)
return
@ -489,18 +491,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
relativePagePos: Int,
lineIndex: Int,
charIndex: Int,
isTouch: Boolean,
isLast: Boolean = false
) {
selectStart.relativePagePos = relativePagePos
selectStart.lineIndex = lineIndex
selectStart.columnIndex = charIndex
selectStart.isTouch = isTouch
selectStart.isLast = isLast
val textLine = relativePage(relativePagePos).getLine(lineIndex)
val textColumn = textLine.getColumn(charIndex)
upSelectedStart(
textColumn.start,
if (charIndex < textLine.columns.lastIndex) textColumn.start else textColumn.end,
textLine.lineBottom + relativeOffset(relativePagePos),
textLine.lineTop + relativeOffset(relativePagePos)
)
@ -508,7 +506,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
}
fun selectStartMoveIndex(textPos: TextPos) = textPos.run {
selectStartMoveIndex(relativePagePos, lineIndex, columnIndex, isTouch, isLast)
selectStartMoveIndex(relativePagePos, lineIndex, columnIndex)
}
/**
@ -518,22 +516,21 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
relativePage: Int,
lineIndex: Int,
charIndex: Int,
isTouch: Boolean,
isLast: Boolean = false
) {
selectEnd.relativePagePos = relativePage
selectEnd.lineIndex = lineIndex
selectEnd.columnIndex = charIndex
selectEnd.isTouch = isTouch
selectEnd.isLast = isLast
val textLine = relativePage(relativePage).getLine(lineIndex)
val textColumn = textLine.getColumn(charIndex)
upSelectedEnd(textColumn.end, textLine.lineBottom + relativeOffset(relativePage))
upSelectedEnd(
if (charIndex > -1) textColumn.end else textColumn.start,
textLine.lineBottom + relativeOffset(relativePage)
)
upSelectChars()
}
fun selectEndMoveIndex(textPos: TextPos) = textPos.run {
selectEndMoveIndex(relativePagePos, lineIndex, columnIndex, isTouch, isLast)
selectEndMoveIndex(relativePagePos, lineIndex, columnIndex)
}
private fun upSelectChars() {
@ -553,8 +550,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
val compareStart = textPos.compare(selectStart)
val compareEnd = textPos.compare(selectEnd)
column.selected = when {
compareStart == 0 -> selectStart.isTouch
compareEnd == 0 -> selectEnd.isTouch || selectEnd.isLast
compareStart == 0 -> true
compareEnd == 0 -> true
compareStart > 0 && compareEnd < 0 -> true
else -> false
}
@ -624,19 +621,19 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
if (column is TextColumn) {
when {
compareStart == 0 -> {
if (selectStart.isTouch) {
if (textPos.columnIndex < textLine.columns.lastIndex) {
builder.append(column.charData)
}
if (
textLine.isParagraphEnd
&& charIndex == textLine.charSize - 1
&& charIndex == textLine.columns.lastIndex
&& compareEnd != 0
) {
builder.append("\n")
}
}
compareEnd == 0 -> if (selectEnd.isTouch || selectEnd.isLast) {
compareEnd == 0 -> if (textPos.columnIndex > -1) {
builder.append(column.charData)
}
@ -644,7 +641,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
builder.append(column.charData)
if (
textLine.isParagraphEnd
&& charIndex == textLine.charSize - 1
&& charIndex == textLine.columns.lastIndex
) {
builder.append("\n")
}

View File

@ -404,17 +404,9 @@ class PageView(context: Context) : FrameLayout(context) {
fun selectStartMoveIndex(
relativePagePos: Int,
lineIndex: Int,
charIndex: Int,
isTouch: Boolean = true,
isLast: Boolean = false
charIndex: Int
) {
binding.contentTextView.selectStartMoveIndex(
relativePagePos,
lineIndex,
charIndex,
isTouch,
isLast
)
binding.contentTextView.selectStartMoveIndex(relativePagePos, lineIndex, charIndex)
}
fun selectStartMoveIndex(textPos: TextPos) {
@ -428,17 +420,9 @@ class PageView(context: Context) : FrameLayout(context) {
fun selectEndMoveIndex(
relativePagePos: Int,
lineIndex: Int,
charIndex: Int,
isTouch: Boolean = true,
isLast: Boolean = false
charIndex: Int
) {
binding.contentTextView.selectEndMoveIndex(
relativePagePos,
lineIndex,
charIndex,
isTouch,
isLast
)
binding.contentTextView.selectEndMoveIndex(relativePagePos, lineIndex, charIndex)
}
fun selectEndMoveIndex(textPos: TextPos) {

View File

@ -200,6 +200,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
}
MotionEvent.ACTION_MOVE -> {
if (!pressDown) return true
val absX = abs(startX - event.x)
val absY = abs(startY - event.y)
if (!isMove) {
@ -443,9 +444,13 @@ class ReadView(context: Context, attrs: AttributeSet) :
curPage.selectText(x, y) { textPos ->
val compare = initialTextPos.compare(textPos)
when {
compare >= 0 -> {
compare > 0 -> {
curPage.selectStartMoveIndex(textPos)
curPage.selectEndMoveIndex(initialTextPos)
curPage.selectEndMoveIndex(
initialTextPos.relativePagePos,
initialTextPos.lineIndex,
initialTextPos.columnIndex - 1
)
}
else -> {

View File

@ -11,30 +11,22 @@ data class TextPos(
var relativePagePos: Int,
var lineIndex: Int,
var columnIndex: Int,
var isTouch: Boolean = true,
var isLast: Boolean = false
) {
fun upData(
relativePos: Int,
lineIndex: Int,
charIndex: Int,
isTouch: Boolean,
isLast: Boolean
) {
this.relativePagePos = relativePos
this.lineIndex = lineIndex
this.columnIndex = charIndex
this.isTouch = isTouch
this.isLast = isLast
}
fun upData(pos: TextPos) {
relativePagePos = pos.relativePagePos
lineIndex = pos.lineIndex
columnIndex = pos.columnIndex
isTouch = pos.isTouch
isLast = pos.isLast
}
fun compare(pos: TextPos): Int {
@ -65,8 +57,6 @@ data class TextPos(
relativePagePos = 0
lineIndex = -1
columnIndex = -1
isTouch = true
isLast = false
}
fun isSelected(): Boolean {

View File

@ -881,7 +881,9 @@ object ChapterProvider {
tPaint.typeface = titleFont
tPaint.textSize = with(ReadBookConfig) { textSize + titleSize }.toFloat().spToPx()
tPaint.isAntiAlias = true
tPaint.isLinearText = true
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q && AppConfig.optimizeRender) {
tPaint.isLinearText = true
}
//正文
val cPaint = TextPaint()
cPaint.color = ReadBookConfig.textColor
@ -889,7 +891,9 @@ object ChapterProvider {
cPaint.typeface = textFont
cPaint.textSize = ReadBookConfig.textSize.toFloat().spToPx()
cPaint.isAntiAlias = true
cPaint.isLinearText = true
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q && AppConfig.optimizeRender) {
cPaint.isLinearText = true
}
return Pair(tPaint, cPaint)
}

View File

@ -14,6 +14,8 @@ import androidx.appcompat.widget.PopupMenu
import androidx.appcompat.widget.SearchView
import androidx.core.os.bundleOf
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
@ -50,6 +52,7 @@ import io.legado.app.utils.ACache
import io.legado.app.utils.applyTint
import io.legado.app.utils.cnCompare
import io.legado.app.utils.dpToPx
import io.legado.app.utils.flowWithLifecycleFirst
import io.legado.app.utils.hideSoftInput
import io.legado.app.utils.isAbsUrl
import io.legado.app.utils.launch
@ -68,6 +71,7 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.isActive
@ -98,7 +102,6 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
override var sortAscending = true
private set
private var snackBar: Snackbar? = null
private var isPaused = false
private val qrResult = registerForActivityResult(QrCodeResult()) {
it ?: return@registerForActivityResult
showDialogFragment(ImportBookSourceDialog(it))
@ -125,6 +128,19 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
}
}
}
private val groupMenuLifecycleOwner = object : LifecycleOwner {
private val registry = LifecycleRegistry(this)
override val lifecycle: Lifecycle get() = registry
fun onMenuOpened() {
registry.handleLifecycleEvent(Lifecycle.Event.ON_START)
}
fun onMenuClosed() {
registry.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
}
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
initRecyclerView()
@ -372,12 +388,17 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
private fun initLiveDataGroup() {
lifecycleScope.launch {
appDb.bookSourceDao.flowGroups().conflate().collect {
groups.clear()
groups.addAll(it)
upGroupMenu()
delay(500)
}
appDb.bookSourceDao.flowGroups()
.flowWithLifecycle(lifecycle)
.flowWithLifecycleFirst(groupMenuLifecycleOwner.lifecycle)
.conflate()
.distinctUntilChanged()
.collect {
groups.clear()
groups.addAll(it)
upGroupMenu()
delay(500)
}
}
}
@ -400,6 +421,20 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
}
}
override fun onMenuOpened(featureId: Int, menu: Menu): Boolean {
if (menu === groupMenu) {
groupMenuLifecycleOwner.onMenuOpened()
}
return super.onMenuOpened(featureId, menu)
}
override fun onPanelClosed(featureId: Int, menu: Menu) {
super.onPanelClosed(featureId, menu)
if (menu === groupMenu) {
groupMenuLifecycleOwner.onMenuClosed()
}
}
private fun initSelectActionBar() {
binding.selectActionBar.setMainActionText(R.string.delete)
binding.selectActionBar.inflateMenu(R.menu.book_source_sel)
@ -637,16 +672,6 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
}
}
override fun onPause() {
super.onPause()
isPaused = true
}
override fun onResume() {
super.onResume()
isPaused = false
}
override fun upCountView() {
binding.selectActionBar
.upCountView(adapter.selection.size, adapter.itemCount)

View File

@ -4,17 +4,14 @@ package io.legado.app.utils
import android.annotation.SuppressLint
import android.content.Context
import android.view.View
import android.widget.TextView
import android.widget.Toast
import androidx.cardview.widget.CardView
import androidx.fragment.app.Fragment
import io.legado.app.BuildConfig
import io.legado.app.R
import io.legado.app.databinding.ViewToastBinding
import io.legado.app.help.config.AppConfig
import io.legado.app.lib.theme.bottomBackground
import io.legado.app.lib.theme.getPrimaryTextColor
import splitties.views.inflate
import splitties.systemservices.layoutInflater
private var toast: Toast? = null
@ -31,14 +28,13 @@ fun Context.toastOnUi(message: CharSequence?, duration: Int = Toast.LENGTH_SHORT
kotlin.runCatching {
toast?.cancel()
toast = Toast(this)
val toastView: View = inflate(R.layout.view_toast)
toast?.view = toastView
val cardView = toastView.findViewById<CardView>(R.id.cv_content)
cardView.setCardBackgroundColor(bottomBackground)
val isLight = ColorUtils.isColorLight(bottomBackground)
val textView = toastView.findViewById<TextView>(R.id.tv_text)
textView.setTextColor(getPrimaryTextColor(isLight))
textView.text = message
ViewToastBinding.inflate(layoutInflater).run {
toast?.view = root
cvToast.setCardBackgroundColor(bottomBackground)
tvText.setTextColor(getPrimaryTextColor(isLight))
tvText.text = message
}
toast?.duration = duration
toast?.show()
}

View File

@ -6,7 +6,7 @@
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:id="@+id/cv_content"
android:id="@+id/cv_toast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="10dp"

View File

@ -5,7 +5,7 @@ ksp = "1.9.23-1.0.20"
agp = "8.3.2"
appcompat = "1.6.1"
colorpicker = "1.1.0"
commonsText = "1.11.0"
commonsText = "1.12.0"
constraintlayout = "2.1.4"
core = "1.12.0"
firebaseBom = "32.8.1"