fix:【光环助手】客户端UI组件规范更新同步2024/06/17 https://jira.shanqu.cc/browse/GHZSCY-5738
This commit is contained in:
@ -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,
|
||||
|
||||
@ -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" />
|
||||
|
||||
|
||||
@ -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
|
||||
)
|
||||
}
|
||||
@ -267,4 +267,29 @@
|
||||
<flag name="regular" value="2" />
|
||||
</attr>
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="BottomSheetTitleView">
|
||||
<attr name="left_style" format="integer">
|
||||
<flag name="text" value="0" />
|
||||
<flag name="icon" value="1" />
|
||||
<flag name="button" value="2" />
|
||||
<flag name="title" value="3" />
|
||||
</attr>
|
||||
<attr name="left_text" format="string" />
|
||||
<attr name="left_text_color" format="color|reference" />
|
||||
<attr name="left_icon_resource" format="reference" />
|
||||
<attr name="left_icon_color" format="color|reference" />
|
||||
<attr name="left_button_background_resource" format="reference" />
|
||||
<attr name="title" format="string" />
|
||||
<attr name="right_style" format="integer">
|
||||
<flag name="text" value="0" />
|
||||
<flag name="icon" value="1" />
|
||||
<flag name="button" value="2" />
|
||||
</attr>
|
||||
<attr name="right_text" format="string" />
|
||||
<attr name="right_text_color" format="color|reference" />
|
||||
<attr name="right_icon_resource" format="reference" />
|
||||
<attr name="right_icon_color" format="color|reference" />
|
||||
<attr name="right_button_background_resource" format="reference" />
|
||||
</declare-styleable>
|
||||
</resources>
|
||||
@ -200,6 +200,18 @@
|
||||
<item name="android:textStyle">bold</item>
|
||||
</style>
|
||||
|
||||
<!-- 正文3 -->
|
||||
<style name="TextBody3">
|
||||
<item name="android:textSize">13sp</item>
|
||||
<item name="android:textStyle">normal</item>
|
||||
</style>
|
||||
|
||||
<!-- 正文3 -->
|
||||
<style name="TextBody3B">
|
||||
<item name="android:textSize">13sp</item>
|
||||
<item name="android:textStyle">bold</item>
|
||||
</style>
|
||||
|
||||
<!-- 说明1 -->
|
||||
<style name="TextCaption1">
|
||||
<item name="android:textSize">12sp</item>
|
||||
|
||||
Reference in New Issue
Block a user