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()