清理代码与更新界面

This commit is contained in:
HapeLee
2025-08-11 03:47:04 +08:00
parent 1607984faa
commit b2918df258
35 changed files with 108 additions and 132 deletions
@@ -10,6 +10,8 @@ import androidx.core.net.toUri
import androidx.lifecycle.lifecycleScope
import io.legato.kazusa.R
import io.legato.kazusa.base.BaseActivity
import io.legato.kazusa.constant.AppConst
import io.legato.kazusa.constant.AppConst.appInfo
import io.legato.kazusa.constant.AppLog
import io.legato.kazusa.databinding.ActivityAboutBinding
import io.legato.kazusa.help.CrashHandler
@@ -50,6 +52,8 @@ class AboutActivity : BaseActivity<ActivityAboutBinding>() {
super.onCreate(savedInstanceState)
setSupportActionBar(binding.topBar)
binding.tvVersion.text = appInfo.versionName
binding.btnUpdate.setOnClickListener {
checkUpdate()
}
@@ -56,7 +56,7 @@ class ExploreShowAdapter(context: Context, val callBack: CallBack) :
llKind.gone()
} else {
llKind.visible()
llKind.setLabels(kinds)
llKind.setLabels(kinds) {}
}
ivCover.load(
item.coverUrl,
@@ -361,7 +361,7 @@ class BookInfoActivity :
lbKind.gone()
} else {
lbKind.visible()
lbKind.setLabels(kinds)
lbKind.setLabels(kinds) {}
}
}
}
@@ -4,6 +4,7 @@ import android.content.Context
import android.os.Bundle
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.core.view.marginEnd
import androidx.recyclerview.widget.DiffUtil
import io.legato.kazusa.R
import io.legato.kazusa.base.adapter.DiffRecyclerAdapter
@@ -11,6 +12,7 @@ import io.legato.kazusa.base.adapter.ItemViewHolder
import io.legato.kazusa.data.entities.SearchBook
import io.legato.kazusa.databinding.ItemSearchBinding
import io.legato.kazusa.help.config.AppConfig
import io.legato.kazusa.utils.dpToPx
import io.legato.kazusa.utils.gone
import io.legato.kazusa.utils.visible
@@ -138,7 +140,9 @@ class SearchAdapter(context: Context, val callBack: CallBack) :
llKind.gone()
} else {
llKind.visible()
llKind.setLabels(kinds)
llKind.setLabels(kinds) { chips ->
chips.textSize = 12f
}
}
}
@@ -16,24 +16,20 @@ class LabelsBar @JvmOverloads constructor(
private val unUsedChips = arrayListOf<Chip>()
private val usedChips = arrayListOf<Chip>()
fun setLabels(labels: List<String>) {
clear()
labels.forEach {
addLabel(it)
}
}
fun setLabels(labels: Array<String>) {
setLabels(labels.toList())
}
fun clear() {
unUsedChips.addAll(usedChips)
usedChips.clear()
removeAllViews()
}
fun addLabel(label: String) {
fun setLabels(labels: List<String>, style: (Chip) -> Unit) {
clear()
labels.forEach {
addLabel(it, style)
}
}
fun addLabel(label: String, style: (Chip) -> Unit) {
val chip = if (unUsedChips.isEmpty()) {
Chip(context).apply {
isClickable = false
@@ -41,11 +37,9 @@ class LabelsBar @JvmOverloads constructor(
chipStartPadding = 8f
chipEndPadding = 8f
chipStrokeWidth = 0f
chipBackgroundColor = ColorStateList.valueOf(
context.themeColor(com.google.android.material.R.attr.colorPrimaryContainer)
)
usedChips.add(this)
}
} else {
@@ -53,7 +47,9 @@ class LabelsBar @JvmOverloads constructor(
usedChips.add(it)
}
}
style(chip) // 在这里应用外部传入的样式
chip.text = label
addView(chip)
}
}