-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ceedd77
commit 02fc68c
Showing
10 changed files
with
117 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
plugins { | ||
id 'com.android.library' | ||
id 'org.jetbrains.kotlin.android' | ||
} | ||
|
||
apply from: '../gradle/publication.gradle' | ||
|
||
android { | ||
namespace = "com.bumble.appyx.utils" | ||
compileSdk 32 | ||
|
||
defaultConfig { | ||
minSdk 21 | ||
targetSdk 32 | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = JavaVersion.VERSION_1_8 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest /> |
10 changes: 10 additions & 0 deletions
10
.../src/main/java/com/bumble/appyx/utils/customisations/MutableNodeCustomisationDirectory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.bumble.appyx.utils.customisations | ||
|
||
import kotlin.reflect.KClass | ||
|
||
interface MutableNodeCustomisationDirectory : NodeCustomisationDirectory { | ||
|
||
fun <T : Any> putSubDirectory(key: KClass<T>, value: NodeCustomisationDirectory) | ||
|
||
fun <T : NodeCustomisation> put(key: KClass<T>, value: T) | ||
} |
3 changes: 3 additions & 0 deletions
3
customisations/src/main/java/com/bumble/appyx/utils/customisations/NodeCustomisation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.bumble.appyx.utils.customisations | ||
|
||
interface NodeCustomisation |
19 changes: 19 additions & 0 deletions
19
...sations/src/main/java/com/bumble/appyx/utils/customisations/NodeCustomisationDirectory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.bumble.appyx.utils.customisations | ||
|
||
import kotlin.reflect.KClass | ||
|
||
interface NodeCustomisationDirectory { | ||
|
||
val parent: NodeCustomisationDirectory? | ||
|
||
fun <T : Any> getSubDirectory(key: KClass<T>) : NodeCustomisationDirectory? | ||
|
||
fun <T : Any> getSubDirectoryOrSelf(key: KClass<T>) : NodeCustomisationDirectory | ||
|
||
fun <T : NodeCustomisation> get(key: KClass<T>) : T? | ||
|
||
fun <T : NodeCustomisation> getRecursively(key: KClass<T>) : T? | ||
|
||
fun <T : NodeCustomisation> getRecursivelyOrDefault(default: T) : T = | ||
get(default::class) ?: parent?.get(default::class) ?: default | ||
} |
52 changes: 52 additions & 0 deletions
52
...ons/src/main/java/com/bumble/appyx/utils/customisations/NodeCustomisationDirectoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.bumble.appyx.utils.customisations | ||
|
||
import kotlin.reflect.KClass | ||
|
||
open class NodeCustomisationDirectoryImpl( | ||
override val parent: NodeCustomisationDirectory? = null | ||
) : MutableNodeCustomisationDirectory { | ||
|
||
private val map: MutableMap<Any, Any> = hashMapOf() | ||
|
||
override fun <T : NodeCustomisation> put(key: KClass<T>, value: T) { | ||
map[key] = value | ||
} | ||
|
||
fun <T : Any> put(vararg values: T) { | ||
values.forEach { | ||
map[it::class] = it | ||
} | ||
} | ||
|
||
inline operator fun <reified T : Any> T.unaryPlus() { | ||
put(this) | ||
} | ||
|
||
override fun <T : NodeCustomisation> get(key: KClass<T>): T? = | ||
map[key] as? T | ||
|
||
override fun <T : NodeCustomisation> getRecursively(key: KClass<T>): T? = | ||
get(key) ?: parent?.get(key) | ||
|
||
override fun <T : Any> putSubDirectory(key: KClass<T>, value: NodeCustomisationDirectory) { | ||
map[key] = value | ||
} | ||
|
||
override fun <T : Any> getSubDirectory(key: KClass<T>): NodeCustomisationDirectory?= | ||
map[key] as? NodeCustomisationDirectory | ||
|
||
override fun <T : Any> getSubDirectoryOrSelf(key: KClass<T>): NodeCustomisationDirectory { | ||
val subDir = map.keys.firstOrNull { | ||
it is KClass<*> && it.java.isAssignableFrom(key.java) | ||
} | ||
|
||
return map[subDir] as? NodeCustomisationDirectory ?: this | ||
} | ||
|
||
operator fun KClass<*>.invoke(block: NodeCustomisationDirectoryImpl.() -> Unit) { | ||
if (map.containsKey(this)) { | ||
// TODO warning for accidental override? | ||
} | ||
map[this] = NodeCustomisationDirectoryImpl(this@NodeCustomisationDirectoryImpl).apply(block) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters