Skip to content

Commit 87907f3

Browse files
committed
Android - #17
- Going to rework how the button data structure works
1 parent b5dcfaf commit 87907f3

File tree

18 files changed

+360
-252
lines changed

18 files changed

+360
-252
lines changed

android/SmartIRHub/.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/_tests/dev_playground/remote_layout/RemoteLayout.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class RemoteLayout(context: Context, attrs: AttributeSet) : AsymmetricGridView(c
111111
convertView
112112
}
113113
}
114-
v.findViewById<TextView>(R.id.btnText).text = button.name
114+
//v.findViewById<TextView>(R.id.btnText).text = button.name
115115

116116
when (position) {
117117
10,12 -> {
@@ -194,7 +194,7 @@ class RemoteLayout(context: Context, attrs: AttributeSet) : AsymmetricGridView(c
194194

195195
fun bind(button: RemoteProfile.Button) {
196196
this.button = button
197-
itemView.findViewById<TextView>(R.id.btnText).text = this.button?.name
197+
//itemView.findViewById<TextView>(R.id.btnText).text = this.button?.name
198198
}
199199
}
200200

android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/_tests/dev_playground/remote_layout/RemoteLayoutFromLibrary.kt

Lines changed: 15 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
package com.ms8.smartirhub.android._tests.dev_playground.remote_layout
22

33
import android.content.Context
4-
import android.graphics.drawable.Drawable
54
import android.os.Parcel
65
import android.os.Parcelable
76
import android.util.AttributeSet
87
import android.util.Log
98
import android.view.LayoutInflater
109
import android.view.View
1110
import android.view.ViewGroup
12-
import android.widget.TextView
1311
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
1712
import com.ms8.smartirhub.android.R
1813
import com.ms8.smartirhub.android._tests.dev_playground.remote_layout.asymmetricgridview.AGVRecyclerViewAdapter
1914
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
2318
import com.ms8.smartirhub.android.custom_views.ButtonView
2419
import com.ms8.smartirhub.android.database.TempData
2520
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
2922

3023
class RemoteLayoutFromLibrary(context: Context, attrs: AttributeSet): AsymmetricRecyclerView(context, attrs) {
3124

@@ -37,26 +30,26 @@ class RemoteLayoutFromLibrary(context: Context, attrs: AttributeSet): Asymmetric
3730
.apply {
3831
name = "Button $i"
3932
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
4238
properties.bgStyle = BgStyle.BG_ROUND_RECT_TOP
4339
properties.marginTop = 16
4440
properties.marginStart = 16
4541
properties.marginEnd = 16
4642
properties.marginBottom = 0
43+
properties.rowSpan = 2
4744
}
4845
8 -> {
49-
style = RemoteProfile.Button.STYLE_BUTTON
46+
style = RemoteProfile.Button.STYLE_BTN_SINGLE_ACTION
5047
properties.bgStyle = BgStyle.BG_ROUND_RECT_BOTTOM
5148
properties.marginTop = 0
5249
properties.marginStart = 16
5350
properties.marginEnd = 16
5451
properties.marginBottom = 16
5552
}
56-
1,2 -> {
57-
style = RemoteProfile.Button.STYLE_SPACE
58-
properties.bgStyle = BgStyle.BG_INVISIBLE
59-
}
6053
}
6154
})
6255
}
@@ -88,7 +81,6 @@ class RemoteLayoutFromLibrary(context: Context, attrs: AttributeSet): Asymmetric
8881
override fun getItemCount() =
8982
TempData.tempRemoteProfile.buttons.size
9083

91-
9284
override fun onBindViewHolder(holder: RemoteLayoutFromLibraryViewHolder, position: Int) {
9385
Log.d("TEST", "Binding ${TempData.tempRemoteProfile.buttons[position]?.name}")
9486
holder.bind(position)
@@ -99,75 +91,23 @@ class RemoteLayoutFromLibrary(context: Context, attrs: AttributeSet): Asymmetric
9991
LayoutInflater.from(parent.context).inflate(R.layout.v_rmt_btn_base, parent, false)
10092
) {
10193
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)
10496

10597
fun bind(position: Int) {
10698
button = TempData.tempRemoteProfile.buttons[position]
99+
if (button == null)
100+
Log.w("TEST##", "BUTTON WAS NULL @ $position")
107101
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
137104

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)
149106
View.VISIBLE
150107
else
151108
View.INVISIBLE
152109
itemView.invalidate()
153110
}
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()
171111
}
172112
}
173113

0 commit comments

Comments
 (0)