feat(watch): 新增已登录未绑定手表的图文占位视图
- 新增 layout_no_watch 占位视图,包含图片、提示文字和"去绑定"按钮 - 新增 onBindWatchClick 回调,供外部处理绑定跳转逻辑 - 提取 showLoginEmpty() 和 showNoWatchPlaceholder() 辅助方法,统一状态管理 - 优化 setWatchInfo() 逻辑,完善已登录无手表时的视图切换 - 修复 init() 中 Tab 切换时的占位视图显示逻辑 - 改进代码格式和缩进规范
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.xjjk.healthyclients.view
|
package com.xjjk.healthyclients.view
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.graphics.Color
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
@@ -26,11 +27,11 @@ class HomeWatchView(context: Context?, attrs: AttributeSet?) :
|
|||||||
RelativeLayout(context, attrs, 0), ViewPagerAdapter.OnCreateFragmentListener {
|
RelativeLayout(context, attrs, 0), ViewPagerAdapter.OnCreateFragmentListener {
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
/** 自动轮播间隔时间(毫秒) */
|
/** 自动轮播间隔时间(毫秒) */
|
||||||
private const val AUTO_PLAY_INTERVAL = 5000L
|
private const val AUTO_PLAY_INTERVAL = 5000L
|
||||||
}
|
}
|
||||||
private var hasWatch :Boolean=false
|
private var hasWatch: Boolean = false
|
||||||
|
|
||||||
var mContext: Context? = context
|
var mContext: Context? = context
|
||||||
var mBinding: LayoutHomeItemWatchBinding = DataBindingUtil.inflate(
|
var mBinding: LayoutHomeItemWatchBinding = DataBindingUtil.inflate(
|
||||||
@@ -60,25 +61,23 @@ class HomeWatchView(context: Context?, attrs: AttributeSet?) :
|
|||||||
|
|
||||||
fun init(fragment: Fragment) {
|
fun init(fragment: Fragment) {
|
||||||
val arrayOf = arrayOf("心脑血管", "癌症", "慢呼", "糖尿病", "亚健康")
|
val arrayOf = arrayOf("心脑血管", "癌症", "慢呼", "糖尿病", "亚健康")
|
||||||
mBinding.watchTabLayout.onCreateTab(arrayOf, 1) {tab->
|
mBinding.watchTabLayout.onCreateTab(arrayOf, 1) { tab ->
|
||||||
if (tab?.position != 0) {
|
if (tab?.position != 0) {
|
||||||
mBinding.emptyText.visibility = View.VISIBLE
|
mBinding.emptyText.visibility = View.VISIBLE
|
||||||
mBinding.emptyText.text = "紧急开发中"
|
mBinding.emptyText.text = "紧急开发中"
|
||||||
mBinding.viewPager.visibility = View.GONE
|
mBinding.viewPager.visibility = View.GONE
|
||||||
|
mBinding.layoutNoWatch.visibility = View.GONE
|
||||||
stopAutoPlay()
|
stopAutoPlay()
|
||||||
} else {
|
} else {
|
||||||
if (!DataStoreManager.isLogin()) {
|
if (!DataStoreManager.isLogin()) {
|
||||||
mBinding.viewPager.visibility = View.GONE
|
showLoginEmpty()
|
||||||
mBinding.emptyText.visibility = View.VISIBLE
|
} else if (hasWatch) {
|
||||||
mBinding.emptyText.text = "暂未登录"
|
|
||||||
}else if (hasWatch) {
|
|
||||||
mBinding.viewPager.visibility = View.VISIBLE
|
mBinding.viewPager.visibility = View.VISIBLE
|
||||||
mBinding.emptyText.visibility = View.GONE
|
mBinding.emptyText.visibility = View.GONE
|
||||||
|
mBinding.layoutNoWatch.visibility = View.GONE
|
||||||
startAutoPlay()
|
startAutoPlay()
|
||||||
} else {
|
} else {
|
||||||
mBinding.viewPager.visibility = View.GONE
|
showNoWatchPlaceholder()
|
||||||
mBinding.emptyText.visibility = View.VISIBLE
|
|
||||||
mBinding.emptyText.text = "您目前未配备智能穿戴设备"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,18 +110,36 @@ class HomeWatchView(context: Context?, attrs: AttributeSet?) :
|
|||||||
|
|
||||||
fun setWatchInfo(watchInfo: WatchInfoBean?) {
|
fun setWatchInfo(watchInfo: WatchInfoBean?) {
|
||||||
if (watchInfo?.hasWatch == true) {
|
if (watchInfo?.hasWatch == true) {
|
||||||
|
hasWatch = true
|
||||||
mBinding.viewPager.visibility = View.VISIBLE
|
mBinding.viewPager.visibility = View.VISIBLE
|
||||||
mBinding.watchName.visibility = View.VISIBLE
|
|
||||||
mBinding.emptyText.visibility = View.GONE
|
mBinding.emptyText.visibility = View.GONE
|
||||||
|
mBinding.layoutNoWatch.visibility = View.GONE
|
||||||
|
mBinding.watchName.setTextColor(Color.parseColor("#14BEBE"))
|
||||||
mBinding.watchName.text = "监测工具编码:${watchInfo.watchNo}"
|
mBinding.watchName.text = "监测工具编码:${watchInfo.watchNo}"
|
||||||
} else {
|
} else {
|
||||||
|
hasWatch = false
|
||||||
|
mBinding.watchName.setTextColor(Color.parseColor("#808080"))
|
||||||
|
mBinding.watchName.text = "监测工具编码:暂无信息"
|
||||||
mBinding.viewPager.visibility = View.GONE
|
mBinding.viewPager.visibility = View.GONE
|
||||||
mBinding.watchName.visibility = View.GONE
|
showNoWatchPlaceholder()
|
||||||
mBinding.emptyText.visibility = View.VISIBLE
|
|
||||||
mBinding.emptyText.text = "您目前未配备智能穿戴设备"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 展示未登录占位文字 */
|
||||||
|
private fun showLoginEmpty() {
|
||||||
|
mBinding.viewPager.visibility = View.GONE
|
||||||
|
mBinding.emptyText.visibility = View.VISIBLE
|
||||||
|
mBinding.emptyText.text = "暂未登录"
|
||||||
|
mBinding.layoutNoWatch.visibility = View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 展示已登录但未绑定手表的图文占位视图 */
|
||||||
|
private fun showNoWatchPlaceholder() {
|
||||||
|
mBinding.viewPager.visibility = View.GONE
|
||||||
|
mBinding.emptyText.visibility = View.GONE
|
||||||
|
mBinding.layoutNoWatch.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接收手表详细数据并通过 EventBus 通知各 WatchItemFragment 刷新
|
* 接收手表详细数据并通过 EventBus 通知各 WatchItemFragment 刷新
|
||||||
* @param dataList 接口返回的手表各项健康数据列表(索引与 Tab position 对应)
|
* @param dataList 接口返回的手表各项健康数据列表(索引与 Tab position 对应)
|
||||||
|
|||||||
@@ -0,0 +1,118 @@
|
|||||||
|
package com.xjjk.healthyclients.view
|
||||||
|
|
||||||
|
import android.app.AlertDialog
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.graphics.drawable.ColorDrawable
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.Gravity
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.WindowManager
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import android.widget.RatingBar
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.databinding.DataBindingUtil
|
||||||
|
import com.sw.healthyclients.view.CustomToast
|
||||||
|
import com.xjjk.healthyclients.R
|
||||||
|
import com.xjjk.healthyclients.databinding.DialogAppraiseBinding
|
||||||
|
|
||||||
|
class AppraiseDialog constructor(
|
||||||
|
context: Context
|
||||||
|
) : AlertDialog(context) {
|
||||||
|
lateinit var mOnSubmitClickListener: OnSubmitClickListener
|
||||||
|
lateinit var binding: DialogAppraiseBinding
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
create()
|
||||||
|
} else {
|
||||||
|
onCreate(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
binding = DataBindingUtil.inflate(
|
||||||
|
LayoutInflater.from(context),
|
||||||
|
R.layout.dialog_appraise, null, false
|
||||||
|
)
|
||||||
|
setContentView(binding.root)
|
||||||
|
window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))//设置dialog背景透明
|
||||||
|
window?.setGravity(Gravity.BOTTOM)
|
||||||
|
window?.setLayout(
|
||||||
|
context.resources.displayMetrics.widthPixels,
|
||||||
|
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||||
|
);//设置对话框大小
|
||||||
|
window?.clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM)
|
||||||
|
binding.btnSubmit.setOnClickListener {
|
||||||
|
if (getRating()==0F) {
|
||||||
|
CustomToast.makeText(context, "您还没有选择星级评分", Toast.LENGTH_SHORT).show()
|
||||||
|
return@setOnClickListener
|
||||||
|
}
|
||||||
|
if (this::mOnSubmitClickListener.isInitialized) {
|
||||||
|
mOnSubmitClickListener?.onSubmitClick(this@AppraiseDialog)
|
||||||
|
}
|
||||||
|
this.cancel()
|
||||||
|
}
|
||||||
|
binding.btnClose.setOnClickListener {
|
||||||
|
if (this::mOnSubmitClickListener.isInitialized) {
|
||||||
|
mOnSubmitClickListener?.onCancelClick(this@AppraiseDialog)
|
||||||
|
}
|
||||||
|
this.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setOnSubmitClickListener(onSubmitClickListener: OnSubmitClickListener): AppraiseDialog {
|
||||||
|
this.mOnSubmitClickListener = onSubmitClickListener
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
interface OnSubmitClickListener {
|
||||||
|
fun onSubmitClick(viewDialog: AppraiseDialog)
|
||||||
|
fun onCancelClick(viewDialog: AppraiseDialog){}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setDialogTitle(title: String, titleSize: Float = 18f): AppraiseDialog {
|
||||||
|
binding.tvTitle.visibility = View.VISIBLE
|
||||||
|
binding.tvTitle.text = title
|
||||||
|
binding.tvTitle.textSize = titleSize
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setContentHint(text: String, textSize: Float = 13f): AppraiseDialog {
|
||||||
|
binding.etAppraise.hint = text
|
||||||
|
binding.etAppraise.textSize = textSize
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setBtnText(text: String, btnTextSize: Float = 18f): AppraiseDialog {
|
||||||
|
binding.btnSubmit.text = text
|
||||||
|
binding.btnSubmit.textSize = btnTextSize
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setDialogCancelable(flag: Boolean): AppraiseDialog {
|
||||||
|
setCancelable(flag)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getAppraiseContext(): String {
|
||||||
|
return binding.etAppraise.text.trim().toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getRatingBar(): RatingBar {
|
||||||
|
return binding.ratingBar
|
||||||
|
}
|
||||||
|
fun getRating(): Float {
|
||||||
|
return getRatingBar().rating
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取匿名状态
|
||||||
|
*/
|
||||||
|
fun getAnonymityStatus(): Boolean {
|
||||||
|
return binding.cbAnonymity.isChecked
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 9.8 KiB |
@@ -0,0 +1,89 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layout 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">
|
||||||
|
|
||||||
|
<data>
|
||||||
|
|
||||||
|
</data>
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/rectangle_top_round_corner20_white">
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_marginTop="@dimen/dp_20"
|
||||||
|
android:textColor="@color/text_black_33"
|
||||||
|
android:textSize="@dimen/txt14"
|
||||||
|
android:text="@string/dialog_appraise_title"/>
|
||||||
|
<RatingBar
|
||||||
|
android:id="@+id/rating_bar"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/tv_title"
|
||||||
|
style="@style/Widget.AppCompat.RatingBar.Indicator"
|
||||||
|
android:layout_marginTop="@dimen/dp_24"
|
||||||
|
android:layout_marginHorizontal="@dimen/dp_12"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:numStars="5"
|
||||||
|
android:stepSize="0.5"
|
||||||
|
android:rating="0"
|
||||||
|
android:isIndicator="false"
|
||||||
|
android:progressTint="@color/rating_bar_color"
|
||||||
|
android:secondaryProgressTint="@color/rating_bar_color"/>
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/et_appraise"
|
||||||
|
android:longClickable="false"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_below="@+id/rating_bar"
|
||||||
|
android:layout_marginTop="@dimen/dp_18"
|
||||||
|
android:layout_marginHorizontal="@dimen/dp_15"
|
||||||
|
android:background="@drawable/rectangle_round_corner10_gray"
|
||||||
|
android:paddingHorizontal="@dimen/dp_12"
|
||||||
|
android:paddingVertical="@dimen/dp_9"
|
||||||
|
android:minHeight="@dimen/dp_130"
|
||||||
|
android:gravity="top"
|
||||||
|
android:textColor="@color/text_black_33"
|
||||||
|
android:textSize="@dimen/txt13"
|
||||||
|
android:hint="@string/dialog_appraise_hint"/>
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/cb_anonymity"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/dp_10"
|
||||||
|
android:layout_alignLeft="@+id/et_appraise"
|
||||||
|
android:layout_below="@+id/et_appraise"
|
||||||
|
android:button="@drawable/check_theme_style"
|
||||||
|
android:paddingLeft="@dimen/dp_8"
|
||||||
|
android:checked="false"
|
||||||
|
android:text="@string/dialog_appraise_anonymity"/>
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btn_submit"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/rectangle_round_corner20_theme"
|
||||||
|
android:text="@string/dialog_appraise_submit"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:minHeight="@dimen/dp_0"
|
||||||
|
android:layout_below="@+id/cb_anonymity"
|
||||||
|
android:layout_marginHorizontal="@dimen/dp_48"
|
||||||
|
android:layout_marginVertical="@dimen/dp_24"
|
||||||
|
android:outlineProvider="none"
|
||||||
|
android:textSize="@dimen/txt14"
|
||||||
|
android:paddingVertical="@dimen/dp_11"/>
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/btn_close"
|
||||||
|
android:layout_width="@dimen/dp_40"
|
||||||
|
android:layout_height="@dimen/dp_40"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:background="@android:color/transparent"
|
||||||
|
android:padding="@dimen/dp_15"
|
||||||
|
android:src="@drawable/ic_close"/>
|
||||||
|
</RelativeLayout>
|
||||||
|
</layout>
|
||||||
@@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:layout_marginHorizontal="12dp"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="12dp"
|
||||||
android:layout_marginTop="15dp">
|
android:layout_marginTop="15dp">
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
@@ -43,6 +43,7 @@
|
|||||||
tools:text="监测工具编码:4PMBB25A28100553" />
|
tools:text="监测工具编码:4PMBB25A28100553" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
|
android:id="@+id/img_watch_more"
|
||||||
android:layout_width="16dp"
|
android:layout_width="16dp"
|
||||||
android:layout_height="16dp"
|
android:layout_height="16dp"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
@@ -100,6 +101,49 @@
|
|||||||
android:textColor="#77849E"
|
android:textColor="#77849E"
|
||||||
android:textSize="15sp" />
|
android:textSize="15sp" />
|
||||||
|
|
||||||
|
<!-- 已登录但未绑定手表的占位视图 -->
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/layout_no_watch"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/watch_tab_layout"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingTop="20dp"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:paddingBottom="20dp">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_height="60dp"
|
||||||
|
android:src="@drawable/icon_empty1" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:text="~暂无数据~"
|
||||||
|
android:textColor="#B6B6B6"
|
||||||
|
android:textSize="11sp" />
|
||||||
|
|
||||||
|
<com.allen.library.shape.ShapeTextView
|
||||||
|
android:id="@+id/btn_bind_watch"
|
||||||
|
android:layout_width="80dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:paddingStart="20dp"
|
||||||
|
android:paddingEnd="20dp"
|
||||||
|
android:text="去绑定"
|
||||||
|
android:textColor="@color/theme_color"
|
||||||
|
android:textSize="13sp"
|
||||||
|
app:shapeCornersRadius="16dp"
|
||||||
|
app:shapeSolidColor="@color/colorWhite"
|
||||||
|
app:shapeStrokeColor="@color/theme_color"
|
||||||
|
app:shapeStrokeWidth="1dp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</com.allen.library.shape.ShapeRelativeLayout>
|
</com.allen.library.shape.ShapeRelativeLayout>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|||||||
Reference in New Issue
Block a user