@@ -9,6 +9,7 @@ import android.view.Gravity
9
9
import android.view.LayoutInflater
10
10
import android.view.View
11
11
import android.view.ViewGroup
12
+ import android.widget.LinearLayout
12
13
import android.widget.TextView
13
14
import androidx.recyclerview.widget.RecyclerView
14
15
import com.osfans.trime.data.theme.ColorManager
@@ -18,7 +19,8 @@ import com.osfans.trime.databinding.SimpleItemOneBinding
18
19
import com.osfans.trime.databinding.SimpleItemRowBinding
19
20
import splitties.dimensions.dp
20
21
21
- class SimpleAdapter (theme : Theme , private val columnSize : Int ) : RecyclerView.Adapter<SimpleAdapter.ViewHolder>() {
22
+ class SimpleAdapter (theme : Theme , private val columnSize : Int ) :
23
+ RecyclerView .Adapter <SimpleAdapter .ViewHolder >() {
22
24
private val mBeans = mutableListOf<SimpleKeyBean >()
23
25
private val mBeansByRows = mutableListOf<List <SimpleKeyBean >>()
24
26
val beans get() = mBeans
@@ -42,6 +44,8 @@ class SimpleAdapter(theme: Theme, private val columnSize: Int) : RecyclerView.Ad
42
44
}
43
45
44
46
private val mSingleWidth = theme.liquid.getInt(" single_width" )
47
+ private val mSingleHeight = theme.liquid.getInt(" key_height" )
48
+ private val mStringMarginX = theme.liquid.getFloat(" margin_x" )
45
49
private val mTextSize = theme.generalStyle.labelTextSize
46
50
private val mTextColor = ColorManager .getColor(" key_text_color" )
47
51
private val mTypeface = FontManager .getTypeface(" key_font" )
@@ -57,13 +61,18 @@ class SimpleAdapter(theme: Theme, private val columnSize: Int) : RecyclerView.Ad
57
61
parent : ViewGroup ,
58
62
viewType : Int ,
59
63
): ViewHolder {
60
- val binding = SimpleItemRowBinding .inflate(LayoutInflater .from(parent.context), parent, false )
61
- val size = parent.dp(mSingleWidth)
64
+ val binding =
65
+ SimpleItemRowBinding .inflate(LayoutInflater .from(parent.context), parent, false )
66
+ val width = parent.dp(mSingleWidth)
67
+ val height = parent.dp(mSingleHeight)
68
+ val marginX = parent.dp(mStringMarginX).toInt()
62
69
val bindings = mutableListOf<SimpleItemOneBinding >()
63
70
for (i in 0 until columnSize) {
64
71
val sub = SimpleItemOneBinding .inflate(LayoutInflater .from(parent.context), null , false )
65
72
bindings.add(sub)
66
- binding.wrapper.addView(sub.root, size, size)
73
+ val layoutParams = LinearLayout .LayoutParams (width, height)
74
+ layoutParams.setMargins(marginX, 0 , marginX, 0 )
75
+ binding.wrapper.addView(sub.root, layoutParams)
67
76
}
68
77
val holder = ViewHolder (binding, bindings)
69
78
@@ -81,7 +90,8 @@ class SimpleAdapter(theme: Theme, private val columnSize: Int) : RecyclerView.Ad
81
90
return holder
82
91
}
83
92
84
- class ViewHolder (binding : SimpleItemRowBinding , views : List <SimpleItemOneBinding >) : RecyclerView.ViewHolder(binding.root) {
93
+ class ViewHolder (binding : SimpleItemRowBinding , views : List <SimpleItemOneBinding >) :
94
+ RecyclerView .ViewHolder (binding.root) {
85
95
val simpleKeyTexts = views.map { it.root.getChildAt(0 ) as TextView }
86
96
val wrappers = views.map { it.root.apply { getChildAt(1 ).visibility = View .GONE } }
87
97
}
0 commit comments