Skip to content

Commit

Permalink
Merge pull request #120 from AlanCheen/demo
Browse files Browse the repository at this point in the history
Demo
  • Loading branch information
AlanCheen authored Oct 12, 2022
2 parents a630475 + 4459066 commit 34cc147
Show file tree
Hide file tree
Showing 67 changed files with 959 additions and 1,108 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ dependencies {

implementation 'androidx.recyclerview:recyclerview:1.2.1'

implementation project(':othermodule')
implementation project(':ktmodule')

implementation project(':flap')
Expand Down
100 changes: 100 additions & 0 deletions app/src/main/java/me/yifeiyuan/flapdev/ConfigMenuView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package me.yifeiyuan.flapdev

import android.content.Context
import android.view.LayoutInflater
import android.widget.FrameLayout
import android.widget.SeekBar
import androidx.recyclerview.widget.RecyclerView
import me.yifeiyuan.flapdev.databinding.DebugMenuBinding

/**
* Created by 程序亦非猿 on 2022/10/11.
*/
class ConfigMenuView : FrameLayout {

constructor(context: Context) : super(context)

private val binding: DebugMenuBinding = DebugMenuBinding.inflate(LayoutInflater.from(context), this, true)

init {

binding.orientationGroup.setOnCheckedChangeListener { group, checkedId ->
when (checkedId) {
R.id.horizontal -> {
callback?.onOrientationChanged(RecyclerView.HORIZONTAL)
}
R.id.vertical -> {
callback?.onOrientationChanged(RecyclerView.VERTICAL)
}
}
}

//0 Linear
//1 Grid
//2 Staggered
//3 IndexedStaggered
binding.layoutManagerGroup.setOnCheckedChangeListener { group, checkedId ->
when (checkedId) {
R.id.linear -> {
callback?.onLayoutManagerChanged(0)
}
R.id.grid -> {
callback?.onLayoutManagerChanged(1)
}
R.id.staggered -> {
callback?.onLayoutManagerChanged(2)
}
R.id.indexedStaggered -> {
callback?.onLayoutManagerChanged(3)
}
}
}

binding.clearAll.setOnClickListener {
callback?.onClearAllData()
}
binding.addTopData.setOnClickListener {
callback?.onAddDataToTop()
}
binding.resetData.setOnClickListener {
callback?.onResetData()
}
binding.appendData.setOnClickListener {
callback?.onAppendData()
}
binding.addZeroHeightData.setOnClickListener {
callback?.onAddZeroHeightData()
}

binding.spanCount.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
}

override fun onStartTrackingTouch(seekBar: SeekBar) {
}

override fun onStopTrackingTouch(seekBar: SeekBar) {
callback?.onSpanCountChanged(seekBar.progress)
}
})

binding.toggleSkeleton.setOnCheckedChangeListener { buttonView, isChecked ->
callback?.onSkeletonVisibilityChanged(isChecked)
}
}

var callback: Callback? = null

interface Callback {
fun onOrientationChanged(orientation: Int)
fun onLayoutManagerChanged(type: Int)
fun onPreloadChanged(direction: Int, enable: Boolean)
fun onClearAllData()
fun onAddDataToTop()
fun onResetData()
fun onAppendData()
fun onSpanCountChanged(spanCount: Int)
fun onSkeletonVisibilityChanged(show: Boolean)
fun onAddZeroHeightData()
}
}
58 changes: 45 additions & 13 deletions app/src/main/java/me/yifeiyuan/flapdev/FlapApplication.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package me.yifeiyuan.flapdev

import android.app.Application
import android.util.Log
import android.widget.Toast
import androidx.multidex.MultiDexApplication
import me.yifeiyuan.flap.Flap
import me.yifeiyuan.flap.apt.delegates.*
import me.yifeiyuan.flap.dsl.adapterHook
import me.yifeiyuan.flap.hook.LoggingHook
import me.yifeiyuan.flapdev.components.*
import me.yifeiyuan.flapdev.components.generictest.GenericFlapComponentDelegate

