Commit 43eb0c28 authored by yinjiacheng's avatar yinjiacheng

add 商品管理列表无数据时增加空视图

parent 1235915f
package com.yidian.common.widget
import android.content.Context
import android.util.AttributeSet
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import com.yidian.common.R
import com.yidian.common.databinding.ViewCommonEmptyPageBinding
/**
* author: yinjiacheng
* date: 7/9/21 8:06 PM
* description: 空视图
*/
class CommonEmptyPageView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = 0
) : ConstraintLayout(context, attrs, defStyle) {
private val viewBinding by lazy {
ViewCommonEmptyPageBinding.bind(
View.inflate(
getContext(),
R.layout.view_common_empty_page,
this
)
)
}
init {
val typeArray = context.obtainStyledAttributes(attrs, R.styleable.CommonEmptyPageView)
viewBinding.ivPlaceHolder.setImageResource(
typeArray.getResourceId(
R.styleable.CommonEmptyPageView_CommonEmptyPageView_place_holder_img,
-1
)
)
viewBinding.tvEmptyContent.text = typeArray.getText(R.styleable.CommonEmptyPageView_CommonEmptyPageView_empty_content_text)
viewBinding.tvEmptyTips.text = typeArray.getText(R.styleable.CommonEmptyPageView_CommonEmptyPageView_empty_tips_text)
typeArray.recycle()
}
}
<?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">
<ImageView
android:id="@+id/iv_place_holder"
android:layout_width="@dimen/dp200"
android:layout_height="@dimen/dp118"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.32"
tools:src="@drawable/img_empty_place_holder" />
<TextView
android:id="@+id/tv_empty_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp10"
android:textColor="@color/color_333333"
android:textSize="@dimen/sp16"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/iv_place_holder"
tools:text="暂无优惠券" />
<TextView
android:id="@+id/tv_empty_tips"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp4"
android:textColor="@color/color_C2C2C2"
android:textSize="@dimen/sp12"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_empty_content"
tools:text="点击下方发布优惠券" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
...@@ -4,4 +4,9 @@ ...@@ -4,4 +4,9 @@
<attr name="CommonTopBarView_title_text" format="string" /> <attr name="CommonTopBarView_title_text" format="string" />
<attr name="CommonTopBarView_action_text" format="string" /> <attr name="CommonTopBarView_action_text" format="string" />
</declare-styleable> </declare-styleable>
<declare-styleable name="CommonEmptyPageView">
<attr name="CommonEmptyPageView_place_holder_img" format="reference" />
<attr name="CommonEmptyPageView_empty_content_text" format="string" />
<attr name="CommonEmptyPageView_empty_tips_text" format="string" />
</declare-styleable>
</resources> </resources>
\ No newline at end of file
package com.yidian.shenghuoquan.commodity.ui.coupon.fragment package com.yidian.shenghuoquan.commodity.ui.coupon.fragment
import androidx.core.view.isVisible
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.scwang.smart.refresh.layout.api.RefreshLayout import com.scwang.smart.refresh.layout.api.RefreshLayout
...@@ -50,7 +51,12 @@ class CommodityListFragment(private val status: CommodityStatus) : ...@@ -50,7 +51,12 @@ class CommodityListFragment(private val status: CommodityStatus) :
private fun subscribeLiveData() { private fun subscribeLiveData() {
vm.refreshFinish.observe(this, { vm.refreshFinish.observe(this, {
binding.rlCommodityList.finishRefresh() binding.rlCommodityList.finishRefresh()
adapter?.updateData(it) if (it.isNullOrEmpty()) {
binding.pvEmptyPage.isVisible = true
} else {
binding.pvEmptyPage.isVisible = false
adapter?.updateData(it)
}
}) })
vm.loadMoreFinish.observe(this, { vm.loadMoreFinish.observe(this, {
binding.rlCommodityList.finishLoadMore() binding.rlCommodityList.finishLoadMore()
......
...@@ -30,6 +30,15 @@ ...@@ -30,6 +30,15 @@
</com.scwang.smart.refresh.layout.SmartRefreshLayout> </com.scwang.smart.refresh.layout.SmartRefreshLayout>
<com.yidian.common.widget.CommonEmptyPageView
android:id="@+id/pv_empty_page"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:CommonEmptyPageView_empty_content_text="@string/no_coupons"
app:CommonEmptyPageView_empty_tips_text="@string/click_post_coupon"
app:CommonEmptyPageView_place_holder_img="@drawable/img_empty_place_holder" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</layout> </layout>
\ No newline at end of file
...@@ -9,4 +9,6 @@ ...@@ -9,4 +9,6 @@
<string name="edit">编辑</string> <string name="edit">编辑</string>
<string name="up_shelves">上架</string> <string name="up_shelves">上架</string>
<string name="publish_coupon">发布优惠券</string> <string name="publish_coupon">发布优惠券</string>
<string name="no_coupons">暂无优惠券</string>
<string name="click_post_coupon">点击下方发布优惠券</string>
</resources> </resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment