Skip to content

Commit

Permalink
perf: 整理demo
Browse files Browse the repository at this point in the history
  • Loading branch information
limuyang2 committed Nov 7, 2023
1 parent c51c612 commit a40f865
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.chad.baserecyclerviewadapterhelper.activity.emptyview.adapter.EmptyVi
import com.chad.baserecyclerviewadapterhelper.base.BaseViewBindingActivity
import com.chad.baserecyclerviewadapterhelper.data.DataServer
import com.chad.baserecyclerviewadapterhelper.databinding.ActivityEmptyViewUseBinding
import com.chad.library.adapter.base.layoutmanager.QuickGridLayoutManager

class EmptyViewUseActivity : BaseViewBindingActivity<ActivityEmptyViewUseBinding>() {

Expand Down Expand Up @@ -61,7 +60,7 @@ class EmptyViewUseActivity : BaseViewBindingActivity<ActivityEmptyViewUseBinding

private fun onRefresh() {
// 方式一:直接传入 layout id
mAdapter.setEmptyViewLayout(this, R.layout.loading_view)
mAdapter.setStateViewLayout(this, R.layout.loading_view)

viewBinding.rvList.postDelayed({
if (mError) { // 模拟网络错误
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.chad.baserecyclerviewadapterhelper.R
import com.chad.baserecyclerviewadapterhelper.databinding.LayoutAnimationBinding
import com.chad.baserecyclerviewadapterhelper.entity.Status
import com.chad.library.adapter.base.BaseQuickAdapter
Expand All @@ -22,14 +21,10 @@ class EmptyViewAdapter : BaseQuickAdapter<Status, EmptyViewAdapter.VH>() {
return VH(parent)
}

override fun onBindViewHolder(holder: VH, position: Int, item: Status?) {
when (holder.layoutPosition % 3) {
0 -> holder.binding.img.setImageResource(R.mipmap.animation_img1)
1 -> holder.binding.img.setImageResource(R.mipmap.animation_img2)
2 -> holder.binding.img.setImageResource(R.mipmap.animation_img3)
else -> {}
}
holder.binding.tweetName.text = "Hoteis in Rio de Janeiro"
override fun onBindViewHolder(holder: VH, position: Int, item: Status?) {
if (item == null) return
holder.binding.img.setImageResource(item.userAvatar)
holder.binding.tweetName.text = item.userName
holder.binding.tweetText.text = "O ever youthful,O ever weeping"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.chad.baserecyclerviewadapterhelper.data

import com.chad.baserecyclerviewadapterhelper.R
import com.chad.baserecyclerviewadapterhelper.entity.DiffEntity
import com.chad.baserecyclerviewadapterhelper.entity.Status

Expand All @@ -11,33 +12,27 @@ object DataServer {
"https://avatars1.githubusercontent.com/u/7698209?v=3&s=460"
const val CYM_CHAD = "CymChad"
const val CHAY_CHAN = "ChayChan"
fun getSampleData(lenth: Int): List<Status> {
fun getSampleData(lenth: Int): MutableList<Status> {
val list: MutableList<Status> = ArrayList()
for (i in 0 until lenth) {
val status = Status()
status.userName = "Chad$i"
status.createdAt = "04/05/$i"
status.isRetweet = i % 2 == 0
status.userAvatar = "https://avatars1.githubusercontent.com/u/7698209?v=3&s=460"


status.userAvatar = when (i % 3) {
0 -> R.mipmap.animation_img1
1 -> R.mipmap.animation_img2
else -> R.mipmap.animation_img3
}
status.text = "BaseRecyclerViewAdpaterHelper https://www.recyclerview.org"
list.add(status)
}
return list
}

fun addData(list: MutableList<Status>, dataSize: Int): List<Status> {
for (i in 0 until dataSize) {
val status = Status()
status.userName = "Chad$i"
status.createdAt = "04/05/$i"
status.isRetweet = i % 2 == 0
status.userAvatar = "https://avatars1.githubusercontent.com/u/7698209?v=3&s=460"
status.text =
"Powerful and flexible RecyclerAdapter https://github.com/CymChad/BaseRecyclerViewAdapterHelper"
list.add(status)
}
return list
}


val strData: List<String>
get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class Status {
private boolean isRetweet;
private String text;
private String userName;
private String userAvatar;
private int userAvatar;
private String createdAt;

public boolean isRetweet() {
Expand All @@ -34,11 +34,11 @@ public void setUserName(String userName) {
this.userName = userName;
}

public String getUserAvatar() {
public int getUserAvatar() {
return userAvatar;
}

public void setUserAvatar(String userAvatar) {
public void setUserAvatar(int userAvatar) {
this.userAvatar = userAvatar;
}

Expand Down

0 comments on commit a40f865

Please sign in to comment.