Skip to content

Commit

Permalink
+ 支持启用和关闭PageRefreshLayout的缺省页功能
Browse files Browse the repository at this point in the history
  • Loading branch information
liangjingkanji committed Jan 13, 2020
1 parent c1ac319 commit b5293e1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ allprojects {
module 的 build.gradle

```groovy
implementation 'com.github.liangjingkanji:BRV:1.2.8'
implementation 'com.github.liangjingkanji:BRV:1.2.9'
```


Expand Down
20 changes: 15 additions & 5 deletions brv/src/main/java/com/drake/brv/PageRefreshLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,25 @@ open class PageRefreshLayout : SmartRefreshLayout, OnRefreshLoadMoreListener {
var startIndex = 1
}

internal var stateEnabled = true // 启用缺省页
var stateEnabled = true // 启用缺省页
set(value) {
field = value
if (!field && !mEnableLoadMore) {
setEnableLoadMore(field)

if (!value && !mEnableLoadMore) {
setEnableLoadMore(value)
}

if (value && state == null && finishInflate) {
replaceStateLayout()
} else {
showContent()
}

field = value
}


private var stateChanged = false
private var finishInflate = false
private var trigger = false
private var hasMore = true
private var adapter: BindingAdapter? = null
Expand Down Expand Up @@ -112,6 +121,7 @@ open class PageRefreshLayout : SmartRefreshLayout, OnRefreshLoadMoreListener {

override fun onFinishInflate() {
super.onFinishInflate()
finishInflate = true
init()
}

Expand Down Expand Up @@ -343,7 +353,7 @@ open class PageRefreshLayout : SmartRefreshLayout, OnRefreshLoadMoreListener {
* @param force 强制显示错误页面
*/
fun showError(tag: Any? = null, force: Boolean = false) {
if (force || !loaded && stateEnabled) {
if (stateEnabled && (force || !loaded)) {
loaded = false
state?.showError(tag)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class RefreshFragment : Fragment() {

}.autoRefresh()


/*
* 关于自动化分页加载请查看我的网络请求库 Net : https://github.com/liangjingkanji/Net
*/
Expand Down
2 changes: 2 additions & 0 deletions smaple/src/main/res/layout/fragment_refresh.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@


<com.drake.brv.PageRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/page"
app:stateEnabled="false"
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand Down

0 comments on commit b5293e1

Please sign in to comment.