Skip to content

Commit

Permalink
Move app-tree-utils into repo
Browse files Browse the repository at this point in the history
  • Loading branch information
CherryPerry committed Jul 4, 2022
1 parent ceedd77 commit 02fc68c
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ android {
}

dependencies {
api libs.appTreeUtils
api project(':customisations')
api libs.kotlin.coroutines.android
api libs.androidx.lifecycle.common
api libs.compose.animation.core
Expand Down
1 change: 1 addition & 0 deletions customisations/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
25 changes: 25 additions & 0 deletions customisations/build.gradle
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
}
}
2 changes: 2 additions & 0 deletions customisations/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest />
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)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.bumble.appyx.utils.customisations

interface NodeCustomisation
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
}
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)
}
}
4 changes: 1 addition & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ kotlin = "1.6.21"
rxjava2 = "2.2.21"
rxandroid = "2.1.1"
junit5 = "5.8.2"
appTreeUtils = "0.1.1"

[libraries]
appTreeUtils = { module = "com.github.badoo:app-tree-utils", version.ref = "appTreeUtils" }
android-plugin = "com.android.tools.build:gradle:7.1.3"
androidx-activity-compose = "androidx.activity:activity-compose:1.3.1"
androidx-appcompat = "androidx.appcompat:appcompat:1.3.1"
Expand All @@ -38,7 +36,7 @@ junit = "junit:junit:4.13.2"
kotlin-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "coroutines" }
kotlin-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
kotlin-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
mvicore = { module = "com.github.badoo.RIBs:rib-mvicore", version.ref = "ribs" }
mvicore = { module = "com.github.badoo.RIBs:rib-mvicore", version.ref = "ribs" }
ribs-base = { module = "com.github.badoo.RIBs:rib-base", version.ref = "ribs" }
ribs-compose = { module = "com.github.badoo.RIBs:rib-compose", version.ref = "ribs" }
ribs-rx = { module = "com.github.badoo.RIBs:rib-rx2", version.ref = "ribs" }
Expand Down
5 changes: 3 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ include ':app',
':sandbox',
':interop-rx2',
':interop-ribs',
'testing-ui',
':routing-source-addons'
':testing-ui',
':routing-source-addons',
':customisations'

0 comments on commit 02fc68c

Please sign in to comment.