Skip to content

Commit

Permalink
支持空和错误消息
Browse files Browse the repository at this point in the history
  • Loading branch information
tangwanchao committed Sep 22, 2022
1 parent fa75d5e commit ff14325
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ interface ISourceObserverView {
/**
* 展示异常 ui
*/
fun showSourceErrorView()
fun showSourceErrorView(message: String = "网络或服务器异常")

/**
* 展示空数据 ui
*/
fun showSourceEmptyView()
fun showSourceEmptyView(message: String = "暂无数据")

/**
* 展示成功 ui
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface ErrorSourceProcessor {

object SimpleContentErrorSourceProcessor : ErrorSourceProcessor {
override fun <T> process(view: ISourceObserverView, error: ErrorSource): Pair<Boolean, T?> {
view.showSourceErrorView()
view.showSourceErrorView(error.message)
return true to null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ abstract class SourceObserverView @JvmOverloads constructor(
showLoading()
}

override fun showSourceErrorView() {
override fun showSourceErrorView(message: String) {
showRetry()
}

override fun showSourceEmptyView() {
override fun showSourceEmptyView(message: String) {
showEmpty()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fun <T> LiveData<Source<IPagination<T>>>.paginationRefreshObserver(
owner: LifecycleOwner,
refreshLayout: SmartRefreshLayout,
observerView: ISourceObserverView,
emptyMessage: String = "暂无数据",
block: (list: List<T>) -> Unit
) = this.observe(owner) { source ->
when (source) {
Expand All @@ -25,14 +26,14 @@ fun <T> LiveData<Source<IPagination<T>>>.paginationRefreshObserver(
}
is ErrorSource -> {
refreshLayout.finishRefresh(false)
observerView.showSourceErrorView()
observerView.showSourceErrorView(source.message)
}
is SuccessSource -> {
val pagination = source.data
refreshLayout.finishRefresh(0, true, pagination.noMoreData())
val data = pagination.getPagingDataList()
if (data.isEmpty()) {
observerView.showSourceEmptyView()
observerView.showSourceEmptyView(emptyMessage)
} else {
refreshLayout.setEnableLoadMore(true)
observerView.showSourceSuccessView()
Expand Down

0 comments on commit ff14325

Please sign in to comment.