Skip to content

Commit e821801

Browse files
committed
Add sparse, bundle, animateLayoutChanges
1 parent b78a6b9 commit e821801

7 files changed

Lines changed: 74 additions & 5 deletions

File tree

.idea/modules.xml

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.omega_r.libs.extensions.bundle
2+
3+
import android.os.Bundle
4+
5+
/**
6+
* Created by Anton Knyazev on 2019-08-07.
7+
*/
8+
fun Bundle?.equalsBundle(other: Bundle?): Boolean {
9+
if (this != null && other != null) {
10+
11+
if (size() != other.size())
12+
return false
13+
14+
if (!keySet().containsAll(other.keySet()))
15+
return false
16+
17+
for (key in keySet()) {
18+
val valueOne = get(key)
19+
val valueTwo = other.get(key)
20+
if (valueOne is Bundle && valueTwo is Bundle) {
21+
if (!valueOne.equalsBundle(valueTwo)) return false
22+
} else if (valueOne != valueTwo) return false
23+
24+
}
25+
return true
26+
27+
} else return this == null && other == null
28+
}
29+
30+
fun Bundle.hashCodeBundle(): Int {
31+
var result = 0
32+
for (key in keySet()) {
33+
val value = get(key)
34+
result = 31 * result + when (value) {
35+
is Bundle -> value.hashCodeBundle()
36+
else -> value?.hashCode() ?: 0
37+
}
38+
}
39+
return result
40+
}

extensionslib/src/main/java/com/omega_r/libs/extensions/context/ResourceExtensions.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import android.content.Context
44
import android.graphics.drawable.AnimatedVectorDrawable
55
import android.graphics.drawable.Drawable
66
import android.os.Build
7+
import android.util.TypedValue
8+
import androidx.annotation.AttrRes
79
import androidx.annotation.ColorRes
810
import androidx.annotation.DrawableRes
911
import androidx.annotation.RequiresApi
@@ -24,3 +26,8 @@ fun Context.getCompatColor(@ColorRes id: Int): Int {
2426
return ContextCompat.getColor(this, id)
2527
}
2628

29+
fun Context.getColorByAttribute(@AttrRes attrInt: Int): Int {
30+
return TypedValue().run {
31+
if (theme.resolveAttribute(attrInt, this, true)) data else 0
32+
}
33+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.omega_r.libs.extensions.sparse
2+
3+
import android.util.SparseArray
4+
5+
/**
6+
* Created by Anton Knyazev on 2019-08-07.
7+
*/
8+
inline fun <T> SparseArray<T>.getOrPut(key: Int, defaultValue: () -> T): T {
9+
val value = get(key)
10+
return if (value == null) {
11+
val answer = defaultValue()
12+
put(key, answer)
13+
answer
14+
} else {
15+
value
16+
}
17+
}

extensionslib/src/main/java/com/omega_r/libs/extensions/view/ViewExtensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ import androidx.annotation.LayoutRes
66

77
fun View.inflate(@LayoutRes resource: Int, root: ViewGroup): View {
88
return View.inflate(context, resource, root)
9-
}
9+
}

extensionslib/src/main/java/com/omega_r/libs/extensions/view/ViewGroupExtensions.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.omega_r.libs.extensions.view
22

3+
import android.animation.LayoutTransition
34
import android.view.View
45
import android.view.ViewGroup
56

@@ -19,4 +20,10 @@ fun ViewGroup.getFirstChildOrNull(): View? {
1920
fun ViewGroup.getLastChildOrNull(): View? {
2021
if (childCount == 0) return null
2122
return getChildAt(childCount - 1)
22-
}
23+
}
24+
25+
var ViewGroup.animateLayoutChanges: Boolean
26+
get() = layoutTransition is LayoutTransition
27+
set(value) {
28+
layoutTransition = if (value) LayoutTransition() else null
29+
}

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

0 commit comments

Comments
 (0)