1
1
package com.ms8.smartirhub.android._tests.dev_playground.remote_layout
2
2
3
3
import android.content.Context
4
- import android.graphics.drawable.Drawable
5
4
import android.os.Parcel
6
5
import android.os.Parcelable
7
6
import android.util.AttributeSet
8
7
import android.util.Log
9
8
import android.view.LayoutInflater
10
9
import android.view.View
11
10
import android.view.ViewGroup
12
- import android.widget.TextView
13
11
import androidx.recyclerview.widget.RecyclerView
14
- import com.bumptech.glide.Glide
15
- import com.bumptech.glide.request.target.CustomTarget
16
- import com.bumptech.glide.request.transition.Transition
17
12
import com.ms8.smartirhub.android.R
18
13
import com.ms8.smartirhub.android._tests.dev_playground.remote_layout.asymmetricgridview.AGVRecyclerViewAdapter
19
14
import com.ms8.smartirhub.android._tests.dev_playground.remote_layout.asymmetricgridview.AsymmetricItem
@@ -23,9 +18,7 @@ import com.ms8.smartirhub.android._tests.dev_playground.remote_layout.asymmetric
23
18
import com.ms8.smartirhub.android.custom_views.ButtonView
24
19
import com.ms8.smartirhub.android.database.TempData
25
20
import com.ms8.smartirhub.android.models.firestore.RemoteProfile
26
- import com.ms8.smartirhub.android.models.firestore.RemoteProfile.Button.Properties.*
27
- import com.wajahatkarim3.easyvalidation.core.view_ktx.validUrl
28
- import org.jetbrains.anko.backgroundResource
21
+ import com.ms8.smartirhub.android.models.firestore.RemoteProfile.Button.Properties.BgStyle
29
22
30
23
class RemoteLayoutFromLibrary (context : Context , attrs : AttributeSet ): AsymmetricRecyclerView(context, attrs) {
31
24
@@ -37,26 +30,26 @@ class RemoteLayoutFromLibrary(context: Context, attrs: AttributeSet): Asymmetric
37
30
.apply {
38
31
name = " Button $i "
39
32
when (i) {
40
- 4 -> {
41
- style = RemoteProfile .Button .STYLE_BUTTON
33
+ 0 ,1 -> {
34
+ properties.columnSpan = 2
35
+ }
36
+ 2 -> {
37
+ style = RemoteProfile .Button .STYLE_BTN_INCREMENTER_VERTICAL
42
38
properties.bgStyle = BgStyle .BG_ROUND_RECT_TOP
43
39
properties.marginTop = 16
44
40
properties.marginStart = 16
45
41
properties.marginEnd = 16
46
42
properties.marginBottom = 0
43
+ properties.rowSpan = 2
47
44
}
48
45
8 -> {
49
- style = RemoteProfile .Button .STYLE_BUTTON
46
+ style = RemoteProfile .Button .STYLE_BTN_SINGLE_ACTION
50
47
properties.bgStyle = BgStyle .BG_ROUND_RECT_BOTTOM
51
48
properties.marginTop = 0
52
49
properties.marginStart = 16
53
50
properties.marginEnd = 16
54
51
properties.marginBottom = 16
55
52
}
56
- 1 ,2 -> {
57
- style = RemoteProfile .Button .STYLE_SPACE
58
- properties.bgStyle = BgStyle .BG_INVISIBLE
59
- }
60
53
}
61
54
})
62
55
}
@@ -88,7 +81,6 @@ class RemoteLayoutFromLibrary(context: Context, attrs: AttributeSet): Asymmetric
88
81
override fun getItemCount () =
89
82
TempData .tempRemoteProfile.buttons.size
90
83
91
-
92
84
override fun onBindViewHolder (holder : RemoteLayoutFromLibraryViewHolder , position : Int ) {
93
85
Log .d(" TEST" , " Binding ${TempData .tempRemoteProfile.buttons[position]?.name} " )
94
86
holder.bind(position)
@@ -99,75 +91,23 @@ class RemoteLayoutFromLibrary(context: Context, attrs: AttributeSet): Asymmetric
99
91
LayoutInflater .from(parent.context).inflate(R .layout.v_rmt_btn_base, parent, false)
100
92
) {
101
93
var button: RemoteProfile .Button ? = null
102
- var buttonText: TextView = itemView.findViewById(R .id.btnText)
103
- var buttonBackground : ButtonView = itemView.findViewById(R .id.btnBackground)
94
+ // var buttonText: TextView = itemView.findViewById(R.id.btnText)
95
+ var buttonView : ButtonView = itemView.findViewById(R .id.btnBackground)
104
96
105
97
fun bind (position : Int ) {
106
98
button = TempData .tempRemoteProfile.buttons[position]
99
+ if (button == null )
100
+ Log .w(" TEST##" , " BUTTON WAS NULL @ $position " )
107
101
button?.let { b ->
108
- buttonText.text = b.name
109
- val layoutParams = buttonBackground.layoutParams as MarginLayoutParams
110
- Log .d(" TEST" , " Setting bottom margin to ${Utils .dpToPx(itemView.context, b.properties.marginStart.toFloat())} for button $position " )
111
- layoutParams.setMargins(
112
- Utils .dpToPx(itemView.context, b.properties.marginStart.toFloat()),
113
- Utils .dpToPx(itemView.context, b.properties.marginTop.toFloat()),
114
- Utils .dpToPx(itemView.context, b.properties.marginEnd.toFloat()),
115
- Utils .dpToPx(itemView.context, b.properties.marginBottom.toFloat())
116
- )
117
- when (b.properties.bgStyle) {
118
- BgStyle .BG_CIRCLE -> {
119
- buttonBackground.backgroundResource = R .drawable.btn_bg_circle
120
- }
121
- BgStyle .BG_ROUND_RECT -> {
122
- buttonBackground.backgroundResource = R .drawable.btn_bg_round_rect
123
- }
124
- BgStyle .BG_ROUND_RECT_BOTTOM -> {
125
- buttonBackground.backgroundResource = R .drawable.btn_bg_round_bottom
126
- }
127
- BgStyle .BG_ROUND_RECT_TOP -> {
128
- buttonBackground.backgroundResource = R .drawable.btn_bg_round_top
129
- }
130
- BgStyle .BG_CUSTOM_IMAGE -> {
131
- val url = b.properties.bgUrl
132
- if (url.validUrl()) {
133
- Glide .with (buttonBackground).load(url).into(object : CustomTarget <Drawable >() {
134
- override fun onResourceReady (resource : Drawable , transition : Transition <in Drawable >? ) {
135
- buttonBackground.background = resource
136
- }
102
+ buttonView.properties = b.properties
103
+ buttonView.buttonText = b.name
137
104
138
- override fun onLoadCleared (placeholder : Drawable ? ) {}
139
- })
140
- }
141
- }
142
- BgStyle .BG_INVISIBLE -> {
143
- buttonBackground.backgroundResource = 0
144
- }
145
- }
146
- buttonBackground.layoutParams = layoutParams
147
- buttonBackground.outlineProvider = button?.properties?.let { ButtonView .ButtonOutlineProvider (it) }
148
- itemView.visibility = if (button?.properties?.bgStyle != BgStyle .BG_INVISIBLE )
105
+ itemView.visibility = if (b.properties.bgStyle != BgStyle .BG_INVISIBLE )
149
106
View .VISIBLE
150
107
else
151
108
View .INVISIBLE
152
109
itemView.invalidate()
153
110
}
154
-
155
-
156
-
157
-
158
- // when (button?.style ?: RemoteProfile.Button.STYLE_SPACE) {
159
- // RemoteProfile.Button.STYLE_SPACE -> {
160
- // Log.d("TEST", "Hiding space at pos $position")
161
- // itemView.visibility = View.INVISIBLE
162
- // itemView.isEnabled = false
163
- // }
164
- // else -> {
165
- // itemView.visibility = View.VISIBLE
166
- // itemView.isEnabled = true
167
- // }
168
- // }
169
- // var lp = itemView.layoutParams
170
- itemView.invalidate()
171
111
}
172
112
}
173
113
0 commit comments