Merge pull request #69 from KKL369/master

修改bookshelf grid显示效果
pull/70/head
kunfei 5 years ago committed by GitHub
commit 8bcd67ad71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt
  2. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt
  3. 6
      app/src/main/java/io/legado/app/ui/widget/BadgeView.kt
  4. 40
      app/src/main/res/layout/item_bookshelf_grid.xml
  5. 4
      app/src/main/res/values/attrs.xml

@ -20,7 +20,7 @@ class BooksAdapterGrid(context: Context, private val callBack: CallBack) :
if (payloads.isEmpty()) { if (payloads.isEmpty()) {
ATH.applyBackgroundTint(this) ATH.applyBackgroundTint(this)
tv_name.text = item.name tv_name.text = item.name
tv_author.text = item.author bv_author.text = item.author
item.getDisplayCover()?.let { item.getDisplayCover()?.let {
ImageLoader.load(context, it)//Glide自动识别http://和file:// ImageLoader.load(context, it)//Glide自动识别http://和file://
.placeholder(R.drawable.image_cover_default) .placeholder(R.drawable.image_cover_default)

@ -71,7 +71,7 @@ class BooksFragment : BaseFragment(R.layout.fragment_books),
booksAdapter = BooksAdapterList(requireContext(), this) booksAdapter = BooksAdapterList(requireContext(), this)
} else { } else {
rv_bookshelf.layoutManager = GridLayoutManager(context, bookshelfLayout + 2) rv_bookshelf.layoutManager = GridLayoutManager(context, bookshelfLayout + 2)
booksAdapter = BooksAdapterGrid(requireContext(), this) booksAdapter = BooksAdapterGrid(requireContext(),this)
} }
rv_bookshelf.adapter = booksAdapter rv_bookshelf.adapter = booksAdapter
} }

@ -74,6 +74,10 @@ class BadgeView @JvmOverloads constructor(
} }
init { init {
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.BadgeView)
val radios =
typedArray.getDimensionPixelOffset(R.styleable.BadgeView_bv_radius, 8)
if (layoutParams !is LayoutParams) { if (layoutParams !is LayoutParams) {
val layoutParams = LayoutParams( val layoutParams = LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,
@ -88,7 +92,7 @@ class BadgeView @JvmOverloads constructor(
//setTypeface(Typeface.DEFAULT_BOLD); //setTypeface(Typeface.DEFAULT_BOLD);
setTextSize(TypedValue.COMPLEX_UNIT_SP, 11f) setTextSize(TypedValue.COMPLEX_UNIT_SP, 11f)
setPadding(dip2Px(5f), dip2Px(1f), dip2Px(5f), dip2Px(1f)) setPadding(dip2Px(5f), dip2Px(1f), dip2Px(5f), dip2Px(1f))
radius = 8f radius = radios.toFloat()
// set default background // set default background
setBackground(radius, context.accentColor) setBackground(radius, context.accentColor)

@ -49,35 +49,39 @@
tools:ignore="RtlHardcoded" /> tools:ignore="RtlHardcoded" />
</FrameLayout> </FrameLayout>
<FrameLayout
android:id="@+id/fl_author"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="@id/iv_cover"
app:layout_constraintBottom_toBottomOf="@id/iv_cover">
<io.legado.app.ui.widget.BadgeView
android:id="@+id/bv_author"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:includeFontPadding="false"
android:singleLine="true"
app:bv_radius="0dp"
tools:ignore="RtlHardcoded" />
</FrameLayout>
<TextView <TextView
android:id="@+id/tv_name" android:id="@+id/tv_name"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:includeFontPadding="false" android:includeFontPadding="false"
android:gravity="center" android:gravity="center"
android:singleLine="true" android:lines="2"
android:ellipsize="end"
android:text="@string/book_name" android:text="@string/book_name"
android:textColor="@color/tv_text_default" android:textColor="@color/tv_text_default"
android:textSize="16sp" android:textSize="12sp"
app:layout_constraintLeft_toLeftOf="@+id/iv_cover" app:layout_constraintLeft_toLeftOf="@+id/iv_cover"
app:layout_constraintRight_toRightOf="@+id/iv_cover" app:layout_constraintRight_toRightOf="@+id/iv_cover"
app:layout_constraintTop_toBottomOf="@+id/iv_cover" app:layout_constraintTop_toBottomOf="@+id/iv_cover"
tools:ignore="RtlHardcoded,RtlSymmetry" /> tools:ignore="RtlHardcoded,RtlSymmetry" />
<TextView
android:id="@+id/tv_author"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:gravity="center"
android:maxLines="1"
android:text="@string/author"
android:textColor="@color/tv_text_secondary"
android:textSize="13sp"
app:layout_constraintLeft_toLeftOf="@+id/iv_cover"
app:layout_constraintRight_toRightOf="@+id/iv_cover"
app:layout_constraintTop_toBottomOf="@+id/tv_name"
app:layout_constraintBottom_toBottomOf="parent"
tools:ignore="RtlSymmetry" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

@ -140,4 +140,8 @@
<declare-styleable name="ATEAccentBgTextView"> <declare-styleable name="ATEAccentBgTextView">
<attr name="abt_radius" format="dimension" /> <attr name="abt_radius" format="dimension" />
</declare-styleable> </declare-styleable>
<declare-styleable name="BadgeView">
<attr name="bv_radius" format="dimension" />
</declare-styleable>
</resources> </resources>
Loading…
Cancel
Save