@@ -9,6 +9,7 @@ import android.view.LayoutInflater
9
9
import android.view.View
10
10
import android.widget.FrameLayout
11
11
import android.widget.ImageView
12
+ import android.widget.LinearLayout
12
13
import android.widget.TextView
13
14
import androidx.constraintlayout.widget.ConstraintLayout
14
15
import androidx.core.content.ContextCompat
@@ -90,20 +91,19 @@ class StateLayout @JvmOverloads constructor(
90
91
91
92
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
92
93
93
- fun stateLoading (loadingMessage : String = "Loading , please wait") {
94
+ fun stateLoading (
95
+ loadingMessage : String = "Loading , please wait",
96
+ backgroundColor : Int = R .color.colorPrimaryDark
97
+ ) {
94
98
Log .i(" zxc" , " stateLoading()" )
95
99
96
100
layoutLoading.findViewById<TextView >(R .id.tvLoading).text = loadingMessage
101
+ layoutLoading.findViewById<LinearLayout >(R .id.layoutLoading).setBackgroundColor(ContextCompat .getColor(context, backgroundColor))
97
102
98
- children.forEach {
99
- if (it == layoutLoading) {
100
- it.visibility = View .VISIBLE
101
- } else {
102
- it.visibility = View .GONE
103
- }
104
- }// forEach
105
103
106
- }// showContent()
104
+ setState(layoutLoading)
105
+
106
+ }// stateLoading()
107
107
108
108
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
109
109
@@ -153,18 +153,7 @@ class StateLayout @JvmOverloads constructor(
153
153
// - - - - - - - - - - - - - -
154
154
155
155
156
- children.forEach {
157
- if (it == layoutRetry) {
158
- it.visibility = View .VISIBLE
159
- return @forEach
160
- }// if
161
- }// forEach
162
-
163
- children.forEach {
164
- if (it != layoutRetry) {
165
- it.visibility = View .GONE
166
- }// if
167
- }// forEach
156
+ setState(layoutRetry)
168
157
169
158
}// stateRetry()
170
159
@@ -187,19 +176,28 @@ class StateLayout @JvmOverloads constructor(
187
176
188
177
189
178
179
+ setState(layoutError)
180
+
181
+ }// stateError()
182
+
183
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
184
+
185
+ private fun setState (state : View ){
186
+
190
187
children.forEach {
191
- if (it == layoutError ) {
188
+ if (it == state ) {
192
189
it.visibility = View .VISIBLE
193
190
return @forEach
194
191
}// if
195
192
}// forEach
196
193
197
194
children.forEach {
198
- if (it != layoutError ) {
195
+ if (it != state ) {
199
196
it.visibility = View .GONE
200
197
}// if
201
198
}// forEach
202
199
203
- }// stateError()
200
+ }// setState()
201
+
204
202
205
203
}//StateLayout
0 commit comments