Update UI

This commit is contained in:
HapeLee
2025-06-03 03:02:00 +08:00
parent 96d2d65511
commit 63a3dfafbc
51 changed files with 437 additions and 457 deletions
@@ -157,7 +157,7 @@ internal class AndroidAlertBuilder(override val ctx: Context) : AlertBuilder<Ale
}
override fun show(): AlertDialog {
var dialog = builder.show().applyTint()
var dialog = builder.show()
if (AppConfig.isEInkMode) {
dialog.window?.run {
val attr = attributes
@@ -435,7 +435,6 @@ class ReadMenu @JvmOverloads constructor(
}
})
//搜索
fabSearch.setOnClickListener {
runMenuOut {
@@ -8,6 +8,7 @@ import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.viewModels
import io.legado.app.R
import io.legado.app.base.BaseBottomSheetDialogFragment
import io.legado.app.base.BaseDialogFragment
import io.legado.app.base.BaseViewModel
import io.legado.app.constant.AppLog
@@ -22,7 +23,7 @@ import kotlinx.coroutines.Dispatchers
import java.util.regex.Pattern
import java.util.regex.PatternSyntaxException
class TxtTocRuleEditDialog() : BaseDialogFragment(R.layout.dialog_toc_regex_edit, true),
class TxtTocRuleEditDialog() : BaseBottomSheetDialogFragment(R.layout.dialog_toc_regex_edit),
Toolbar.OnMenuItemClickListener {
constructor(id: Long?) : this() {
@@ -9,6 +9,7 @@ import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.viewModels
import io.legado.app.R
import io.legado.app.base.BaseBottomSheetDialogFragment
import io.legado.app.base.BaseDialogFragment
import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
@@ -18,7 +19,7 @@ import io.legado.app.databinding.DialogDictRuleEditBinding
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
class DictRuleEditDialog() : BaseDialogFragment(R.layout.dialog_dict_rule_edit, true),
class DictRuleEditDialog() : BaseBottomSheetDialogFragment(R.layout.dialog_dict_rule_edit),
Toolbar.OnMenuItemClickListener {
val viewModel by viewModels<DictRuleEditViewModel>()
@@ -5,10 +5,12 @@ import android.content.DialogInterface
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.util.TypedValue
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.drawable.DrawableCompat
import androidx.fragment.app.FragmentManager
@@ -165,7 +167,7 @@ class FilePickerDialog : BaseDialogFragment(R.layout.dialog_file_chooser),
inner class PathAdapter :
RecyclerAdapter<File, ItemPathPickerBinding>(requireContext()) {
private val arrowIcon = ConvertUtils.toDrawable(FilePickerIcon.getArrow())
private val arrowIcon = ContextCompat.getDrawable(requireContext(),R.drawable.ic_arrow_right)
init {
addHeaderView {
@@ -207,14 +209,16 @@ class FilePickerDialog : BaseDialogFragment(R.layout.dialog_file_chooser),
}
inner class FileAdapter : RecyclerAdapter<File, ItemFilePickerBinding>(requireContext()) {
//private val primaryTextColor = context.getPrimaryTextColor(!AppConfig.isNightTheme)
//private val disabledTextColor = context.getPrimaryDisabledTextColor(!AppConfig.isNightTheme)
private val upIcon = ConvertUtils.toDrawable(FilePickerIcon.getUpDir())!!
private val folderIcon = ConvertUtils.toDrawable(FilePickerIcon.getFolder())!!
private val fileIcon = ConvertUtils.toDrawable(FilePickerIcon.getFile())!!
private val upIcon = ContextCompat.getDrawable(requireContext(),R.drawable.ic_return)
private val folderIcon = ContextCompat.getDrawable(requireContext(),R.drawable.ic_folder)
private val fileIcon = ContextCompat.getDrawable(requireContext(),R.drawable.ic_file)
private val selectDrawable =
ResourcesCompat.getDrawable(resources, R.drawable.shape_radius_1dp, null)!!.apply {
//DrawableCompat.setTint(this, primaryTextColor)
// 从主题获取颜色
val typedValue = TypedValue()
requireContext().theme.resolveAttribute(android.R.attr.colorPrimary, typedValue, true)
val primaryColor = typedValue.data
DrawableCompat.setTint(this, primaryColor)
}
var selectFile: File? = null
@@ -2,6 +2,7 @@ package io.legado.app.ui.main.bookshelf.style1.books
import android.content.Context
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.data.entities.Book
@@ -44,32 +45,36 @@ class BooksAdapterGrid(context: Context, private val callBack: CallBack) :
private fun upRefresh(binding: ItemBookshelfGridBinding, item: Book) {
if (!item.isLocal && callBack.isUpdate(item.bookUrl)) {
binding.bvUnread.invisible()
binding.rlLoading.visible()
binding.cdUnread.visibility = View.GONE
binding.rlLoading.visibility = View.VISIBLE
} else {
binding.rlLoading.inVisible()
binding.rlLoading.visibility = View.GONE
if (AppConfig.showUnread) {
binding.bvUnread.setBadgeCount(item.getUnreadChapterNum())
binding.bvUnread.setHighlight(item.lastCheckCount > 0)
val unreadCount = item.getUnreadChapterNum()
if (unreadCount > 0) {
binding.cdUnread.visibility = View.VISIBLE
binding.tvUnread.text = unreadCount.toString()
} else {
binding.cdUnread.visibility = View.GONE
}
} else {
binding.bvUnread.invisible()
binding.cdUnread.visibility = View.GONE
}
}
}
override fun registerListener(holder: ItemViewHolder, binding: ItemBookshelfGridBinding) {
holder.itemView.apply {
setOnClickListener {
getItem(holder.layoutPosition)?.let {
callBack.open(it)
}
binding.cvContent.setOnClickListener {
getItem(holder.layoutPosition)?.let {
callBack.open(it)
}
}
onLongClick {
getItem(holder.layoutPosition)?.let {
callBack.openBookInfo(it)
}
binding.cvContent.setOnLongClickListener {
getItem(holder.layoutPosition)?.let {
callBack.openBookInfo(it)
}
true
}
}
}
@@ -2,6 +2,7 @@ package io.legado.app.ui.main.bookshelf.style2
import android.content.Context
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.data.entities.Book
@@ -89,19 +90,25 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
private fun upRefresh(binding: ItemBookshelfGridBinding, item: Book) {
if (!item.isLocal && callBack.isUpdate(item.bookUrl)) {
binding.bvUnread.invisible()
binding.rlLoading.visible()
binding.cdUnread.visibility = View.GONE
binding.rlLoading.visibility = View.VISIBLE
} else {
binding.rlLoading.inVisible()
binding.rlLoading.visibility = View.GONE
if (AppConfig.showUnread) {
binding.bvUnread.setBadgeCount(item.getUnreadChapterNum())
binding.bvUnread.setHighlight(item.lastCheckCount > 0)
val unreadCount = item.getUnreadChapterNum()
if (unreadCount > 0) {
binding.cdUnread.visibility = View.VISIBLE
binding.tvUnread.text = unreadCount.toString()
} else {
binding.cdUnread.visibility = View.GONE
}
} else {
binding.bvUnread.invisible()
binding.cdUnread.visibility = View.GONE
}
}
}
}
inner class GroupViewHolder(val binding: ItemBookshelfGridGroupBinding) :
@@ -129,10 +136,10 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
}
fun registerListener(item: Any) {
binding.root.setOnClickListener {
binding.cvContent.setOnClickListener {
callBack.onItemClick(item)
}
binding.root.onLongClick {
binding.cvContent.onLongClick {
callBack.onItemLongClick(item)
}
}
@@ -11,6 +11,7 @@ import androidx.fragment.app.activityViewModels
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R
import io.legado.app.base.BaseBottomSheetDialogFragment
import io.legado.app.base.BaseDialogFragment
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter
@@ -32,7 +33,7 @@ import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.launch
class GroupManageDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
class GroupManageDialog : BaseBottomSheetDialogFragment(R.layout.dialog_recycler_view),
Toolbar.OnMenuItemClickListener {
private val viewModel: RssSourceViewModel by activityViewModels()
@@ -41,7 +42,7 @@ class GroupManageDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
override fun onStart() {
super.onStart()
setLayout(0.9f, 0.9f)
}
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) = binding.run {
@@ -1,9 +1,13 @@
package io.legado.app.ui.widget
import android.content.Context
import android.os.Build
import android.util.AttributeSet
import android.widget.LinearLayout
import android.widget.TextView
import androidx.annotation.RequiresApi
import com.google.android.material.chip.Chip
import com.google.android.material.chip.ChipGroup
import io.legado.app.ui.widget.text.AccentBgTextView
import io.legado.app.utils.dpToPx
@@ -11,19 +15,19 @@ import io.legado.app.utils.dpToPx
class LabelsBar @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null
) : LinearLayout(context, attrs) {
) : ChipGroup(context, attrs) {
private val unUsedViews = arrayListOf<TextView>()
private val usedViews = arrayListOf<TextView>()
var textSize = 12f
private val unUsedChips = arrayListOf<Chip>()
private val usedChips = arrayListOf<Chip>()
//var textSizeSp = 12f
fun setLabels(labels: Array<String>) {
clear()
labels.forEach {
addLabel(it)
}
init {
// isSingleLine = false
// chipSpacingHorizontal = 8.dpToPx()
// chipSpacingVertical = 4.dpToPx()
}
@RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM)
fun setLabels(labels: List<String>) {
clear()
labels.forEach {
@@ -31,32 +35,32 @@ class LabelsBar @JvmOverloads constructor(
}
}
@RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM)
fun setLabels(labels: Array<String>) {
setLabels(labels.toList())
}
fun clear() {
unUsedViews.addAll(usedViews)
usedViews.clear()
unUsedChips.addAll(usedChips)
usedChips.clear()
removeAllViews()
}
@RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM)
fun addLabel(label: String) {
val tv = if (unUsedViews.isEmpty()) {
AccentBgTextView(context, null).apply {
setPadding(3.dpToPx(), 0, 3.dpToPx(), 0)
//setRadius(2)
val lp = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)
lp.setMargins(0, 0, 2.dpToPx(), 0)
layoutParams = lp
text = label
maxLines = 1
usedViews.add(this)
val chip = if (unUsedChips.isEmpty()) {
Chip(context).apply {
isClickable = false
isCheckable = false
chipStartPadding = 8f
chipEndPadding = 8f
chipStrokeWidth = 0f
usedChips.add(this)
}
} else {
unUsedViews.last().apply {
usedViews.add(this)
unUsedViews.removeAt(unUsedViews.lastIndex)
}
unUsedChips.removeLast().also { usedChips.add(it) }
}
tv.textSize = textSize
tv.text = label
addView(tv)
chip.text = label
addView(chip)
}
}
}
@@ -81,22 +81,26 @@ class CoverImageView @JvmOverloads constructor(
)
}
private val cornerRadius = 24f
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
super.onLayout(changed, left, top, right, bottom)
viewWidth = width.toFloat()
viewHeight = height.toFloat()
filletPath.reset()
if (width > 10 && viewHeight > 10) {
if (viewWidth > cornerRadius * 2 && viewHeight > cornerRadius * 2) {
val r = cornerRadius
filletPath.apply {
moveTo(12f, 0f)
lineTo(viewWidth - 12, 0f)
quadTo(viewWidth, 0f, viewWidth, 12f)
lineTo(viewWidth, viewHeight - 12)
quadTo(viewWidth, viewHeight, viewWidth - 12, viewHeight)
lineTo(12f, viewHeight)
quadTo(0f, viewHeight, 0f, viewHeight - 12)
lineTo(0f, 12f)
quadTo(0f, 0f, 12f, 0f)
moveTo(r, 0f)
lineTo(viewWidth - r, 0f)
quadTo(viewWidth, 0f, viewWidth, r)
lineTo(viewWidth, viewHeight - r)
quadTo(viewWidth, viewHeight, viewWidth - r, viewHeight)
lineTo(r, viewHeight)
quadTo(0f, viewHeight, 0f, viewHeight - r)
lineTo(0f, r)
quadTo(0f, 0f, r, 0f)
close()
}
}
@@ -14,5 +14,4 @@ class TextInputLayout(context: Context, attrs: AttributeSet?) : TextInputLayout(
Selector.colorBuild().setDefaultColor(ThemeStore.accentColor(context)).create()
}
}
}