From 0980a1267b32d051b7d7121497c82102b970356d Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 15 Feb 2020 17:51:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/info/BookInfoActivity.kt | 29 ++---------- .../java/io/legado/app/ui/widget/LabelsBar.kt | 36 +++++++++++++++ .../app/ui/widget/text/AccentBgTextView.kt | 19 ++++++-- .../main/res/layout/activity_book_info.xml | 44 ++----------------- .../main/res/layout/dialog_number_picker.xml | 3 +- 5 files changed, 58 insertions(+), 73 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/widget/LabelsBar.kt 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">