Skip to content

Commit

Permalink
Merge pull request #113 from AlanCheen/feature/mid-autumn
Browse files Browse the repository at this point in the history
Feature/mid autumn
  • Loading branch information
AlanCheen authored Sep 19, 2022
2 parents f4e8e7f + 19a7ce5 commit aaa2fa0
Show file tree
Hide file tree
Showing 29 changed files with 483 additions and 103 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,8 @@ dependencies {
// kapt 'me.yifeiyuan.flap:flap-compiler:2.0.0'

implementation 'jp.wasabeef:recyclerview-animators:4.0.2'
// implementation 'com.google.code.gson:gson:2.9.1'

implementation 'com.github.bumptech.glide:glide:4.13.2'
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2'
}
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
xmlns:tools="http://schemas.android.com/tools"
package="me.yifeiyuan.flapdev">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-sdk tools:overrideLibrary="jp.wasabeef.recyclerview"/>

Expand Down
19 changes: 14 additions & 5 deletions app/src/main/java/me/yifeiyuan/flapdev/FlapApplication.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package me.yifeiyuan.flapdev

import android.app.Application
import androidx.multidex.MultiDexApplication
import me.yifeiyuan.flap.Flap
import me.yifeiyuan.flap.apt.delegates.*
import me.yifeiyuan.flap.hook.ApmHook
import me.yifeiyuan.flap.hook.LoggingHook
import me.yifeiyuan.flapdev.components.CustomViewTypeComponentDelegate
import me.yifeiyuan.flapdev.components.SimpleTextComponentDelegate
import me.yifeiyuan.flapdev.components.ZeroHeightComponent
import me.yifeiyuan.flapdev.components.*
import me.yifeiyuan.flapdev.components.generictest.GenericFlapComponentDelegate

