-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modify: 优化show逻辑 lastState改为对象地址 同一state不再create
- Loading branch information
1 parent
42728ac
commit 4a2a370
Showing
13 changed files
with
181 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
app/src/main/java/com/zy/demo/SmartRefreshLayoutActivity2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.zy.demo | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.lifecycle.lifecycleScope | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import com.zy.demo.base.* | ||
import com.zy.demo.databinding.ActivitySmartRefreshLayout2Binding | ||
import com.zy.demo.databinding.ActivitySmartRefreshLayoutBinding | ||
import com.zy.multistatepage.bindMultiState | ||
import kotlinx.coroutines.delay | ||
|
||
/** | ||
* @ProjectName: MultiStatePage | ||
* @Author: jojo | ||
* @Email: 17635289240@163.com | ||
* @CreateDate: 2021/8/2 5:48 下午 | ||
* @Description: TODO | ||
*/ | ||
class SmartRefreshLayoutActivity2 : BaseActivity<ActivitySmartRefreshLayout2Binding>() { | ||
private val rlvAdapter = SmartRefreshLayoutActivity.RlvAdapter() | ||
private val container by lazy { viewBinding.recyclerView.bindMultiState() } | ||
|
||
override fun initPage() { | ||
viewBinding.recyclerView.layoutManager = LinearLayoutManager(this) | ||
viewBinding.recyclerView.adapter = rlvAdapter | ||
loadData() | ||
|
||
|
||
viewBinding.smartRefreshLayout.setEnableLoadMoreWhenContentNotFull(false) | ||
|
||
viewBinding.smartRefreshLayout.setOnRefreshListener { | ||
rlvAdapter.refreshData(getData(50)) | ||
container.showSuccess() | ||
it.finishRefresh() | ||
} | ||
viewBinding.smartRefreshLayout.setOnLoadMoreListener { | ||
rlvAdapter.addData(getData(30)) | ||
container.showSuccess() | ||
it.finishLoadMore() | ||
} | ||
|
||
viewBinding.btnContent.setOnClickListener { | ||
rlvAdapter.refreshData(getData(50)) | ||
container.showSuccess() | ||
} | ||
viewBinding.btnError.setOnClickListener { | ||
rlvAdapter.clearData() | ||
container.showError() { | ||
it.retry { loadData() } | ||
} | ||
} | ||
viewBinding.btnEmpty.setOnClickListener { | ||
rlvAdapter.clearData() | ||
container.showEmpty() | ||
} | ||
} | ||
|
||
private fun loadData() { | ||
lifecycleScope.launchWhenResumed { | ||
container.showLoading() | ||
delay(3000) | ||
rlvAdapter.refreshData(getData(50)) | ||
container.showSuccess() | ||
} | ||
} | ||
|
||
private fun getData(count: Int): MutableList<String> { | ||
val data = mutableListOf<String>() | ||
for (i in 0 until count) { | ||
data.add("data") | ||
} | ||
return data | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
app/src/main/res/layout/activity_smart_refresh_layout2.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context="com.zy.demo.SmartRefreshLayoutActivity"> | ||
|
||
<com.scwang.smart.refresh.layout.SmartRefreshLayout | ||
android:id="@+id/smart_refresh_layout" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:layout_constrainedHeight="true" | ||
app:layout_constraintBottom_toTopOf="@id/ll" | ||
app:layout_constraintTop_toTopOf="parent"> | ||
|
||
<androidx.appcompat.widget.LinearLayoutCompat | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content"> | ||
|
||
<androidx.recyclerview.widget.RecyclerView | ||
android:id="@+id/recycler_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
</androidx.appcompat.widget.LinearLayoutCompat> | ||
|
||
</com.scwang.smart.refresh.layout.SmartRefreshLayout> | ||
|
||
<LinearLayout | ||
android:id="@+id/ll" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal" | ||
app:layout_constraintBottom_toBottomOf="parent"> | ||
|
||
<Button | ||
android:id="@+id/btn_error" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="error" /> | ||
|
||
<Button | ||
android:id="@+id/btn_empty" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="empty" /> | ||
|
||
<Button | ||
android:id="@+id/btn_content" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="content" /> | ||
</LinearLayout> | ||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters