Skip to content

Commit

Permalink
Merge pull request #117 from AlanCheen/feature/delegation
Browse files Browse the repository at this point in the history
Feature/delegation
  • Loading branch information
AlanCheen authored Oct 8, 2022
2 parents f4cd37b + 726c7a6 commit f4c7603
Show file tree
Hide file tree
Showing 26 changed files with 436 additions and 475 deletions.
14 changes: 0 additions & 14 deletions app/src/main/java/me/yifeiyuan/flapdev/ASMKotlinTest.kt

This file was deleted.

14 changes: 0 additions & 14 deletions app/src/main/java/me/yifeiyuan/flapdev/AsmTest.java

This file was deleted.

8 changes: 4 additions & 4 deletions app/src/main/java/me/yifeiyuan/flapdev/FlapApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import me.yifeiyuan.flapdev.components.generictest.GenericFlapComponentDelegate
*/
class FlapApplication : MultiDexApplication() {

companion object{

var application :Application?=null
companion object {
var application: Application? = null
}

override fun onCreate() {
Expand Down Expand Up @@ -50,7 +49,8 @@ class FlapApplication : MultiDexApplication() {
)

//也是全局
registerAdapterHooks(LoggingHook(),
registerAdapterHooks(
LoggingHook(),
// ApmHook()
)

Expand Down
135 changes: 0 additions & 135 deletions app/src/main/java/me/yifeiyuan/flapdev/SpaceItemDecorationT.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ import me.yifeiyuan.flap.FlapAdapter
import me.yifeiyuan.flap.decoration.LinearItemDecoration
import me.yifeiyuan.flap.decoration.LinearSpaceItemDecoration
import me.yifeiyuan.flap.decoration.SpaceItemDecoration
import me.yifeiyuan.flap.widget.FlapGridLayoutManager
import me.yifeiyuan.flap.widget.FlapIndexedStaggeredGridLayoutManager
import me.yifeiyuan.flap.widget.FlapLinearLayoutManager
import me.yifeiyuan.flap.widget.FlapRecyclerView
import me.yifeiyuan.flap.widget.*
import me.yifeiyuan.flapdev.*
import me.yifeiyuan.flapdev.components.SimpleTextModel
import java.util.*
Expand Down Expand Up @@ -52,7 +49,8 @@ open class BaseTestcaseFragment : Fragment(), Scrollable {

lateinit var linearLayoutManager: FlapLinearLayoutManager
lateinit var gridLayoutManager: FlapGridLayoutManager
lateinit var staggeredGridLayoutManager: FlapIndexedStaggeredGridLayoutManager
lateinit var staggeredGridLayoutManager: FlapStaggeredGridLayoutManager
lateinit var indexedStaggeredGridLayoutManager: FlapIndexedStaggeredGridLayoutManager
lateinit var currentLayoutManager: RecyclerView.LayoutManager

override fun onAttach(context: Context) {
Expand Down Expand Up @@ -82,30 +80,26 @@ open class BaseTestcaseFragment : Fragment(), Scrollable {
emptyView = view.findViewById(R.id.emptyView)
recyclerView = view.findViewById(R.id.recyclerView)
adapter = createAdapter()
adapter.setLifecycleOwner(viewLifecycleOwner)

adapter.setEmptyView(emptyView)

adapter.observeEvent<String>("showToast") {
toast(it.arg ?: "Default Message")
Log.d("observeEvent", "showToast event ")
}

adapter.observeEvent<Int>("intEvent") {
Log.d("observeEvent", "intEvent called")
}

adapter.observerEvents {
when (it.eventName) {
"showToast" -> {
Log.d("observerEvents", "showToast ~~ ${it.arg}")
it.setEventResult(isSuccess = true)
.withLifecycleOwner(viewLifecycleOwner)
.withEmptyView(emptyView)
.observeEvent<String>("showToast") {
toast(it.arg ?: "Default Message")
Log.d("observeEvent", "showToast event ")
}
"intEvent" -> {
Log.d("observerEvents", "intEvent ~~ ${it.arg}")
.observeEvent<Int>("intEvent") {
Log.d("observeEvent", "intEvent called")
}
.observerEvents {
when (it.eventName) {
"showToast" -> {
Log.d("observerEvents", "showToast ~~ ${it.arg}")
it.setEventResult(isSuccess = true)
}
"intEvent" -> {
Log.d("observerEvents", "intEvent ~~ ${it.arg}")
}
}
}
}
}

adapter.setParamProvider {
when (it) {
Expand Down Expand Up @@ -148,8 +142,6 @@ open class BaseTestcaseFragment : Fragment(), Scrollable {

swipeRefreshLayout.isRefreshing = true

// FlapItemTouchHelper(adapter).attachToRecyclerView(recyclerView)

Handler().postDelayed({
adapter.setDataAndNotify(createRefreshData())
swipeRefreshLayout.isRefreshing = false
Expand All @@ -164,15 +156,17 @@ open class BaseTestcaseFragment : Fragment(), Scrollable {
spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
var spanSize = 1
// spanSize = if (position % 2 == 0) 2 else 1
//spanSize = if (position % 2 == 0) 2 else 1
return spanSize
}
}
}

staggeredGridLayoutManager = FlapIndexedStaggeredGridLayoutManager(2, RecyclerView.VERTICAL).apply {
indexedStaggeredGridLayoutManager = FlapIndexedStaggeredGridLayoutManager(2, RecyclerView.VERTICAL).apply {
gapStrategy = StaggeredGridLayoutManager.GAP_HANDLING_NONE
}

staggeredGridLayoutManager = FlapStaggeredGridLayoutManager(2)
}

open fun initItemDecorations() {
Expand Down Expand Up @@ -248,6 +242,9 @@ open class BaseTestcaseFragment : Fragment(), Scrollable {
is StaggeredGridLayoutManager -> {
layoutManager.scrollToPositionWithOffset(0, 0)
}
is FlapIndexedStaggeredGridLayoutManager->{
layoutManager.scrollToPositionWithOffset(0, 0)
}
else -> {
layoutManager?.scrollToPosition(0)
}
Expand All @@ -259,6 +256,7 @@ open class BaseTestcaseFragment : Fragment(), Scrollable {
* 0 Linear
* 1 Grid
* 2 Staggered
* 3 IndexedStaggered
*/
fun switchLayoutManager(type: Int) {
when (type) {
Expand Down Expand Up @@ -290,6 +288,15 @@ open class BaseTestcaseFragment : Fragment(), Scrollable {
currentLayoutManager = staggeredGridLayoutManager
recyclerView.layoutManager = currentLayoutManager
}
3 -> {
recyclerView.removeItemDecoration(currentItemDecoration)
currentItemDecoration = gridItemDecoration
recyclerView.addItemDecoration(currentItemDecoration)
recyclerView.invalidateItemDecorations()

currentLayoutManager = indexedStaggeredGridLayoutManager
recyclerView.layoutManager = currentLayoutManager
}
}
}

Expand Down Expand Up @@ -317,6 +324,9 @@ open class BaseTestcaseFragment : Fragment(), Scrollable {
is StaggeredGridLayoutManager -> {
(currentLayoutManager as StaggeredGridLayoutManager).orientation = orientation
}
is FlapIndexedStaggeredGridLayoutManager -> {
(currentLayoutManager as FlapIndexedStaggeredGridLayoutManager).orientation = orientation
}
}

recyclerView.invalidateItemDecorations()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class FlapRecyclerViewTestcase : BaseTestcaseFragment() {

with(flapRecyclerView.flapAdapter) {

this.setEmptyView(emptyView)
this.withEmptyView(emptyView)

doOnPreload {
toast("onPreload 预加载")
Expand All @@ -69,6 +69,8 @@ class FlapRecyclerViewTestcase : BaseTestcaseFragment() {

linearSpaceItemDecoration = LinearSpaceItemDecoration(requireActivity().toPixel(6))
recyclerView.addItemDecoration(linearSpaceItemDecoration)

flapRecyclerView.disableAnimation()
}

override fun createRefreshData(size: Int): MutableList<Any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import android.view.MenuItem
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import me.yifeiyuan.flap.decoration.SpaceItemDecoration
import me.yifeiyuan.flap.ext.doOnBindViewHolderEnd
import me.yifeiyuan.flap.ext.doOnCreateViewHolderEnd
import me.yifeiyuan.flapdev.R
import me.yifeiyuan.flapdev.SpaceItemDecorationT
import me.yifeiyuan.flapdev.toPixel
import kotlin.random.Random

Expand All @@ -26,8 +26,7 @@ class ItemDecorationTestcase : BaseTestcaseFragment() {
setHasOptionsMenu(true)

currentItemDecoration = gridItemDecoration
// recyclerView.addItemDecoration(currentItemDecoration)
recyclerView.addItemDecoration(SpaceItemDecorationT(requireActivity().toPixel(6)))
recyclerView.addItemDecoration(currentItemDecoration)

currentLayoutManager = staggeredGridLayoutManager
recyclerView.layoutManager = staggeredGridLayoutManager
Expand Down Expand Up @@ -88,6 +87,9 @@ class ItemDecorationTestcase : BaseTestcaseFragment() {
R.id.staggered -> {
switchLayoutManager(2)
}
R.id.indexed_staggered->{
switchLayoutManager(3)
}

R.id.horizontal -> {
updateOrientation(RecyclerView.HORIZONTAL)
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/menu/item_decorations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<item
android:id="@+id/staggered"
android:title="StaggeredGridLayoutManager" />
<item
android:id="@+id/indexed_staggered"
android:title="IndexedStaggeredGridLayoutManager" />
<item
android:id="@+id/horizontal"
android:title="Horizontal" />
Expand Down
Loading

0 comments on commit f4c7603

Please sign in to comment.