diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index cd41c8980..efcddba7c 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -111,33 +111,10 @@ class BookInfoActivity : upTvBookshelf() val kinds = book.getKindList() if (kinds.isEmpty()) { - ll_kind.gone() + lb_kind.gone() } else { - ll_kind.visible() - for (index in 0..2) { - if (kinds.size > index) { - when (index) { - 0 -> { - tv_kind.text = kinds[index] - tv_kind.visible() - } - 1 -> { - tv_kind_1.text = kinds[index] - tv_kind_1.visible() - } - 2 -> { - tv_kind_2.text = kinds[index] - tv_kind_2.visible() - } - } - } else { - when (index) { - 0 -> tv_kind.gone() - 1 -> tv_kind_1.gone() - 2 -> tv_kind_2.gone() - } - } - } + lb_kind.visible() + lb_kind.setLabels(kinds) } upGroup(book.group) } diff --git a/app/src/main/java/io/legado/app/ui/widget/LabelsBar.kt b/app/src/main/java/io/legado/app/ui/widget/LabelsBar.kt new file mode 100644 index 000000000..e59ac8983 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/LabelsBar.kt @@ -0,0 +1,36 @@ +package io.legado.app.ui.widget + +import android.content.Context +import android.util.AttributeSet +import android.widget.LinearLayout +import androidx.core.view.setPadding +import io.legado.app.ui.widget.text.AccentBgTextView +import io.legado.app.utils.dp + + +class LabelsBar(context: Context, attrs: AttributeSet?) : LinearLayout(context, attrs) { + + + fun setLabels(labels: Array) { + removeAllViews() + labels.forEach { + addLabel(it) + } + } + + fun setLabels(labels: List) { + removeAllViews() + labels.forEach { + addLabel(it) + } + } + + fun addLabel(label: String) { + addView(AccentBgTextView(context, null).apply { + setPadding(2.dp) + setRadios(2) + text = label + }) + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/widget/text/AccentBgTextView.kt b/app/src/main/java/io/legado/app/ui/widget/text/AccentBgTextView.kt index 846f34204..b5114cd4a 100644 --- a/app/src/main/java/io/legado/app/ui/widget/text/AccentBgTextView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/text/AccentBgTextView.kt @@ -8,20 +8,31 @@ import io.legado.app.R import io.legado.app.lib.theme.ColorUtils import io.legado.app.lib.theme.Selector import io.legado.app.lib.theme.ThemeStore +import io.legado.app.utils.dp -class AccentBgTextView(context: Context, attrs: AttributeSet) : +class AccentBgTextView(context: Context, attrs: AttributeSet?) : AppCompatTextView(context, attrs) { + private var radios = 0 + init { val typedArray = context.obtainStyledAttributes(attrs, R.styleable.AccentBgTextView) - val radios = - typedArray.getDimensionPixelOffset(R.styleable.AccentBgTextView_radius, 0) + radios = typedArray.getDimensionPixelOffset(R.styleable.AccentBgTextView_radius, radios) typedArray.recycle() + upBackground() + setTextColor(Color.WHITE) + } + + fun setRadios(radio: Int) { + this.radios = radio.dp + upBackground() + } + + private fun upBackground() { background = Selector.shapeBuild() .setCornerRadius(radios) .setDefaultBgColor(ThemeStore.accentColor(context)) .setPressedBgColor(ColorUtils.darkenColor(ThemeStore.accentColor(context))) .create() - setTextColor(Color.WHITE) } } diff --git a/app/src/main/res/layout/activity_book_info.xml b/app/src/main/res/layout/activity_book_info.xml index 0c98f4cda..20fc5e56e 100644 --- a/app/src/main/res/layout/activity_book_info.xml +++ b/app/src/main/res/layout/activity_book_info.xml @@ -100,50 +100,12 @@ - - - - - - - - - + android:visibility="gone" /> + android:layout_height="match_parent">