@@ -11,34 +11,30 @@ import android.view.LayoutInflater
1111import android.view.View
1212import android.view.ViewTreeObserver
1313import android.view.animation.AccelerateDecelerateInterpolator
14- import android.widget.*
1514import androidx.annotation.IdRes
1615import androidx.annotation.IntDef
1716import androidx.constraintlayout.widget.ConstraintLayout
17+ import androidx.core.content.withStyledAttributes
18+ import androidx.core.util.isNotEmpty
19+ import androidx.core.util.size
20+ import androidx.core.view.isGone
21+ import androidx.core.view.isNotEmpty
1822import androidx.core.view.marginBottom
1923import androidx.core.view.marginTop
2024import androidx.core.view.updateLayoutParams
21- import androidx.recyclerview.widget.*
22- import androidx.recyclerview.widget.RecyclerView.ItemDecoration
25+ import androidx.recyclerview.widget.GridLayoutManager
26+ import androidx.recyclerview.widget.LinearLayoutManager
27+ import androidx.recyclerview.widget.RecyclerView
28+ import androidx.recyclerview.widget.SimpleItemAnimator
2329import com.framework.tagflow.adapter.BaseTagAdapter
24- import com.framework.tagflow.bean.BaseTagBean
30+ import com.framework.tagflow.databinding.TagFlowLayoutBinding
2531import com.framework.tagflow.interfac.OnTagClickListener
2632import com.framework.tagflow.interfac.OnTagSelectedListener
2733import com.framework.tagflow.tags.MutSelectedTagView
2834import com.framework.tagflow.tags.NonTouchableRecyclerView
2935import com.framework.tagflow.utils.DensityUtils
30- import com.framework.tagflow.view.ControlScrollView
3136import com.framework.tagflow.view.FlowLayout
3237import kotlin.math.ceil
33- import androidx.core.view.isNotEmpty
34- import androidx.core.content.withStyledAttributes
35- import androidx.core.util.isNotEmpty
36- import androidx.core.util.size
37- import androidx.core.view.isGone
38- import com.framework.tagflow.databinding.TagFlowLayoutBinding
39- import kotlin.compareTo
40- import kotlin.text.clear
41- import kotlin.text.toFloat
4238
4339/* *
4440 * @author: xiaxueyi
@@ -63,19 +59,9 @@ open class MultiTagFlowLayout @JvmOverloads constructor(
6359 private const val LAYOUT_TYPE_DEFAULT = 0
6460 private const val LAYOUT_MANAGER_MODE_DEFAULT = 0
6561 private const val DEFAULT_ROWS = 3
66- private const val DEFAULT_COLUMN = 3
6762 private const val MAX_FLOW_LAYOUT_LINES = 6
6863 }
6964
70- private lateinit var mControlScrollView: ControlScrollView // 标签容器
71-
72- private lateinit var mIvArrowMore: ImageView // 箭头
73-
74- private lateinit var mTvMoreHint: TextView // 提示文本
75-
76- private lateinit var mRlShowMore: LinearLayout // 展开收起布局
77-
78- private lateinit var mEmptyViewContainer: FrameLayout ;
7965
8066 // 是否折叠起来
8167 // true:折叠起来了
@@ -244,15 +230,7 @@ open class MultiTagFlowLayout @JvmOverloads constructor(
244230 * 初始化组件
245231 */
246232 private fun initWidget () {
247- inflate(context, R .layout.tag_flow_layout, this )
248- mControlScrollView = findViewById(R .id.hsv_tag_content)
249- mIvArrowMore = findViewById(R .id.iv_arrow_more)
250- mTvMoreHint = findViewById(R .id.tv_more_hint)
251- mRlShowMore = findViewById(R .id.rl_show_more)
252- mEmptyViewContainer= findViewById(R .id.fl_empty)
253-
254-
255- mRlShowMore.setOnClickListener {
233+ mBinding.rlShowMore.setOnClickListener {
256234 // 真实数量
257235 var realCount = 0
258236 var finalLine = 0
@@ -320,7 +298,7 @@ open class MultiTagFlowLayout @JvmOverloads constructor(
320298 animator.duration = animationDuration.toLong()
321299 animator.addUpdateListener { animation ->
322300 val value = animation.animatedValue as Int
323- mControlScrollView .updateLayoutParams {
301+ mBinding.hsvTagContent .updateLayoutParams {
324302 this .height= value
325303 }
326304 }
@@ -374,14 +352,13 @@ open class MultiTagFlowLayout @JvmOverloads constructor(
374352 } else {
375353 180f
376354 }
377- ObjectAnimator .ofFloat(mIvArrowMore , " rotation" , rotationStart, rotationEnd).start()
355+ ObjectAnimator .ofFloat(mBinding.ivArrowMore , " rotation" , rotationStart, rotationEnd).start()
378356 animate(animateStart, animateEnd)
379- mTvMoreHint .text = if (isFolded) {
357+ mBinding.tvMoreHint .text = if (isFolded) {
380358 expandHint
381359 } else {
382360 foldHint
383361 }
384- mControlScrollView.setCanScroll(false )
385362 isFolded = ! isFolded
386363 }
387364
@@ -414,7 +391,7 @@ open class MultiTagFlowLayout @JvmOverloads constructor(
414391 mRecyclerView.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver .OnGlobalLayoutListener {
415392
416393 override fun onGlobalLayout () {
417- mControlScrollView .updateLayoutParams {
394+ mBinding.hsvTagContent .updateLayoutParams {
418395 this .height = calculateControlScrollViewHeight(itemCount) // 计算 ControlScrollView 的高度
419396 }
420397 mRecyclerView.viewTreeObserver.removeOnGlobalLayoutListener(this )
@@ -434,22 +411,22 @@ open class MultiTagFlowLayout @JvmOverloads constructor(
434411 override fun onGlobalLayout () {
435412 val flowLayoutLines = mFlowLayout.getLineSize()
436413 val controlScrollViewHeight = if (mHasMore) { // 有展开更多的布局
437- if (mRlShowMore .isGone){
438- mRlShowMore .visibility = VISIBLE
439- mRlShowMore .isClickable = true
414+ if (mBinding.rlShowMore .isGone){
415+ mBinding.rlShowMore .visibility = VISIBLE
416+ mBinding.rlShowMore .isClickable = true
440417 }
441418 if (flowLayoutLines <= DEFAULT_ROWS ) {
442419 getLineHeight() * flowLayoutLines
443420 } else {
444421 getLineHeight() * DEFAULT_ROWS
445422 }
446423 } else { // 没有展开更多的布局
447- mRlShowMore .visibility = View .GONE
448- mRlShowMore .isClickable = false // 避免点击事件
424+ mBinding.rlShowMore .visibility = View .GONE
425+ mBinding.rlShowMore .isClickable = false // 避免点击事件
449426 getLineHeight() * flowLayoutLines
450427 }
451428
452- mControlScrollView .updateLayoutParams {
429+ mBinding.hsvTagContent .updateLayoutParams {
453430 this .height= controlScrollViewHeight
454431 }
455432 mFlowLayout.viewTreeObserver.removeOnGlobalLayoutListener(this )
@@ -515,16 +492,16 @@ open class MultiTagFlowLayout @JvmOverloads constructor(
515492 * 实例化布局类型
516493 */
517494 private fun initLayoutType () {
518- if (mControlScrollView .isNotEmpty()) {
519- mControlScrollView .removeAllViews()
495+ if (mBinding.hsvTagContent .isNotEmpty()) {
496+ mBinding.hsvTagContent .removeAllViews()
520497 }
521498 when (mLayoutType) {
522499 LayoutTypeMode .RecyclerView .index -> {
523- mControlScrollView .addView(mRecyclerView)
500+ mBinding.hsvTagContent .addView(mRecyclerView)
524501 }
525502
526503 LayoutTypeMode .FlowLayout .index -> {
527- mControlScrollView .addView(mFlowLayout)
504+ mBinding.hsvTagContent .addView(mFlowLayout)
528505 }
529506 }
530507 }
@@ -762,17 +739,17 @@ open class MultiTagFlowLayout @JvmOverloads constructor(
762739 *
763740 */
764741 private fun updateLayoutForEmptyData () {
765- mControlScrollView .updateLayoutParams {
742+ mBinding.hsvTagContent .updateLayoutParams {
766743 this .height = 0
767744 }
768- val childCount: Int = mEmptyViewContainer .childCount
745+ val childCount: Int = mBinding.flEmpty .childCount
769746 if (childCount> 0 ){
770- mEmptyViewContainer .removeAllViews()
747+ mBinding.flEmpty .removeAllViews()
771748 }
772- mEmptyViewContainer .addView(mEmptyView)
773- mEmptyViewContainer .visibility= VISIBLE
774- mRlShowMore .visibility = INVISIBLE
775- mRlShowMore .isClickable = false
749+ mBinding.flEmpty .addView(mEmptyView)
750+ mBinding.flEmpty .visibility= VISIBLE
751+ mBinding.rlShowMore .visibility = INVISIBLE
752+ mBinding.rlShowMore .isClickable = false
776753 }
777754
778755
@@ -798,10 +775,10 @@ open class MultiTagFlowLayout @JvmOverloads constructor(
798775 val controlScrollViewHeight= if (mHasMore) { // 有展开更多的布局
799776 if (isNotifyData) {
800777 if (finalLine <= 3 ) {
801- mRlShowMore .visibility = GONE
778+ mBinding.rlShowMore .visibility = GONE
802779 getLineHeight() * finalLine
803780 } else {
804- mRlShowMore .visibility = VISIBLE
781+ mBinding.rlShowMore .visibility = VISIBLE
805782 if (isFolded) {
806783 getLineHeight() * finalLine
807784 } else {
@@ -810,15 +787,15 @@ open class MultiTagFlowLayout @JvmOverloads constructor(
810787 }
811788 } else {
812789 if (finalLine <= 3 ) {
813- mRlShowMore .visibility = GONE
790+ mBinding.rlShowMore .visibility = GONE
814791 getLineHeight() * finalLine
815792 } else {
816- mRlShowMore .visibility = VISIBLE
793+ mBinding.rlShowMore .visibility = VISIBLE
817794 getLineHeight() * defaultRows
818795 }
819796 }
820797 } else { // 没有展开更多的布局
821- mRlShowMore .visibility = GONE
798+ mBinding.rlShowMore .visibility = GONE
822799 getLineHeight() * itemCount // 使用之前获取的 itemCount
823800 }
824801
@@ -859,7 +836,7 @@ open class MultiTagFlowLayout @JvmOverloads constructor(
859836 fun setFoldHint (foldHint : String ) {
860837 this .foldHint = foldHint
861838 if (isFolded) {
862- mTvMoreHint .text = foldHint
839+ mBinding.tvMoreHint .text = foldHint
863840 }
864841 }
865842
@@ -880,7 +857,7 @@ open class MultiTagFlowLayout @JvmOverloads constructor(
880857 fun setExpandHint (expandHint : String ) {
881858 this .expandHint = expandHint
882859 if (! isFolded) {
883- mTvMoreHint .text = expandHint
860+ mBinding.tvMoreHint .text = expandHint
884861 }
885862 }
886863
@@ -901,25 +878,6 @@ open class MultiTagFlowLayout @JvmOverloads constructor(
901878 this .animationDuration = animationDuration
902879 }
903880
904- /* *
905- *
906- * @return Boolean
907- */
908- fun isCanScroll (): Boolean {
909- return mControlScrollView.isCanScroll()
910- }
911-
912- /* *
913- * 设置是否退出内部标签容器
914- * @param can Boolean
915- */
916- fun setCanScroll (can : Boolean ) {
917- mControlScrollView.setCanScroll(can)
918- }
919-
920- fun setForceFixed (fixed : Boolean ) {
921- mControlScrollView.setForceFixed(fixed)
922- }
923881
924882 /* *
925883 * 获取FlowLayout 点击模式
0 commit comments