Skip to content

Commit

Permalink
Merge pull request #98 from AlanCheen/feature/kt-v3
Browse files Browse the repository at this point in the history
Feature/kt v3
  • Loading branch information
AlanCheen authored Aug 10, 2022
2 parents f65809f + 5998c8f commit 9c23878
Show file tree
Hide file tree
Showing 44 changed files with 170 additions and 421 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

> - [Flap 接入文档](https://www.yuque.com/cxyfy/blog/ghsc4b)
> - [Flap 更新日志](https://www.yuque.com/cxyfy/blog/ehnxdy)
> - [Flap 设计理念](https://www.yuque.com/cxyfy/blog/ehnxdy)
> - [Flap 设计理念](https://www.yuque.com/cxyfy/blog/gsi2b8)

<a name="E94H7"></a>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
</intent-filter>

</activity>
<activity android:name=".DifferActivity" />
<activity android:name=".KotlinTestActivity" />
</application>

Expand Down
116 changes: 0 additions & 116 deletions app/src/main/java/me/yifeiyuan/flapdev/DifferActivity.java

This file was deleted.

2 changes: 1 addition & 1 deletion app/src/main/java/me/yifeiyuan/flapdev/FlapApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FlapApplication : MultiDexApplication() {
TestClickComponentAdapterDelegate(),
TestBinderComponentAdapterDelegate(),
TestAllComponentAdapterDelegate(),
SimpleDataBindingComponentAdapterDelegate(),
DataBindingComponentAdapterDelegate(),
DiffComponentAdapterDelegate(),
)

Expand Down
17 changes: 4 additions & 13 deletions app/src/main/java/me/yifeiyuan/flapdev/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MainActivity : AppCompatActivity() {
subtitle = "多 itemViewType"
replace(MultiTypeTestcase::class.java)
}
R.id.nav_prefetch -> {
R.id.nav_preload -> {
title = "预加载"
subtitle = "在滑动到底部之前预先加载"
replace(PreloadTestcase::class.java)
Expand All @@ -65,7 +65,9 @@ class MainActivity : AppCompatActivity() {
replace(ViewPager2Testcase::class.java)
}
R.id.nav_diff -> {
replace(DiffAdapterTestcase::class.java)
title = "FlapDifferAdapter"
subtitle = "修改数据后,下拉刷新观察"
replace(FlapDifferAdapterTestcase::class.java)
}
R.id.nav_clicks -> {
subtitle = "点击、长按事件功能测试"
Expand Down Expand Up @@ -113,15 +115,4 @@ class MainActivity : AppCompatActivity() {
private fun <T : Fragment> replace(fragmentClass: Class<T>, args: Bundle? = null) {
supportFragmentManager.beginTransaction().replace(R.id.container, fragmentClass, args).commitAllowingStateLoss()
}

// private fun createAdvanceTestCase(recyclerView: RecyclerView) {
// val models = mockModels()
// val adapter: FlapAdapter = ShowcaseAdapter()
// adapter.setUseComponentPool(true)
// .setLifecycleEnable(true)
// .setLifecycleOwner(this)
// .data = models
// recyclerView.adapter = adapter
// }

}
11 changes: 1 addition & 10 deletions app/src/main/java/me/yifeiyuan/flapdev/Mocks.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package me.yifeiyuan.flapdev

import me.yifeiyuan.flap.FlapAdapter
import me.yifeiyuan.flap.ktmodule.KtComponentModel
import me.yifeiyuan.flapdev.components.*
import me.yifeiyuan.flapdev.components.databindingsample.SimpleDataBindingModel
import me.yifeiyuan.flapdev.components.SimpleDataBindingModel
import me.yifeiyuan.flapdev.components.generictest.GenericModel
import me.yifeiyuan.ktx.foundation.othermodule.JavaModuleModel
import me.yifeiyuan.ktx.foundation.othermodule.vb.ViewBindingModel
Expand All @@ -13,14 +12,6 @@ import java.util.*
* Created by 程序亦非猿 on 2021/9/28.
*/

fun FlapAdapter.mockData() {
setData(mockMultiTypeModels())
}

fun FlapAdapter.appendMockData() {
appendData(mockMultiTypeModels())
}

/**
* 测试多类型数据
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,4 @@ class CustomViewTypeComponentDelegate : AdapterDelegate<CustomViewTypeModel, Cus
override fun getItemViewType(model: Any): Int {
return CustomViewTypeComponent.CUSTOM_ITEM_VIEW_TYPE
}

override fun getItemId(model: Any): Long {
return super.getItemId(model)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package me.yifeiyuan.flapdev.components

import me.yifeiyuan.flap.Component
import me.yifeiyuan.flap.annotations.Delegate
import me.yifeiyuan.flapdev.databinding.FlapItemSimpleDatabindingBinding

/**
* 测试 DataBinding 功能
*
*
* Created by 程序亦非猿 on 2022/8/9.
*/

class SimpleDataBindingModel {
var text = "该 Component 使用了 DataBinding"
}

@Delegate(layoutName = "flap_item_simple_databinding", useDataBinding = true)
class DataBindingComponent(private var binding: FlapItemSimpleDatabindingBinding) : Component<SimpleDataBindingModel?>(binding.getRoot()) {

override fun onBind(model: SimpleDataBindingModel?) {
binding.model = model
binding.executePendingBindings()
}

}
56 changes: 21 additions & 35 deletions app/src/main/java/me/yifeiyuan/flapdev/components/DiffComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,38 +51,13 @@ class DiffComponent(view: View) : Component<TestDiffModel>(view) {

override fun onBind(model: TestDiffModel, position: Int, payloads: List<Any>, adapter: FlapAdapter, delegate: AdapterDelegate<*, *>) {

if (payloads.isNotEmpty()) {
bindTextView(R.id.content) {
text = "展示 content :${payloads.get(0)}"
}

//当 payloads 更新时,事件点击需要重新设置
bindButton(R.id.modifyContent) {
setOnClickListener {
model.content = "修改后 Content:" + (SystemClock.uptimeMillis() % 10000).toInt().toString()
adapter.notifyItemChanged(position)
}
}

bindButton(R.id.modifyId) {
setOnClickListener {
model.id = (SystemClock.uptimeMillis() % 10000).toInt()
adapter.notifyItemChanged(position)
}
//当 payloads 更新时,事件点击需要重新设置
bindButton(R.id.modifyContent) {
setOnClickListener {
model.content = "修改后 Content:" + (SystemClock.uptimeMillis() % 10000).toInt().toString()
adapter.notifyItemChanged(position, model.content)//不会闪
// adapter.notifyItemChanged(position)//会闪
}
return
}

bindTextView(R.id.content) {
text = "展示 content :${model.content}"
}

bindTextView(R.id.id) {
text = "展示 ID :${model.id}"
}

bindTextView(R.id.desc) {
text = "展示 desc :${model.desc}"
}

bindButton(R.id.modifyId) {
Expand All @@ -92,10 +67,21 @@ class DiffComponent(view: View) : Component<TestDiffModel>(view) {
}
}

bindButton(R.id.modifyContent) {
setOnClickListener {
model.content = "修改后 Content:" + (SystemClock.uptimeMillis() % 10000).toInt().toString()
adapter.notifyItemChanged(position)
if (payloads.isNotEmpty()) {
bindTextView(R.id.content) {
text = "展示 content :${payloads.get(0)}"
}
} else {
bindTextView(R.id.content) {
text = "展示 content :${model.content}"
}

bindTextView(R.id.id) {
text = "展示 ID :${model.id}"
}

bindTextView(R.id.desc) {
text = "展示 desc :${model.desc}"
}
}
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ import java.util.ArrayList


/**
* 测试 FlapDifferAdapter 功能
*
* 测试说明,点击按钮后,再下拉刷新,只有被修改了的数据才会有刷新动画
*
* @see FlapDifferAdapter
*
* Created by 程序亦非猿 on 2022/8/1.
*/
class DiffAdapterTestcase : BaseTestcaseFragment() {
class FlapDifferAdapterTestcase : BaseTestcaseFragment() {

//如果不测试 header footer,就注释掉 onViewCreated
// override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -58,10 +61,6 @@ class DiffAdapterTestcase : BaseTestcaseFragment() {
}
}

override fun onInit(view: View) {
super.onInit(view)
}

override fun createRefreshData(size: Int): MutableList<Any> {
val list = mutableListOf<Any>()
repeat(20) {
Expand Down
Loading

0 comments on commit 9c23878

Please sign in to comment.