Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
Create sets using DSL
  • Loading branch information
STRENCH0 committed Oct 22, 2019
1 parent 7015a75 commit 4496946
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions easydnd/src/main/java/ru/checka/easydnd/DragAndDropDslFacade.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ru.checka.easydnd

import android.view.View

@ConfigMarker
class DragAndDropDslFacade<S, R>(
private val dragAndDropManager: DragAndDropManager<S, R>
Expand All @@ -10,11 +12,18 @@ class DragAndDropDslFacade<S, R>(
newReceivers: Set<DragAndDropObject<R>>,
init: (DragAndDropLocalConfig<S, R>.() -> Unit)? = null
) {
var localConfig: DragAndDropLocalConfig<S, R>? = null
if (init != null) {
val localConfig = DragAndDropLocalConfig<S, R>()
localConfig = DragAndDropLocalConfig<S, R>()
localConfig.init()
dragAndDropManager.mapSets(newSenders, newReceivers, localConfig)
}
dragAndDropManager.mapSets(newSenders, newReceivers, localConfig)
}

fun mapSets(init: (DslSetConfig<S, R>.() -> Unit)) {
val dslSetConfig = DslSetConfig<S, R>()
dslSetConfig.init()
mapSets(dslSetConfig.senders, dslSetConfig.receivers, dslSetConfig.localConfigInit)
}

fun default(init: (DragAndDropDefaultConfig<S, R>.() -> Unit)) {
Expand All @@ -23,4 +32,28 @@ class DragAndDropDslFacade<S, R>(



}
}

@ConfigMarker
class DslSetConfig<S, R> {

internal var localConfigInit: (DragAndDropLocalConfig<S, R>.() -> Unit)? = null

internal var senders: MutableSet<DragAndDropObject<S>> = mutableSetOf()

internal var receivers: MutableSet<DragAndDropObject<R>> = mutableSetOf()

fun config(init: (DragAndDropLocalConfig<S, R>.() -> Unit)?) {
localConfigInit = init
}

infix fun View.assignSender(assigned: S) {
senders.add(DragAndDropObject(this, assigned))
}

infix fun View.assignReceiver(assigned: R) {
receivers.add(DragAndDropObject(this, assigned))
}

}

0 comments on commit 4496946

Please sign in to comment.