Skip to content

Commit

Permalink
AdapteDelegate DSL 功能重构;增加 dsl 目录;getItemId 增加 position 参数;完善注释
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCheen committed Sep 2, 2022
1 parent 9f4e0f6 commit f40183c
Show file tree
Hide file tree
Showing 14 changed files with 277 additions and 355 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package me.yifeiyuan.flapdev

import android.view.View
import me.yifeiyuan.flap.decoration.LinearSpaceItemDecoration
import me.yifeiyuan.flap.delegate.adapterDelegate
import me.yifeiyuan.flap.dsl.adapterDelegate
import me.yifeiyuan.flap.ext.bindTextView
import me.yifeiyuan.flapdev.components.SimpleTextModel
import me.yifeiyuan.flapdev.testcases.BaseTestcaseFragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import android.util.Log
import android.view.View
import android.widget.ImageView
import me.yifeiyuan.flap.FlapAdapter
import me.yifeiyuan.flap.delegate.LayoutAdapterDelegate
import me.yifeiyuan.flap.delegate.adapterDelegate
import me.yifeiyuan.flap.dsl.adapterDelegate
import me.yifeiyuan.flap.ext.bindButton
import me.yifeiyuan.flap.ext.bindTextView
import me.yifeiyuan.flap.ext.bindView
Expand Down Expand Up @@ -127,13 +126,27 @@ class AdapterDelegateDSLTestcase : BaseTestcaseFragment() {
}
}

val simpleImageDelegate = LayoutAdapterDelegate(SimpleImageModel::class.java,
R.layout.flap_item_simple_image) { model ->
bindView<ImageView>(R.id.logo) {
setOnClickListener {
toast("simpleImageDelegate clicked")
// val simpleImageDelegate = LayoutAdapterDelegate(SimpleImageModel::class.java,
// R.layout.flap_item_simple_image) { model ->
// bindView<ImageView>(R.id.logo) {
// setOnClickListener {
// toast("simpleImageDelegate clicked")
// }
// }
// }

val simpleImageDelegate = adapterDelegate<SimpleImageModel>(R.layout.flap_item_simple_image) {

onBind { model, position, payloads, adapter ->
bindView<ImageView>(R.id.logo) {
setOnClickListener {
toast("simpleImageDelegate clicked")
}
}
}
onResume {
Log.d(TAG, "simpleImageDelegate onResume() called $this")
}
}

adapter.registerAdapterDelegates(simpleTextDelegate, simpleImageDelegate, testAllDelegate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ private TypeSpec createAdapterDelegateTypeSpec(final RoundEnvironment roundEnvir
.addModifiers(Modifier.PUBLIC)
// .addParameter(itemModelClass, "model")
.addParameter(CLASS_OBJECT, "model")
.addParameter(Integer.TYPE, "position")
.addStatement("return 0")
.returns(Long.TYPE);

Expand Down
26 changes: 24 additions & 2 deletions flap/src/main/java/me/yifeiyuan/flap/ComponentConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,42 @@ import me.yifeiyuan.flap.ext.SwipeDragHelper
/**
* 组件的配置项抽象,可以控制部分功能的开关
*
* @see SwipeDragHelper
* @see me.yifeiyuan.flap.ext.ItemClicksHelper
*
* Created by 程序亦非猿 on 2022/8/31.
*
* @since 3.0.8
*/
interface ComponentConfig {

/**
* 支持滑动的方向
*/
fun getSwipeFlags(): Int = SwipeDragHelper.FLAG_UN_SET

/**
* 支持拖动的方向
*/
fun getDragFlags(): Int = SwipeDragHelper.FLAG_UN_SET

fun isSwipeEnable(): Boolean = true
/**
* 是否可以滑动删除
*/
fun isSwipeEnabled(): Boolean = true

fun isDragEnable(): Boolean = true
/**
* 是否可以拖动
*/
fun isDragEnabled(): Boolean = true

/**
* 是否可以点击
*/
fun isClickable(): Boolean = true

/**
* 是否可以长按点击
*/
fun isLongClickable(): Boolean = true
}
2 changes: 1 addition & 1 deletion flap/src/main/java/me/yifeiyuan/flap/FlapAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ open class FlapAdapter : RecyclerView.Adapter<Component<*>>(), IRegistry, IAdapt
override fun getItemId(position: Int): Long {
val itemData = getItemData(position)
val delegate = getDelegateByViewType(getItemViewType(position))
return delegate.getItemId(itemData)
return delegate.getItemId(itemData, position)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ interface AdapterDelegate<M, VH : Component<M>> {
/**
* @see RecyclerView.Adapter.getItemId
*/
fun getItemId(model: Any): Long = RecyclerView.NO_ID
fun getItemId(model: Any, position: Int): Long = RecyclerView.NO_ID

/**
* @see RecyclerView.Adapter.getItemViewType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,19 @@ internal class FallbackComponent(v: View) : Component<Any>(v) {
}
}

override fun isDragEnable(): Boolean {
override fun isClickable(): Boolean {
return false
}

override fun isSwipeEnable(): Boolean {
override fun isLongClickable(): Boolean {
return false
}

override fun isDragEnabled(): Boolean {
return false
}

override fun isSwipeEnabled(): Boolean {
return false
}
}
199 changes: 0 additions & 199 deletions flap/src/main/java/me/yifeiyuan/flap/delegate/LayoutAdapterDelegate.kt

This file was deleted.

Loading

0 comments on commit f40183c

Please sign in to comment.