Skip to content
This repository was archived by the owner on Jun 3, 2023. It is now read-only.

Commit 1ce532a

Browse files
improvements
1 parent 6608a4a commit 1ce532a

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

statelayout/src/main/java/com/github/ahmed7official/statelayout/StateLayout.kt

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import android.view.LayoutInflater
99
import android.view.View
1010
import android.widget.FrameLayout
1111
import android.widget.ImageView
12+
import android.widget.LinearLayout
1213
import android.widget.TextView
1314
import androidx.constraintlayout.widget.ConstraintLayout
1415
import androidx.core.content.ContextCompat
@@ -90,20 +91,19 @@ class StateLayout @JvmOverloads constructor(
9091

9192
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
9293

93-
fun stateLoading(loadingMessage: String = "Loading, please wait") {
94+
fun stateLoading(
95+
loadingMessage: String = "Loading, please wait",
96+
backgroundColor: Int = R.color.colorPrimaryDark
97+
) {
9498
Log.i("zxc", "stateLoading()")
9599

96100
layoutLoading.findViewById<TextView>(R.id.tvLoading).text = loadingMessage
101+
layoutLoading.findViewById<LinearLayout>(R.id.layoutLoading).setBackgroundColor(ContextCompat.getColor(context, backgroundColor))
97102

98-
children.forEach {
99-
if (it == layoutLoading) {
100-
it.visibility = View.VISIBLE
101-
} else {
102-
it.visibility = View.GONE
103-
}
104-
}//forEach
105103

106-
}//showContent()
104+
setState(layoutLoading)
105+
106+
}//stateLoading()
107107

108108
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
109109

@@ -153,18 +153,7 @@ class StateLayout @JvmOverloads constructor(
153153
// - - - - - - - - - - - - - -
154154

155155

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)
168157

169158
}//stateRetry()
170159

@@ -187,19 +176,28 @@ class StateLayout @JvmOverloads constructor(
187176

188177

189178

179+
setState(layoutError)
180+
181+
}//stateError()
182+
183+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
184+
185+
private fun setState(state: View){
186+
190187
children.forEach {
191-
if (it == layoutError) {
188+
if (it == state) {
192189
it.visibility = View.VISIBLE
193190
return@forEach
194191
}//if
195192
}//forEach
196193

197194
children.forEach {
198-
if (it != layoutError) {
195+
if (it != state) {
199196
it.visibility = View.GONE
200197
}//if
201198
}//forEach
202199

203-
}//stateError()
200+
}//setState()
201+
204202

205203
}//StateLayout

statelayout/src/main/res/layout/layout_loading.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout
3+
android:id="@+id/layoutLoading"
34
android:background="@android:color/white"
45
android:gravity="center"
56
xmlns:android="http://schemas.android.com/apk/res/android"

0 commit comments

Comments
 (0)