Skip to content

Commit

Permalink
refactor(layers): 规范类名方法名
Browse files Browse the repository at this point in the history
  • Loading branch information
goweii committed Oct 30, 2021
1 parent 9c73b8f commit 68e2f6c
Show file tree
Hide file tree
Showing 18 changed files with 320 additions and 207 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import per.goweii.anylayer.Layer;

public class DefaultOnVisibleChangedListener implements Layer.OnVisibleChangedListener {
public class DefaultOnVisibleChangeListener implements Layer.OnVisibleChangeListener {
@Override
public void onShow(@NonNull Layer layer) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ fun <T : DialogLayer> T.swipeTransformer(swipeTransformer: DialogLayer.SwipeTran
this.setSwipeTransformer(swipeTransformer)
}

fun <T : DialogLayer> T.onSwipeStart(onStart: T.() -> Unit) = this.apply {
fun <T : DialogLayer> T.doOnSwipeStart(onStart: T.() -> Unit) = this.apply {
this.addOnSwipeListener(object : DefaultDialogOnSwipeListener() {
override fun onStart(layer: DialogLayer) {
this@apply.onStart()
}
})
}

fun <T : DialogLayer> T.onSwiping(onSwiping: T.(direction: Int, fraction: Float) -> Unit) = this.apply {
fun <T : DialogLayer> T.doOnSwiping(onSwiping: T.(direction: Int, fraction: Float) -> Unit) = this.apply {
this.addOnSwipeListener(object : DefaultDialogOnSwipeListener() {
override fun onSwiping(layer: DialogLayer,
@SwipeLayout.Direction direction: Int,
Expand All @@ -57,7 +57,7 @@ fun <T : DialogLayer> T.onSwiping(onSwiping: T.(direction: Int, fraction: Float)
})
}

fun <T : DialogLayer> T.onSwipeEnd(onEnd: T.(direction: Int) -> Unit) = this.apply {
fun <T : DialogLayer> T.doOnSwipeEnd(onEnd: T.(direction: Int) -> Unit) = this.apply {
this.addOnSwipeListener(object : DefaultDialogOnSwipeListener() {
override fun onEnd(layer: DialogLayer, @SwipeLayout.Direction direction: Int) {
this@apply.onEnd(direction)
Expand Down Expand Up @@ -183,10 +183,10 @@ fun <T : DialogLayer> T.outsideInterceptTouchEvent(enable: Boolean) = this.apply
this.setOutsideInterceptTouchEvent(enable)
}

fun <T : DialogLayer> T.onOutsideTouch(onOutsideTouched: T.() -> Unit) = this.apply {
fun <T : DialogLayer> T.doOnOutsideTouch(onOutsideTouched: T.() -> Unit) = this.apply {
this.setOnOutsideTouchListener { this@apply.onOutsideTouched() }
}

fun <T : DialogLayer> T.outsideTouchToDismiss(enable: Boolean) = this.apply {
fun <T : DialogLayer> T.dismissOnOutsideTouch(enable: Boolean) = this.apply {
this.setOutsideTouchToDismiss(enable)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ fun <T : GuideLayer> T.mapping(init: GuideLayer.Mapping.() -> Unit) = this.apply
this.addMapping(GuideLayer.Mapping().apply { init() })
}

fun GuideLayer.Mapping.onClick(@IdRes viewId: Int, onClickListener: GuideLayer.Mapping.(view: View) -> Unit) = this.apply {
this.addOnClickListener(Layer.OnClickListener { _, v -> this.onClickListener(v) }, viewId)
fun GuideLayer.Mapping.doOnClick(@IdRes viewId: Int, onClickListener: GuideLayer.Mapping.(view: View) -> Unit) = this.apply {
this.addOnClickListener({ _, v -> this.onClickListener(v) }, viewId)
}
32 changes: 16 additions & 16 deletions anylayer-ktx/src/main/java/per/goweii/anylayer/ktx/Layer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,77 +6,77 @@ import androidx.annotation.IdRes
import per.goweii.anylayer.Layer
import per.goweii.anylayer.ext.DefaultOnDismissListener
import per.goweii.anylayer.ext.DefaultOnShowListener
import per.goweii.anylayer.ext.DefaultOnVisibleChangedListener
import per.goweii.anylayer.ext.DefaultOnVisibleChangeListener

fun <T : Layer> T.onClick(@IdRes viewId: Int, onClickListener: T.(view: View) -> Unit) = this.apply {
fun <T : Layer> T.doOnClick(@IdRes viewId: Int, onClickListener: T.(view: View) -> Unit) = this.apply {
this.addOnClickListener(Layer.OnClickListener { _, v -> this.onClickListener(v) }, viewId)
}

fun <T : Layer> T.onClickToDismiss(@IdRes viewId: Int, onClickListener: (T.(view: View) -> Unit)? = null) = this.apply {
fun <T : Layer> T.dismissOnClick(@IdRes viewId: Int, onClickListener: (T.(view: View) -> Unit)? = null) = this.apply {
onClickListener?.let {
this.addOnClickToDismissListener(Layer.OnClickListener { _, v -> this.it(v) }, viewId)
} ?: addOnClickToDismissListener(null, viewId)
}

fun <T : Layer> T.onLongClick(@IdRes viewId: Int, onLongClickListener: T.(view: View) -> Boolean) = this.apply {
fun <T : Layer> T.doOnLongClick(@IdRes viewId: Int, onLongClickListener: T.(view: View) -> Boolean) = this.apply {
this.addOnLongClickListener(Layer.OnLongClickListener { _, v -> this.onLongClickListener(v) }, viewId)
}

fun <T : Layer> T.onLongClickToDismiss(@IdRes viewId: Int, onLongClickListener: (T.(view: View) -> Boolean)? = null) = this.apply {
fun <T : Layer> T.dismissOnLongClick(@IdRes viewId: Int, onLongClickListener: (T.(view: View) -> Boolean)? = null) = this.apply {
onLongClickListener?.let {
this.addOnLongClickToDismissListener(Layer.OnLongClickListener { _, v -> this.it(v) }, viewId)
} ?: addOnLongClickToDismissListener(null, viewId)
}

fun <T : Layer> T.onBindData(dataBinder: T.() -> Unit) = this.apply {
this.addOnBindDataListener { this.dataBinder() }
fun <T : Layer> T.doBindData(dataBinder: T.() -> Unit) = this.apply {
this.addDataBindCallback { this.dataBinder() }
}

fun <T : Layer> T.onInitialize(onInitialize: T.() -> Unit) = this.apply {
fun <T : Layer> T.doOnInitialize(onInitialize: T.() -> Unit) = this.apply {
this.addOnInitializeListener { this.onInitialize() }
}

fun <T : Layer> T.onShow(onShow: T.() -> Unit) = this.apply {
this.addOnVisibleChangeListener(object : DefaultOnVisibleChangedListener() {
fun <T : Layer> T.doOnShow(onShow: T.() -> Unit) = this.apply {
this.addOnVisibleChangeListener(object : DefaultOnVisibleChangeListener() {
override fun onShow(layer: Layer) {
onShow.invoke(this@apply)
}
})
}

fun <T : Layer> T.onDismiss(onDismiss: T.() -> Unit) = this.apply {
this.addOnVisibleChangeListener(object : DefaultOnVisibleChangedListener() {
fun <T : Layer> T.doOnDismiss(onDismiss: T.() -> Unit) = this.apply {
this.addOnVisibleChangeListener(object : DefaultOnVisibleChangeListener() {
override fun onDismiss(layer: Layer) {
onDismiss.invoke(this@apply)
}
})
}

fun <T : Layer> T.onPreShow(onPreShow: T.() -> Unit) = this.apply {
fun <T : Layer> T.doOnPreShow(onPreShow: T.() -> Unit) = this.apply {
this.addOnShowListener(object : DefaultOnShowListener() {
override fun onPreShow(layer: Layer) {
this@apply.onPreShow()
}
})
}

fun <T : Layer> T.onPostShow(onPostShow: T.() -> Unit) = this.apply {
fun <T : Layer> T.doOnPostShow(onPostShow: T.() -> Unit) = this.apply {
this.addOnShowListener(object : DefaultOnShowListener() {
override fun onPostShow(layer: Layer) {
this@apply.onPostShow()
}
})
}

fun <T : Layer> T.onPreDismiss(onPreDismiss: T.() -> Unit) = this.apply {
fun <T : Layer> T.doOnPreDismiss(onPreDismiss: T.() -> Unit) = this.apply {
this.addOnDismissListener(object : DefaultOnDismissListener() {
override fun onPreDismiss(layer: Layer) {
this@apply.onPreDismiss()
}
})
}

fun <T : Layer> T.onPostDismiss(onPostDismiss: T.() -> Unit) = this.apply {
fun <T : Layer> T.doOnPostDismiss(onPostDismiss: T.() -> Unit) = this.apply {
this.addOnDismissListener(object : DefaultOnDismissListener() {
override fun onPostDismiss(layer: Layer) {
this@apply.onPostDismiss()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ fun <T : NotificationLayer> T.duration(duration: Long) = this.apply {
}

fun <T : NotificationLayer> T.onNotificationClick(onNotificationClick: T.(view: View) -> Unit) = this.apply {
this.setOnNotificationClickListener { _, view -> this.onNotificationClick(view) }
this.addOnNotificationClickListener { _, view -> this.onNotificationClick(view) }
}

fun <T : NotificationLayer> T.onNotificationLongClick(onNotificationClick: T.(view: View) -> Boolean) = this.apply {
this.setOnNotificationLongClickListener { _, view -> this.onNotificationClick(view) }
fun <T : NotificationLayer> T.doOnNotificationLongClick(onNotificationClick: T.(view: View) -> Boolean) = this.apply {
this.addOnNotificationLongClickListener { _, view -> this.onNotificationClick(view) }
}

fun <T : NotificationLayer> T.autoDismiss(autoDismiss: Boolean) = this.apply {
Expand All @@ -115,15 +115,15 @@ fun <T : NotificationLayer> T.swipeTransformer(swipeTransformer: NotificationLay
this.setSwipeTransformer(swipeTransformer)
}

fun <T : NotificationLayer> T.onSwipeStart(onStart: T.() -> Unit) = this.apply {
fun <T : NotificationLayer> T.doOnSwipeStart(onStart: T.() -> Unit) = this.apply {
this.addOnSwipeListener(object : DefaultNotificationOnSwipeListener() {
override fun onStart(layer: NotificationLayer) {
this@apply.onStart()
}
})
}

fun <T : NotificationLayer> T.onSwiping(onSwiping: T.(direction: Int, fraction: Float) -> Unit) = this.apply {
fun <T : NotificationLayer> T.doOnSwiping(onSwiping: T.(direction: Int, fraction: Float) -> Unit) = this.apply {
this.addOnSwipeListener(object : DefaultNotificationOnSwipeListener() {
override fun onSwiping(layer: NotificationLayer,
@SwipeLayout.Direction direction: Int,
Expand All @@ -133,7 +133,7 @@ fun <T : NotificationLayer> T.onSwiping(onSwiping: T.(direction: Int, fraction:
})
}

fun <T : NotificationLayer> T.onSwipeEnd(onEnd: T.(direction: Int) -> Unit) = this.apply {
fun <T : NotificationLayer> T.doOnSwipeEnd(onEnd: T.(direction: Int) -> Unit) = this.apply {
this.addOnSwipeListener(object : DefaultNotificationOnSwipeListener() {
override fun onEnd(layer: NotificationLayer, @SwipeLayout.Direction direction: Int) {
this@apply.onEnd(direction)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ fun <T : OverlayLayer> T.paddingBottom(padding: Int) = this.apply {
this.setPaddingBottom(padding)
}

fun <T : OverlayLayer> T.doOnFloatClick(onFloatClick: T.(view: View) -> Unit) = this.apply {
fun <T : OverlayLayer> T.doOnOverlayClick(onFloatClick: T.(view: View) -> Unit) = this.apply {
this.addOnOverlayClickListener { _, view -> this.onFloatClick(view) }
}

fun <T : OverlayLayer> T.onFloatLongClick(onFloatClick: T.(view: View) -> Boolean) = this.apply {
fun <T : OverlayLayer> T.doOnOverlayLongClick(onFloatClick: T.(view: View) -> Boolean) = this.apply {
this.setOnOverlayLongClickListener { _, view -> this.onFloatClick(view) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ fun <T : PopupLayer> T.updateLocationInterceptor(interceptor: PopupLayer.UpdateL
this.setUpdateLocationInterceptor(interceptor)
}

fun <T : PopupLayer> T.onViewTreeScrollChanged(onScrollChanged: T.() -> Unit) = this.apply {
fun <T : PopupLayer> T.doOnViewTreeScrollChanged(onScrollChanged: T.() -> Unit) = this.apply {
this.setOnViewTreeScrollChangedListener { this.onScrollChanged() }
}

fun <T : PopupLayer> T.scrollChangedToDismiss(enable: Boolean) = this.apply {
fun <T : PopupLayer> T.dismissOnScrollChanged(enable: Boolean) = this.apply {
this.setScrollChangedToDismiss(enable)
}

Expand Down
1 change: 1 addition & 0 deletions anylayer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ android {

dependencies {
compileOnly 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'per.goweii.visualeffect:visualeffect-core:1.0.3'
implementation 'per.goweii.visualeffect:visualeffect-blur:1.0.3'
implementation 'per.goweii.visualeffect:visualeffect-view:1.0.3'
Expand Down
Loading

0 comments on commit 68e2f6c

Please sign in to comment.