/**
Expand All @@ -16,17 +14,26 @@ import me.yifeiyuan.flapdev.components.generictest.GenericFlapComponentDelegate
*/
class FlapApplication : MultiDexApplication() {

companion object{

var application :Application?=null
}

override fun onCreate() {
super.onCreate()
application = this
initFlap()
}

private fun initFlap() {

Flap.apply {

//Flap 这里注册的都是是全局的,只是为了测试方便
//实际开发使用的话 哪个 Adapter 需要才注册更加合适。
registerAdapterDelegates(
fullConfigAdapterDelegate(),
bannerAdapterDelegate(),
ZeroHeightComponentAdapterDelegate(),
SimpleTextComponentDelegate(),
SimpleImageComponentAdapterDelegate(),
Expand All @@ -47,8 +54,10 @@ class FlapApplication : MultiDexApplication() {
// ApmHook()
)

registerAdapterService(TestService::class.java)

//可选
init(this@FlapApplication)
withContext(this@FlapApplication)

//打开日志
setDebug(true)
Expand Down
59 changes: 59 additions & 0 deletions app/src/main/java/me/yifeiyuan/flapdev/Mocks.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.yifeiyuan.flapdev

import androidx.recyclerview.widget.ItemTouchHelper
import me.yifeiyuan.flap.ktmodule.KtComponentModel
import me.yifeiyuan.flapdev.components.*
import me.yifeiyuan.flapdev.components.SimpleDataBindingModel
Expand All @@ -17,6 +18,16 @@ import java.util.*
*/
fun mockMultiTypeModels(): MutableList<Any> {
val models: MutableList<Any> = ArrayList()

val bannerModel = BannerModel()

bannerModel.images = mutableListOf<BannerImageModel>().apply {
add(BannerImageModel().apply { resId = R.drawable.flap_ic_baicai })
add(BannerImageModel().apply { resId = R.drawable.flap_ic_baozi })
add(BannerImageModel().apply { resId = R.drawable.flap_ic_jd })
}

models.add(bannerModel)
models.add(SimpleTextModel("Flap(灵动)"))
models.add(SimpleTextModel("一个基于 RecyclerView 的页面组件化框架"))
models.add(SimpleTextModel("—— by 程序亦非猿"))
Expand All @@ -31,6 +42,54 @@ fun mockMultiTypeModels(): MutableList<Any> {
models.add(KtComponentModel())
models.add(TestBinderModel())
models.add(UnknownModel())
models.addAll(mockFullFeatureModels())
return models
}

fun mockFullFeatureModels(): MutableList<Any> {
val models: MutableList<Any> = ArrayList()

val clickModel = TestConfigModel().apply {
clickEnable = true
title = "测试点击"
content = "可单击"
}
val clickModel2 = TestConfigModel().apply {
clickEnable = false
title = "测试点击"
content = "不可点击"
}
models.add(clickModel)
models.add(clickModel2)

val longClickModel = TestConfigModel().apply {
longClickEnable = true
title = "测试长按"
content = "可长按"
}
val longClickModel2 = TestConfigModel().apply {
longClickEnable = false
title = "测试长按"
content = "不可长按"
}
models.add(longClickModel)
models.add(longClickModel2)

val swipeModel = TestConfigModel().apply {
swipeEnable = true
title = "测试滑动删除"
content = "可从右往左滑动删除"
swipeFlags = ItemTouchHelper.LEFT
}
val swipeModel2 = TestConfigModel().apply {
swipeEnable = true
title = "测试滑动删除"
content = "可从左往右滑动删除"
swipeFlags = ItemTouchHelper.RIGHT
}
models.add(swipeModel)
models.add(swipeModel2)

return models
}

Expand Down
53 changes: 53 additions & 0 deletions app/src/main/java/me/yifeiyuan/flapdev/components/Banner.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package me.yifeiyuan.flapdev.components

import android.widget.ImageView
import androidx.viewpager2.widget.ViewPager2
import com.bumptech.glide.Glide
import me.yifeiyuan.flap.FlapAdapter
import me.yifeiyuan.flap.dsl.adapterDelegate
import me.yifeiyuan.flapdev.R

/**
* Created by 程序亦非猿 on 2022/9/11.
*/

class BannerModel {
var images: MutableList<BannerImageModel>? = null
}

class BannerImageModel {
var url: String? = null
var resId: Int = 0
}

fun bannerAdapterDelegate() = adapterDelegate<BannerModel>(R.layout.component_banner) {

swipeEnable = false
dragEnable = false

val viewPager2 = findViewById<ViewPager2>(R.id.banner)
val bannerAdapter = FlapAdapter().apply {
registerAdapterDelegate(bannerImageDelegate())
}

viewPager2.adapter = bannerAdapter

onBind { model, position, payloads, adapter ->
model.images?.let {
bannerAdapter.setDataAndNotify(it)
}
}
}

fun bannerImageDelegate() = adapterDelegate<BannerImageModel>(R.layout.component_banner_image) {

val imageView = findViewById<ImageView>(R.id.logo)

onBind { model ->
if (model.url?.isNotEmpty() == true) {
Glide.with(context).load(model.url).into(imageView)
} else if (model.resId > 0) {
Glide.with(context).load(model.resId).into(imageView)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package me.yifeiyuan.flapdev.components

import android.view.View
import android.widget.ImageView
import com.bumptech.glide.Glide
import me.yifeiyuan.flap.Component
import me.yifeiyuan.flap.annotations.Delegate
import me.yifeiyuan.flapdev.R
Expand All @@ -10,11 +12,22 @@ import me.yifeiyuan.flapdev.R
* Created by 程序亦非猿 on 2018/12/4.
*/

class SimpleImageModel
class SimpleImageModel {
var url: String? = null
var resId: Int = 0
}

@Delegate(layoutId = R.layout.flap_item_simple_image)
@Delegate(layoutId = R.layout.component_simple_image)
//@Delegate(layoutName = "flap_item_simple_image")
class SimpleImageComponent(itemView: View) : Component<SimpleImageModel>(itemView) {

private val imageView = findViewById<ImageView>(R.id.logo)

override fun onBind(model: SimpleImageModel) {
if (model.url?.isNotEmpty() == true) {
Glide.with(context).load(model.url).into(imageView)
} else if (model.resId > 0) {
Glide.with(context).load(model.resId).into(imageView)
}
}
}
59 changes: 59 additions & 0 deletions app/src/main/java/me/yifeiyuan/flapdev/components/TestConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package me.yifeiyuan.flapdev.components

import me.yifeiyuan.flap.differ.IDiffer
import me.yifeiyuan.flap.dsl.adapterDelegate
import me.yifeiyuan.flap.ext.bindTextView
import me.yifeiyuan.flapdev.R

/**
* Created by 程序亦非猿 on 2022/9/13.
*/

class TestConfigModel : IDiffer {

var id: Int = -1
var title: String? = null
var content: String? = null

var dragEnable: Boolean = false
var swipeEnable: Boolean = false

var swipeFlags: Int = 0
var dragFlags: Int = 0

var clickEnable: Boolean = false
var longClickEnable: Boolean = false

override fun areItemsTheSame(newItem: Any): Boolean {
return false
}

override fun areContentsTheSame(newItem: Any): Boolean {
return false
}

override fun getChangePayload(newItem: Any): Any? {
return super.getChangePayload(newItem)
}
}

fun fullConfigAdapterDelegate() = adapterDelegate<TestConfigModel>(R.layout.component_full_feature) {

onBind { model, position, payloads, adapter ->

bindTextView(R.id.title) {
text = model.title
}

bindTextView(R.id.content) {
text = model.content
}

swipeEnable = model.swipeEnable
dragEnable = model.dragEnable
swipeFlags = model.swipeFlags
dragFlags = model.dragFlags
clickable = model.clickEnable
longClickable = model.longClickEnable
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@ package me.yifeiyuan.flapdev.testcases
import android.util.Log
import android.view.View
import android.widget.ImageView
import me.yifeiyuan.flap.Component
import me.yifeiyuan.flap.FlapAdapter
import me.yifeiyuan.flap.delegate.AdapterDelegate
import me.yifeiyuan.flap.delegate.LayoutAdapterDelegate
import me.yifeiyuan.flap.dsl.adapterDelegate
import me.yifeiyuan.flap.dsl.adapterHook
import me.yifeiyuan.flap.ext.*
import me.yifeiyuan.flap.hook.AdapterHook
import me.yifeiyuan.flapdev.R
import me.yifeiyuan.flapdev.components.SimpleImageModel
import me.yifeiyuan.flapdev.components.SimpleTextModel
import me.yifeiyuan.flapdev.components.TestAllModel
import me.yifeiyuan.flapdev.components.TestBinderModel
import me.yifeiyuan.flapdev.mockMultiTypeModels

private const val TAG = "DSLTestcase"
Expand Down Expand Up @@ -132,7 +127,7 @@ class DSLTestcase : BaseTestcaseFragment() {
}
}

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

onBind { model, position, payloads, adapter ->
bindView<ImageView>(R.id.logo) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package me.yifeiyuan.flapdev.testcases

import android.animation.ObjectAnimator
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.util.Log
import android.view.View
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.vectordrawable.graphics.drawable.ArgbEvaluator
import me.yifeiyuan.flap.FlapAdapter
import me.yifeiyuan.flap.ext.SwipeDragHelper

Expand Down Expand Up @@ -39,10 +41,18 @@ class SwipeAndDragTestcase : BaseTestcaseFragment() {
.onDragStarted { viewHolder, adapterPosition ->
Log.d(TAG, "开始拖动 position=$adapterPosition")
toast("开始拖动 position=$adapterPosition")

//做个放大动画
val scaleY = ObjectAnimator.ofFloat(viewHolder.itemView, "scaleY", 1f, 1.5f)
scaleY.start()
}
.onDragReleased { viewHolder, adapterPosition ->
Log.d(TAG, "拖动结束 position=$adapterPosition")
toast("拖动结束 position=$adapterPosition")

//恢复原状
val scaleY = ObjectAnimator.ofFloat(viewHolder.itemView, "scaleY", 1f)
scaleY.start()
}
.onSwipeStarted { viewHolder, adapterPosition ->
Log.d(TAG, "滑动开始 position=$adapterPosition")
Expand All @@ -52,6 +62,9 @@ class SwipeAndDragTestcase : BaseTestcaseFragment() {
Log.d(TAG, "滑动结束 position=$adapterPosition")
toast("滑动结束 position=$adapterPosition")
}
.onClearView { viewHolder, adapterPosition ->
Log.d(TAG, "onClearView called position=$adapterPosition")
}
.attachToRecyclerView(recyclerView)

recyclerView.addItemDecoration(spaceItemDecoration)
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/layout/component_banner.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="wrap_content">

<androidx.viewpager2.widget.ViewPager2
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="120dp"
/>

</FrameLayout>
Loading

0 comments on commit aaa2fa0

Please sign in to comment.