/**
* Flap
Expand All @@ -16,6 +18,16 @@ class FlapApplication : MultiDexApplication() {

companion object {
var application: Application? = null
set(value) {
field = value
toast = Toast.makeText(value, "", Toast.LENGTH_SHORT)
}
lateinit var toast: Toast
fun toast(title: String) {
toast.setText(title)
toast.duration = Toast.LENGTH_SHORT
toast.show()
}
}

override fun onCreate() {
Expand All @@ -26,24 +38,43 @@ class FlapApplication : MultiDexApplication() {

private fun initFlap() {

val dslAdapterHook = adapterHook {
onCreateViewHolderStart { adapter, delegate, viewType ->

}
onCreateViewHolderEnd { adapter, delegate, viewType, component ->

}
onBindViewHolderStart { adapter, delegate, component, data, position, payloads ->

}
onBindViewHolderEnd { adapter, delegate, component, data, position, payloads ->
Log.d("dslAdapterHook", "onBindViewHolderEnd() called with: adapter = $adapter, delegate = $delegate, component = $component, data = $data, position = $position, payloads = $payloads")
}
onViewAttachedToWindow { adapter, delegate, component ->

}

onViewDetachedFromWindow { adapter, delegate, component ->

}
}

Flap.apply {

//Flap 这里注册的都是是全局的,只是为了测试方便
//实际开发使用的话 哪个 Adapter 需要才注册更加合适。
registerAdapterDelegates(
fullConfigAdapterDelegate(),
bannerAdapterDelegate(),
ZeroHeightComponentAdapterDelegate(),
createFullConfigAdapterDelegate(),
createBannerAdapterDelegate(),
createSimpleImageDelegate(),
SimpleTextComponentDelegate(),
SimpleImageComponentAdapterDelegate(),
CustomViewTypeComponentDelegate(),
GenericFlapComponentDelegate(),
ViewBindingComponentAdapterDelegate(),
JavaModuleComponentAdapterDelegate(),
createCustomViewTypeComponentDelegate(),
createViewBindingDelegate(),
KtModuleComponentAdapterDelegate(),
TestClickComponentAdapterDelegate(),
TestBinderComponentAdapterDelegate(),
TestAllComponentAdapterDelegate(),
createZeroHeightComponentDelegate(),
createTestAdapterApiComponentDelegate(),
DataBindingComponentAdapterDelegate(),
DiffComponentAdapterDelegate(),
)
Expand All @@ -52,9 +83,10 @@ class FlapApplication : MultiDexApplication() {
registerAdapterHooks(
LoggingHook(
enableLog = true,
printTrace = true
// printTrace = true
),
// ApmHook()
// ApmHook(),
dslAdapterHook,
)

registerAdapterService(TestService::class.java)
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/me/yifeiyuan/flapdev/IMenuView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package me.yifeiyuan.flapdev

/**
* Created by 程序亦非猿 on 2022/10/11.
*/
interface IMenuView {
fun showMenu()
}
64 changes: 48 additions & 16 deletions app/src/main/java/me/yifeiyuan/flapdev/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package me.yifeiyuan.flapdev

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.drawerlayout.widget.DrawerLayout
import androidx.fragment.app.Fragment
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.android.material.navigation.NavigationView
import me.yifeiyuan.flap.ext.ifIs
import me.yifeiyuan.flapdev.testcases.*
import me.yifeiyuan.flapdev.testcases.ViewPager2Testcase
import java.lang.Exception

class MainActivity : AppCompatActivity() {

Expand Down Expand Up @@ -70,22 +75,10 @@ class MainActivity : AppCompatActivity() {
subtitle = "修改数据后,下拉刷新观察"
replace(FlapDifferAdapterTestcase::class.java)
}
R.id.nav_clicks -> {
subtitle = "点击、长按事件功能测试"
replace(ItemClicksTestcase::class.java)
}
R.id.nav_header_footer -> {
subtitle = "Header、Footer"
replace(HeaderFooterTestcase::class.java)
}
R.id.nav_flap_dsl -> {
subtitle = "DSL"
replace(DSLTestcase::class.java)
}
R.id.nav_dismiss -> {
subtitle = "滑动删除&拖放"
replace(SwipeAndDragTestcase::class.java)
}
R.id.nav_animation -> {
subtitle = "动画"
replace(AnimationTestcase::class.java)
Expand Down Expand Up @@ -113,15 +106,54 @@ class MainActivity : AppCompatActivity() {

val fab = findViewById<FloatingActionButton>(R.id.fab)
fab.setOnClickListener {
val fragment = supportFragmentManager.fragments.get(0)
val fragment = supportFragmentManager.findFragmentByTag("testcase")
fragment.ifIs<IMenuView> {
showMenu()
}
}

fab.setOnLongClickListener {
val fragment = supportFragmentManager.findFragmentByTag("testcase")
if (fragment is Scrollable) {
fragment.scrollToTop()
}
true
}

}

private fun <T : Fragment> replace(fragmentClass: Class<T>, args: Bundle? = null) {
supportFragmentManager.beginTransaction().replace(R.id.container, fragmentClass, args).commitAllowingStateLoss()
supportFragmentManager.beginTransaction().replace(R.id.container, fragmentClass, args, "testcase").commitAllowingStateLoss()
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.author -> {
val url = "https://www.yuque.com/cxyfy/blog/axzri0"
val uri: Uri = Uri.parse(url)
val intent = Intent(Intent.ACTION_VIEW, uri)
try {
startActivity(intent)
} catch (e: Exception) {
e.printStackTrace()
}
}

R.id.github -> {
val url = "https://github.com/AlanCheen/Flap"
val uri: Uri = Uri.parse(url)
val intent = Intent(Intent.ACTION_VIEW, uri)
try {
startActivity(intent)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
return super.onOptionsItemSelected(item)
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.home, menu)
return true
}
}
Loading

0 comments on commit 34cc147

Please sign in to comment.