Skip to content

Commit

Permalink
Merge pull request #99 from AlanCheen/feature/skeleton
Browse files Browse the repository at this point in the history
Feature/skeleton
  • Loading branch information
AlanCheen authored Aug 14, 2022
2 parents 9c23878 + b2b794d commit 0c63166
Show file tree
Hide file tree
Showing 20 changed files with 1,512 additions and 73 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,6 @@ dependencies {
// implementation 'me.yifeiyuan.flap:flap-annotations:2.0.0'
// implementation 'me.yifeiyuan.flap:flap:2.0.0'
// kapt 'me.yifeiyuan.flap:flap-compiler:2.0.0'

//http://facebook.github.io/shimmer-android/
// implementation 'com.facebook.shimmer:shimmer:0.5.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.recyclerview.widget.StaggeredGridLayoutManager
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import me.yifeiyuan.flap.FlapAdapter
import me.yifeiyuan.flap.ext.ExtraParamsProvider
import me.yifeiyuan.flap.skeleton.Skeleton
import me.yifeiyuan.flap.widget.FlapRecyclerView
import me.yifeiyuan.flapdev.R
import me.yifeiyuan.flapdev.Scrollable
Expand All @@ -29,6 +30,7 @@ private const val TAG = "BaseCaseFragment"
open class BaseTestcaseFragment : Fragment(), Scrollable {

lateinit var recyclerView: RecyclerView

lateinit var swipeRefreshLayout: SwipeRefreshLayout

lateinit var adapter: FlapAdapter
Expand Down Expand Up @@ -120,15 +122,22 @@ open class BaseTestcaseFragment : Fragment(), Scrollable {
}
}

//配置完结束最后在赋值
//配置完结束最后再赋值
recyclerView.adapter = adapter

swipeRefreshLayout.isRefreshing = true

Handler().postDelayed({
adapter.setData(createRefreshData())
swipeRefreshLayout.isRefreshing = false
}, getRefreshDelayedTime())
}

open fun isClickEnable() = true
open fun isLongClickEnable() = true

open fun createAdapter() = FlapAdapter().apply {
setData(createRefreshData())
// setData(createRefreshData())
}

open fun getLayoutId(): Int = R.layout.fragment_base_case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ private const val TAG = "HeaderFooterTestcase"
*/
class HeaderFooterTestcase : BaseTestcaseFragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
override fun onInit(view: View) {
super.onInit(view)

val headerFooterAdapter = HeaderFooterAdapter(adapter)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package me.yifeiyuan.flapdev.showcase

import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import me.yifeiyuan.flap.skeleton.Skeleton
import me.yifeiyuan.flap.widget.FlapGridLayoutManager
import me.yifeiyuan.flap.widget.FlapLinearLayoutManager
import me.yifeiyuan.flap.widget.FlapStaggeredGridLayoutManager
Expand All @@ -21,10 +21,38 @@ class MultiTypeTestcase : BaseTestcaseFragment() {

//测试第一个组件高度为 0 的 case,会导致不能下拉刷新
var testZeroHeight = false
lateinit var skeletonHelper: Skeleton

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
override fun onInit(view: View) {
super.onInit(view)
setHasOptionsMenu(true)

skeletonHelper = Skeleton()
.bind(recyclerView)
.adapter(adapter)
.autoHide(true)
.count(10)
.shimmer(true)
// .layout(R.layout.skeleton_layout) // 单个资源
.layouts { //多资源
when (it % 3) {
0 -> {
R.layout.skeleton_layout
}
1 -> {
R.layout.skeleton_layout2
}
2 -> {
R.layout.skeleton_layout3
}
else -> {
R.layout.skeleton_layout
}
}
}
.onlyOnce(false)
.withEmptyViewHelper(adapter.emptyViewHelper)
.show()
}

override fun createRefreshData(size: Int): MutableList<Any> {
Expand All @@ -42,6 +70,7 @@ class MultiTypeTestcase : BaseTestcaseFragment() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.emptyData -> {
skeletonHelper.hide()
adapter.setData(mutableListOf())
}
R.id.resetData -> {
Expand Down Expand Up @@ -72,6 +101,13 @@ class MultiTypeTestcase : BaseTestcaseFragment() {
testZeroHeight = !testZeroHeight
onRefresh()
}
R.id.toggleSkeleton -> {
if (skeletonHelper.isShowing) {
skeletonHelper.hide()
} else {
skeletonHelper.show()
}
}
}
return super.onOptionsItemSelected(item)
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_base_case.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
android:gravity="center"
android:text="无数据时展示"
android:textSize="40dp"
android:visibility="gone"
/>

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
Expand Down
54 changes: 54 additions & 0 deletions app/src/main/res/layout/skeleton_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_marginHorizontal="12dp"
android:layout_marginVertical="6dp"
android:background="#FFFFFF">

<View
android:id="@+id/sk1"
android:layout_width="84dp"
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="16dp"
android:background="#16000000"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
android:layout_marginTop="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintLeft_toRightOf="@id/sk1"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">

<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="#16000000" />

<View
android:layout_width="120dp"
android:layout_height="10dp"
android:layout_centerVertical="true"
android:background="#16000000" />

<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_alignParentBottom="true"
android:background="#16000000" />
</RelativeLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
23 changes: 23 additions & 0 deletions app/src/main/res/layout/skeleton_layout2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginHorizontal="12dp"
android:layout_marginVertical="6dp"
android:background="#FFFFFF">

<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="16dp"
android:background="#16000000"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
54 changes: 54 additions & 0 deletions app/src/main/res/layout/skeleton_layout3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_marginHorizontal="12dp"
android:layout_marginVertical="6dp"
android:background="#FFFFFF">

<View
android:id="@+id/sk1"
android:layout_width="84dp"
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="16dp"
android:background="#16000000"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
android:layout_marginTop="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="@id/sk1"
app:layout_constraintRight_toRightOf="parent"
>

<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="#16000000" />

<View
android:layout_width="180dp"
android:layout_height="10dp"
android:layout_centerVertical="true"
android:background="#16000000" />

<View
android:layout_width="120dp"
android:layout_height="10dp"
android:layout_alignParentBottom="true"
android:background="#16000000" />
</RelativeLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 4 additions & 0 deletions app/src/main/res/menu/multitype.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@

<item android:id="@+id/testZeroHeight"
android:title="测试第一个组件高度=0"/>

<item android:id="@+id/toggleSkeleton"
android:title="开关骨架屏效果"/>

</menu>
4 changes: 2 additions & 2 deletions flap/src/main/java/me/yifeiyuan/flap/FlapAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ open class FlapAdapter : RecyclerView.Adapter<Component<*>>(), IRegistry {
var paramProvider: ExtraParamsProvider? = null

private var itemClicksHelper = ItemClicksHelper()
private val emptyViewHelper = EmptyViewHelper()
val emptyViewHelper = EmptyViewHelper()

lateinit var bindingRecyclerView: RecyclerView
lateinit var bindingContext: Context
Expand Down Expand Up @@ -319,7 +319,7 @@ open class FlapAdapter : RecyclerView.Adapter<Component<*>>(), IRegistry {
super.onDetachedFromRecyclerView(recyclerView)
FlapDebug.d(TAG, "onDetachedFromRecyclerView: ")
itemClicksHelper.detachRecyclerView(recyclerView)
emptyViewHelper.detachRecyclerView(recyclerView)
emptyViewHelper.detachRecyclerView()
}

/**
Expand Down
Loading

0 comments on commit 0c63166

Please sign in to comment.