From ff1432561c11d596ac7c39c9630f091701142b7a Mon Sep 17 00:00:00 2001 From: tangwanchao <18284228392@163.com> Date: Thu, 22 Sep 2022 16:10:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=A9=BA=E5=92=8C=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/twc/source/observer/engine/ISourceObserverView.kt | 4 ++-- .../me/twc/source/observer/processor/ErrorSourceProcessor.kt | 2 +- .../java/me/twc/source/observer/widget/SourceObserverView.kt | 4 ++-- .../main/java/me/twc/source/observer/paging/ObserverUtil.kt | 5 +++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/observer/src/main/java/me/twc/source/observer/engine/ISourceObserverView.kt b/observer/src/main/java/me/twc/source/observer/engine/ISourceObserverView.kt index 8cb8096..b2dbe54 100644 --- a/observer/src/main/java/me/twc/source/observer/engine/ISourceObserverView.kt +++ b/observer/src/main/java/me/twc/source/observer/engine/ISourceObserverView.kt @@ -16,12 +16,12 @@ interface ISourceObserverView { /** * 展示异常 ui */ - fun showSourceErrorView() + fun showSourceErrorView(message: String = "网络或服务器异常") /** * 展示空数据 ui */ - fun showSourceEmptyView() + fun showSourceEmptyView(message: String = "暂无数据") /** * 展示成功 ui diff --git a/observer/src/main/java/me/twc/source/observer/processor/ErrorSourceProcessor.kt b/observer/src/main/java/me/twc/source/observer/processor/ErrorSourceProcessor.kt index 47a91a8..cc8c85e 100644 --- a/observer/src/main/java/me/twc/source/observer/processor/ErrorSourceProcessor.kt +++ b/observer/src/main/java/me/twc/source/observer/processor/ErrorSourceProcessor.kt @@ -17,7 +17,7 @@ interface ErrorSourceProcessor { object SimpleContentErrorSourceProcessor : ErrorSourceProcessor { override fun process(view: ISourceObserverView, error: ErrorSource): Pair { - view.showSourceErrorView() + view.showSourceErrorView(error.message) return true to null } } diff --git a/observer/src/main/java/me/twc/source/observer/widget/SourceObserverView.kt b/observer/src/main/java/me/twc/source/observer/widget/SourceObserverView.kt index 806a2c5..cad2f02 100644 --- a/observer/src/main/java/me/twc/source/observer/widget/SourceObserverView.kt +++ b/observer/src/main/java/me/twc/source/observer/widget/SourceObserverView.kt @@ -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() } diff --git a/paging/src/main/java/me/twc/source/observer/paging/ObserverUtil.kt b/paging/src/main/java/me/twc/source/observer/paging/ObserverUtil.kt index c477dc9..2cce487 100644 --- a/paging/src/main/java/me/twc/source/observer/paging/ObserverUtil.kt +++ b/paging/src/main/java/me/twc/source/observer/paging/ObserverUtil.kt @@ -16,6 +16,7 @@ fun LiveData>>.paginationRefreshObserver( owner: LifecycleOwner, refreshLayout: SmartRefreshLayout, observerView: ISourceObserverView, + emptyMessage: String = "暂无数据", block: (list: List) -> Unit ) = this.observe(owner) { source -> when (source) { @@ -25,14 +26,14 @@ fun LiveData>>.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()