Skip to content

Commit 4bf299d

Browse files
authored
Merge pull request #5 from valartech/loading-layout-bug-fix
Loading layout bug fix
2 parents d570ee2 + fabfae1 commit 4bf299d

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<TextView
4545
android:layout_width="match_parent"
4646
android:layout_height="match_parent"
47-
android:background="#ee0000"
47+
android:background="#ff0000"
4848
android:gravity="center"
4949
android:tag="@string/ll_error"
5050
android:text="Error!"

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ buildscript {
2828

2929
}
3030
dependencies {
31-
classpath 'com.android.tools.build:gradle:3.6.0-beta02'
31+
classpath 'com.android.tools.build:gradle:3.6.0-beta03'
3232
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
3333
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
3434
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:${dokka_version}"

commons/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ apply plugin: 'org.jetbrains.dokka-android'
66

77

88
static def getAppVersionCode() {
9-
return 24
9+
return 25
1010
}
1111

1212
static def getAppVersionName() {
13-
return "0.8.3"
13+
return "0.8.4"
1414
}
1515

1616
group = 'com.github.valartech'

commons/src/main/kotlin/com/valartech/commons/views/LoadingLayout.kt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import android.util.AttributeSet
77
import android.view.View
88
import android.widget.FrameLayout
99
import androidx.annotation.IntDef
10+
import androidx.annotation.StringRes
11+
import androidx.core.view.children
1012
import com.valartech.commons.R
1113

1214
/**
@@ -63,10 +65,10 @@ class LoadingLayout @JvmOverloads constructor(
6365
errorView = getChildAt(3)
6466

6567
//If views are specified with tags, override
66-
findViewWithTag<View?>(context.getString(R.string.ll_loading))?.let { loadingView = it }
67-
findViewWithTag<View?>(context.getString(R.string.ll_complete))?.let { completeView = it }
68-
findViewWithTag<View?>(context.getString(R.string.ll_empty))?.let { emptyView = it }
69-
findViewWithTag<View?>(context.getString(R.string.ll_error))?.let { errorView = it }
68+
findChildViewWithTag(R.string.ll_loading)?.let { loadingView = it }
69+
findChildViewWithTag(R.string.ll_complete)?.let { completeView = it }
70+
findChildViewWithTag(R.string.ll_empty)?.let { emptyView = it }
71+
findChildViewWithTag(R.string.ll_error)?.let { errorView = it }
7072

7173
if (!isInEditMode) {
7274
if (loadingView == null) {
@@ -111,8 +113,12 @@ class LoadingLayout @JvmOverloads constructor(
111113
loadingView?.visibility = View.GONE
112114
completeView?.visibility = View.VISIBLE
113115
} else if (currentState == LOADING) {
116+
//if we're showing results after loading, animate the appearance of the
117+
//complete view
114118
crossfadeCompleteView()
115119
} else {
120+
//if we're showing the complete state in any other case, then just show the
121+
//view immediately
116122
loadingView?.visibility = View.GONE
117123
completeView?.visibility = View.VISIBLE
118124
}
@@ -159,6 +165,18 @@ class LoadingLayout @JvmOverloads constructor(
159165
})
160166
}
161167

168+
/**
169+
* Searches only the direct children of this view for a child view with the specified tag.
170+
*/
171+
private fun findChildViewWithTag(@StringRes tagRes: Int): View? {
172+
children.forEach {
173+
if (context.getString(tagRes) == it.tag) {
174+
return it
175+
}
176+
}
177+
return null
178+
}
179+
162180
companion object {
163181
//the values of these constants is significant, they correspond to params in attrs.xml
164182
const val LOADING = 1

0 commit comments

Comments
 (0)