From 6c8ea6ffb2d0c5ffad5b501f079b418d47d441dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=99=A8?= Date: Mon, 11 Nov 2024 18:04:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E3=80=90=E5=85=89=E7=8E=AF=E5=8A=A9?= =?UTF-8?q?=E6=89=8B=E3=80=91=E5=AE=A2=E6=88=B7=E7=AB=AFUI=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E8=A7=84=E8=8C=83=E6=9B=B4=E6=96=B0=E5=90=8C=E6=AD=A5?= =?UTF-8?q?2024/06/17=20https://jira.shanqu.cc/browse/GHZSCY-5738?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qa/dialog/MoreFunctionPanelDialog.kt | 40 ++- .../res/layout/dialog_game_detail_more.xml | 2 +- .../view/titlebar/BottomSheetTitleView.kt | 253 ++++++++++++++++++ module_common/src/main/res/values/attrs.xml | 25 ++ module_common/src/main/res/values/style.xml | 12 + 5 files changed, 325 insertions(+), 7 deletions(-) create mode 100644 module_common/src/main/java/com/gh/gamecenter/common/view/titlebar/BottomSheetTitleView.kt diff --git a/app/src/main/java/com/gh/gamecenter/qa/dialog/MoreFunctionPanelDialog.kt b/app/src/main/java/com/gh/gamecenter/qa/dialog/MoreFunctionPanelDialog.kt index 9d0ac90d2d..9de109f97c 100644 --- a/app/src/main/java/com/gh/gamecenter/qa/dialog/MoreFunctionPanelDialog.kt +++ b/app/src/main/java/com/gh/gamecenter/qa/dialog/MoreFunctionPanelDialog.kt @@ -12,15 +12,13 @@ import android.widget.LinearLayout import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat +import androidx.core.widget.TextViewCompat import com.gh.common.util.NewLogUtils import com.gh.gamecenter.common.base.fragment.BaseDraggableDialogFragment import com.gh.gamecenter.common.constant.EntranceConsts import com.gh.gamecenter.common.entity.NormalShareEntity import com.gh.gamecenter.common.eventbus.EBShare -import com.gh.gamecenter.common.utils.ShareUtils -import com.gh.gamecenter.common.utils.debounceActionWithInterval -import com.gh.gamecenter.common.utils.dip2px -import com.gh.gamecenter.common.utils.setDrawableTop +import com.gh.gamecenter.common.utils.* import com.gh.gamecenter.databinding.DialogGameDetailMoreBinding import com.gh.gamecenter.entity.MenuItemEntity import org.greenrobot.eventbus.EventBus @@ -32,6 +30,7 @@ class MoreFunctionPanelDialog : BaseDraggableDialogFragment() { private var mTitle: String = "" private var mParentTag: String = "" private var mStatus: String = "" + private var titleStyle: Int = MORE_DIALOG_TITLE_STYLE_CENTER_BOLD private var mShareEntity: NormalShareEntity? = null private var mShareUtils: ShareUtils? = null @@ -43,6 +42,7 @@ class MoreFunctionPanelDialog : BaseDraggableDialogFragment() { mStatus = getString(KEY_STATUS) ?: "" mShareEntity = getParcelable(KEY_SHARE) mParentTag = getString(EntranceConsts.KEY_PARENT_TAG) ?: "" + titleStyle = getInt(KEY_TITLE_STYLE) } mShareUtils = getShareUtils() } @@ -59,11 +59,30 @@ class MoreFunctionPanelDialog : BaseDraggableDialogFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding.gameNameTv.text = mTitle - binding.gameNameTv.gravity = Gravity.CENTER binding.gameIconView.visibility = View.GONE binding.feedbackTv.visibility = View.GONE binding.copyrightTv.visibility = View.GONE + when (titleStyle) { + MORE_DIALOG_TITLE_STYLE_CENTER_BOLD -> { + TextViewCompat.setTextAppearance(binding.gameNameTv, com.gh.gamecenter.common.R.style.TextBody2B) + binding.gameNameTv.setTextColor(com.gh.gamecenter.common.R.color.text_primary.toColor(requireContext())) + binding.gameNameTv.gravity = Gravity.CENTER + } + + MORE_DIALOG_TITLE_STYLE_LEFT_BOLD -> { + TextViewCompat.setTextAppearance(binding.gameNameTv, com.gh.gamecenter.common.R.style.TextBody2B) + binding.gameNameTv.setTextColor(com.gh.gamecenter.common.R.color.text_primary.toColor(requireContext())) + binding.gameNameTv.gravity = Gravity.START + } + + MORE_DIALOG_TITLE_STYLE_CENTER_NORMAL -> { + TextViewCompat.setTextAppearance(binding.gameNameTv, com.gh.gamecenter.common.R.style.TextBody2) + binding.gameNameTv.setTextColor(com.gh.gamecenter.common.R.color.text_secondary.toColor(requireContext())) + binding.gameNameTv.gravity = Gravity.CENTER + } + } + binding.shareWechatTv.setOnClickListener { debounceActionWithInterval(it.id, 2000) { if (checkStatusIsPass()) { @@ -142,10 +161,12 @@ class MoreFunctionPanelDialog : BaseDraggableDialogFragment() { toast("内容审核中,不支持分享") false } + "fail" -> { toast("内容审核不通过,不支持分享") false } + else -> true } } @@ -227,8 +248,13 @@ class MoreFunctionPanelDialog : BaseDraggableDialogFragment() { const val KEY_TITLE = "title" const val KEY_SHARE = "share" const val KEY_STATUS = "status" + const val KEY_TITLE_STYLE = "title_style" const val REQUEST_CODE = 1101 + const val MORE_DIALOG_TITLE_STYLE_CENTER_BOLD = 0 // 居中-加粗 + const val MORE_DIALOG_TITLE_STYLE_LEFT_BOLD = 1 // 左对齐-加粗 + const val MORE_DIALOG_TITLE_STYLE_CENTER_NORMAL = 2 // 居中 + @JvmStatic fun showMoreDialog( activity: AppCompatActivity, @@ -236,7 +262,8 @@ class MoreFunctionPanelDialog : BaseDraggableDialogFragment() { title: String, share: NormalShareEntity, status: String, - parentTag: String + parentTag: String, + titleStyle: Int = MORE_DIALOG_TITLE_STYLE_CENTER_BOLD ) { MoreFunctionPanelDialog().apply { arguments = Bundle().apply { @@ -245,6 +272,7 @@ class MoreFunctionPanelDialog : BaseDraggableDialogFragment() { putParcelable(KEY_SHARE, share) putString(KEY_STATUS, status) putString(EntranceConsts.KEY_PARENT_TAG, parentTag) + putInt(KEY_TITLE_STYLE, titleStyle) } }.show( activity.supportFragmentManager, diff --git a/app/src/main/res/layout/dialog_game_detail_more.xml b/app/src/main/res/layout/dialog_game_detail_more.xml index 265c945856..d1fbdd979e 100644 --- a/app/src/main/res/layout/dialog_game_detail_more.xml +++ b/app/src/main/res/layout/dialog_game_detail_more.xml @@ -46,7 +46,7 @@ android:id="@+id/gameIconView" android:layout_width="28dp" android:layout_height="28dp" - android:layout_marginRight="12dp" + android:layout_marginRight="8dp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> diff --git a/module_common/src/main/java/com/gh/gamecenter/common/view/titlebar/BottomSheetTitleView.kt b/module_common/src/main/java/com/gh/gamecenter/common/view/titlebar/BottomSheetTitleView.kt new file mode 100644 index 0000000000..f6f08a8ec4 --- /dev/null +++ b/module_common/src/main/java/com/gh/gamecenter/common/view/titlebar/BottomSheetTitleView.kt @@ -0,0 +1,253 @@ +package com.gh.gamecenter.common.view.titlebar + +import android.content.Context +import android.content.res.ColorStateList +import android.util.AttributeSet +import android.util.TypedValue +import android.view.Gravity +import android.view.View +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.appcompat.content.res.AppCompatResources +import androidx.appcompat.view.ContextThemeWrapper +import androidx.constraintlayout.widget.ConstraintLayout +import com.gh.gamecenter.common.R +import com.gh.gamecenter.common.utils.dip2px +import com.gh.gamecenter.common.utils.toColor +import splitties.views.dsl.constraintlayout.* +import splitties.views.dsl.core.add +import splitties.views.dsl.core.matchParent +import splitties.views.dsl.core.wrapContent + +/** + * 面板标题栏 + * 一般用于底部拉起面板 + */ +class BottomSheetTitleView @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0, + defStyleRes: Int = 0 +) : ConstraintLayout(context, attrs, defStyleAttr, defStyleRes) { + + private lateinit var config: Config + + private var leftView: View? = null + private var rightView: View? = null + + init { + setBackgroundResource(R.drawable.background_shape_white_radius_12_top_only) + initAttrs(context, attrs) + } + + private fun initAttrs(context: Context, attrs: AttributeSet?) { + val typedArray = context.obtainStyledAttributes(attrs, R.styleable.BottomSheetTitleView) + val leftStyle = typedArray.getInt(R.styleable.BottomSheetTitleView_left_style, BUTTON_STYLE_TEXT) + val leftText = typedArray.getString(R.styleable.BottomSheetTitleView_left_text) ?: "" + val leftTextColor = typedArray.getColor(R.styleable.BottomSheetTitleView_left_text_color, -1) + val leftIconResource = typedArray.getResourceId(R.styleable.BottomSheetTitleView_left_icon_resource, -1) + val leftIconColor = typedArray.getColor(R.styleable.BottomSheetTitleView_left_icon_color, -1) + val leftButtonBackgroundResource = + typedArray.getResourceId(R.styleable.BottomSheetTitleView_left_button_background_resource, -1) + val title = typedArray.getString(R.styleable.BottomSheetTitleView_title) ?: "" + val rightStyle = typedArray.getInt(R.styleable.BottomSheetTitleView_right_style, -1) + val rightText = typedArray.getString(R.styleable.BottomSheetTitleView_right_text) ?: "" + val rightTextColor = typedArray.getColor(R.styleable.BottomSheetTitleView_right_text_color, -1) + val rightIconResource = typedArray.getResourceId(R.styleable.BottomSheetTitleView_right_icon_resource, -1) + val rightIconColor = typedArray.getColor(R.styleable.BottomSheetTitleView_right_icon_color, -1) + val rightButtonBackgroundResource = + typedArray.getResourceId(R.styleable.BottomSheetTitleView_right_button_background_resource, -1) + + config = Config( + leftStyle = leftStyle, + leftText = leftText, + leftTextColor = leftTextColor, + leftIconResource = leftIconResource, + leftIconColor = leftIconColor, + leftButtonBackgroundResource = leftButtonBackgroundResource, + title = title, + rightStyle = rightStyle, + rightText = rightText, + rightTextColor = rightTextColor, + rightIconResource = rightIconResource, + rightIconColor = rightIconColor, + rightButtonBackgroundResource = rightButtonBackgroundResource + ) + + typedArray.recycle() + + initView() + } + + private fun initView() { + leftView = when (config.leftStyle) { + BUTTON_STYLE_TEXT -> createTextView(context, true) + + BUTTON_STYLE_ICON -> createIconView(context, true) + + BUTTON_STYLE_BUTTON -> createButtonView(context, true) + + BUTTON_STYLE_TITLE -> createTitleView(context) + + else -> null + + } + leftView?.let { + + add(it, lParams(it.wrapContent, it.matchParent) { + startOfParent() + topOfParent() + bottomOfParent() + }) + } + + rightView = when (config.rightStyle) { + BUTTON_STYLE_TEXT -> createTextView(context, false) + + BUTTON_STYLE_ICON -> createIconView(context, false) + + BUTTON_STYLE_BUTTON -> createButtonView(context, false) + + else -> null + } + rightView?.let { + add(it, lParams(it.wrapContent, it.matchParent) { + endOfParent() + topOfParent() + bottomOfParent() + }) + } + + if (config.leftStyle != BUTTON_STYLE_TITLE) { + createTitleView(context).let { + add(it, lParams(it.wrapContent, it.matchParent) { + endOfParent() + startOfParent() + topOfParent() + bottomOfParent() + }) + } + } + } + + private fun createTitleView(context: Context): View { + val themedContext = ContextThemeWrapper(context, R.style.TextHeadline) + val textView = TextView(themedContext) + textView.setPadding(16F.dip2px(), 0, 16F.dip2px(), 0) + textView.gravity = Gravity.CENTER + textView.setTextColor(R.color.text_primary.toColor(context)) + textView.text = config.title + return textView + } + + private fun createButtonView( + context: Context, + isLeft: Boolean + ): View { + val backgroundResId = if (isLeft) { + config.leftButtonBackgroundResource + } else { + config.rightButtonBackgroundResource + } + val textColor = if (isLeft) { + config.leftTextColor + } else { + config.rightTextColor + } + + val text = if (isLeft) { + config.leftText + } else { + config.rightText + } + + val themedContext = ContextThemeWrapper(context, R.style.BtnMiniStyle) + val textView = TextView(themedContext) + if (backgroundResId == -1) { + textView.setBackgroundResource(R.drawable.bg_common_button_fill_blue) + } else { + textView.setBackgroundResource(backgroundResId) + } + textView.height = 24F.dip2px() + + if (textColor == -1) { + textView.setTextColor(R.color.text_aw_primary.toColor(context)) + } else { + textView.setTextColor(textColor) + } + textView.text = text + + val btnContainer = LinearLayout(context) + btnContainer.gravity = Gravity.CENTER + btnContainer.setPadding(16F.dip2px(), 0, 16F.dip2px(), 0) + btnContainer.addView(textView) + return btnContainer + } + + private fun createIconView(context: Context, isLeft: Boolean): View { + val iconResId = if (isLeft) config.leftIconResource else config.rightIconResource + val iconColor = if (isLeft) config.leftIconColor else config.rightIconColor + + val imageView = ImageView(context) + if (iconResId != -1) { + val drawable = AppCompatResources.getDrawable(context, iconResId) + imageView.setImageDrawable(drawable) + } + + if (iconColor != -1) { + imageView.imageTintList = ColorStateList.valueOf(iconColor) + } + + imageView.setPadding(16F.dip2px(), 0, 16F.dip2px(), 0) + return imageView + } + + private fun createTextView(context: Context, isLeft: Boolean): View { + val text = if (isLeft) config.leftText else config.rightText + val textColor = if (isLeft) config.leftTextColor else config.rightTextColor + val textView = TextView(context) + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14F) + textView.setPadding(16F.dip2px(), 0, 16F.dip2px(), 0) + textView.gravity = Gravity.CENTER + textView.text = text + if (textColor == -1) { + textView.setTextColor(R.color.primary_theme.toColor(context)) + } else { + textView.setTextColor(textColor) + } + return textView + } + + fun setOnLeftClickListener(onClick: (View) -> Unit) { + leftView?.setOnClickListener(onClick) + } + + fun setOnRightClickListener(onClick: (View) -> Unit) { + rightView?.setOnClickListener(onClick) + } + + companion object { + + private const val BUTTON_STYLE_TEXT = 0 // 纯文本 + private const val BUTTON_STYLE_ICON = 1 // 图标 + private const val BUTTON_STYLE_BUTTON = 2 // 按钮 + private const val BUTTON_STYLE_TITLE = 3 // 标题 + } + + class Config( + val leftStyle: Int = -1, + val leftText: String = "", + val leftTextColor: Int = -1, + val leftIconResource: Int = -1, + val leftIconColor: Int = -1, + val leftButtonBackgroundResource: Int = -1, + val title: String = "", + val rightStyle: Int = -1, + val rightText: String = "", + val rightTextColor: Int = -1, + val rightIconResource: Int = -1, + val rightIconColor: Int = -1, + val rightButtonBackgroundResource: Int = -1 + ) +} \ No newline at end of file diff --git a/module_common/src/main/res/values/attrs.xml b/module_common/src/main/res/values/attrs.xml index 47c952f916..6e09afa101 100644 --- a/module_common/src/main/res/values/attrs.xml +++ b/module_common/src/main/res/values/attrs.xml @@ -267,4 +267,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/module_common/src/main/res/values/style.xml b/module_common/src/main/res/values/style.xml index c9ce84b08e..b0d396bd38 100644 --- a/module_common/src/main/res/values/style.xml +++ b/module_common/src/main/res/values/style.xml @@ -200,6 +200,18 @@ bold + + + + + +