feat: 优化代码

pull/115/head
kunfei 5 years ago
parent 07d4fa66b6
commit 1481ce288d
  1. 2
      app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt
  2. 14
      app/src/main/java/io/legado/app/ui/widget/recycler/DividerNoLast.kt

@ -20,7 +20,6 @@ import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.ui.widget.recycler.DividerNoLast
import io.legado.app.utils.isAbsUrl import io.legado.app.utils.isAbsUrl
import io.legado.app.utils.sendToClip import io.legado.app.utils.sendToClip
import kotlinx.android.synthetic.main.item_fillet_text.view.* import kotlinx.android.synthetic.main.item_fillet_text.view.*
@ -46,7 +45,6 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
private fun initRecyclerView() = with(contentView) { private fun initRecyclerView() = with(contentView) {
val adapter = Adapter(context) val adapter = Adapter(context)
recycler_view.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false) recycler_view.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
recycler_view.addItemDecoration(DividerNoLast(context, DividerNoLast.HORIZONTAL))
recycler_view.adapter = adapter recycler_view.adapter = adapter
val menu = MenuBuilder(context) val menu = MenuBuilder(context)
SupportMenuInflater(context).inflate(R.menu.content_select_action, menu) SupportMenuInflater(context).inflate(R.menu.content_select_action, menu)

@ -8,6 +8,8 @@ import android.util.Log
import android.view.View import android.view.View
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import kotlin.math.roundToInt
/** /**
* 不画最后一条分隔线 * 不画最后一条分隔线
@ -106,7 +108,7 @@ class DividerNoLast(context: Context, orientation: Int) :
for (i in 0 until childCount - 1) { for (i in 0 until childCount - 1) {
val child = parent.getChildAt(i) val child = parent.getChildAt(i)
parent.getDecoratedBoundsWithMargins(child, mBounds) parent.getDecoratedBoundsWithMargins(child, mBounds)
val bottom = mBounds.bottom + Math.round(child.translationY) val bottom = mBounds.bottom + child.translationY.roundToInt()
val top = bottom - mDivider!!.intrinsicHeight val top = bottom - mDivider!!.intrinsicHeight
mDivider!!.setBounds(left, top, right, bottom) mDivider!!.setBounds(left, top, right, bottom)
mDivider!!.draw(canvas) mDivider!!.draw(canvas)
@ -133,7 +135,7 @@ class DividerNoLast(context: Context, orientation: Int) :
for (i in 0 until childCount - 1) { for (i in 0 until childCount - 1) {
val child = parent.getChildAt(i) val child = parent.getChildAt(i)
parent.layoutManager!!.getDecoratedBoundsWithMargins(child, mBounds) parent.layoutManager!!.getDecoratedBoundsWithMargins(child, mBounds)
val right = mBounds.right + Math.round(child.translationX) val right = mBounds.right + child.translationX.roundToInt()
val left = right - mDivider!!.intrinsicWidth val left = right - mDivider!!.intrinsicWidth
mDivider!!.setBounds(left, top, right, bottom) mDivider!!.setBounds(left, top, right, bottom)
mDivider!!.draw(canvas) mDivider!!.draw(canvas)
@ -149,10 +151,18 @@ class DividerNoLast(context: Context, orientation: Int) :
outRect[0, 0, 0] = 0 outRect[0, 0, 0] = 0
return return
} }
if (mOrientation == VERTICAL) { if (mOrientation == VERTICAL) {
outRect[0, 0, 0] = mDivider!!.intrinsicHeight outRect[0, 0, 0] = mDivider!!.intrinsicHeight
} else { } else {
val childAdapterPosition = parent.getChildAdapterPosition(view)
val lastCount = parent.adapter!!.itemCount - 1
//如果不是最后一条 正常赋值 如果是最后一条 赋值为0
if (childAdapterPosition != lastCount) {
outRect[0, 0, mDivider!!.intrinsicWidth] = 0 outRect[0, 0, mDivider!!.intrinsicWidth] = 0
} else {
outRect[0, 0, 0] = 0
}
} }
} }

Loading…
Cancel
Save