This commit is contained in:
Horis 2024-02-06 12:54:13 +08:00
parent cd8fe30880
commit 5e9eb6f0be
5 changed files with 22 additions and 17 deletions

View File

@ -5,16 +5,15 @@ import android.content.Context
import android.util.SparseArray import android.util.SparseArray
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.os.postDelayed
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding import androidx.viewbinding.ViewBinding
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.utils.buildMainHandler import io.legado.app.utils.buildMainHandler
import kotlinx.coroutines.ensureActive import kotlinx.coroutines.withTimeoutOrNull
import splitties.views.onLongClick import splitties.views.onLongClick
import java.util.* import java.util.Collections
/** /**
* Created by Invincible on 2017/11/24. * Created by Invincible on 2017/11/24.
@ -152,9 +151,16 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co
} }
diffJob?.cancel() diffJob?.cancel()
diffJob = Coroutine.async { diffJob = Coroutine.async {
val diffResult = DiffUtil.calculateDiff(callback) val diffResult = if (skipDiff) withTimeoutOrNull(500L) {
ensureActive() DiffUtil.calculateDiff(callback)
} else {
DiffUtil.calculateDiff(callback)
}
handler.post { handler.post {
if (diffResult == null) {
setItems(items)
return@post
}
if (this@RecyclerAdapter.items.isNotEmpty()) { if (this@RecyclerAdapter.items.isNotEmpty()) {
this@RecyclerAdapter.items.clear() this@RecyclerAdapter.items.clear()
} }
@ -165,12 +171,6 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co
onCurrentListChanged() onCurrentListChanged()
} }
} }
if (skipDiff) handler.postDelayed(500) {
if (diffJob?.isCompleted == false) {
diffJob?.cancel()
setItems(items)
}
}
} }
} }

View File

@ -10,8 +10,8 @@ import io.legado.app.data.entities.Book
abstract class BaseBooksAdapter<VB : ViewBinding>(context: Context) : abstract class BaseBooksAdapter<VB : ViewBinding>(context: Context) :
DiffRecyclerAdapter<Book, VB>(context) { DiffRecyclerAdapter<Book, VB>(context) {
override val diffItemCallback: DiffUtil.ItemCallback<Book> override val diffItemCallback: DiffUtil.ItemCallback<Book> =
get() = object : DiffUtil.ItemCallback<Book>() { object : DiffUtil.ItemCallback<Book>() {
override fun areItemsTheSame(oldItem: Book, newItem: Book): Boolean { override fun areItemsTheSame(oldItem: Book, newItem: Book): Boolean {
return oldItem.name == newItem.name return oldItem.name == newItem.name

View File

@ -40,12 +40,12 @@ class BooksAdapterList(
upRefresh(binding, item) upRefresh(binding, item)
upLastUpdateTime(binding, item) upLastUpdateTime(binding, item)
} else { } else {
tvRead.text = item.durChapterTitle
tvLast.text = item.latestChapterTitle
bundle.keySet().forEach { bundle.keySet().forEach {
when (it) { when (it) {
"name" -> tvName.text = item.name "name" -> tvName.text = item.name
"author" -> tvAuthor.text = item.author "author" -> tvAuthor.text = item.author
"dur" -> tvRead.text = item.durChapterTitle
"last" -> tvLast.text = item.latestChapterTitle
"cover" -> ivCover.load( "cover" -> ivCover.load(
item.getDisplayCover(), item.getDisplayCover(),
item.name, item.name,

View File

@ -106,6 +106,10 @@ class BadgeView @JvmOverloads constructor(
} }
override fun setBackgroundColor(color: Int) { override fun setBackgroundColor(color: Int) {
val background = background
if (background is ShapeDrawable && background.paint.color == color) {
return
}
setBackground(radius, color) setBackground(radius, color)
} }

View File

@ -7,7 +7,7 @@ import io.legado.app.BuildConfig
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import splitties.init.appCtx import splitties.init.appCtx
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.Date
import java.util.logging.FileHandler import java.util.logging.FileHandler
import java.util.logging.Level import java.util.logging.Level
import java.util.logging.LogRecord import java.util.logging.LogRecord
@ -40,7 +40,8 @@ object LogUtils {
private val fileHandler by lazy { private val fileHandler by lazy {
val root = appCtx.externalCacheDir ?: return@lazy null val root = appCtx.externalCacheDir ?: return@lazy null
val logFolder = FileUtils.createFolderIfNotExist(root, "logs") val logFolder = FileUtils.createFolderIfNotExist(root, "logs")
val logPath = FileUtils.getPath(root = logFolder, "appLog") val date = getCurrentDateStr(TIME_PATTERN)
val logPath = FileUtils.getPath(root = logFolder, "appLog-$date.txt")
FileHandler(logPath, 10240, 10).apply { FileHandler(logPath, 10240, 10).apply {
formatter = object : java.util.logging.Formatter() { formatter = object : java.util.logging.Formatter() {
override fun format(record: LogRecord): String { override fun format(record: LogRecord): String {