From 7fbe32d2afbf0cbe23c22dc132d90454a180fc0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E5=AD=90=E7=BB=B4?= Date: Mon, 5 Dec 2022 13:53:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E3=80=90=E5=85=89=E7=8E=AF=E5=8A=A9?= =?UTF-8?q?=E6=89=8BV5.17.0=E3=80=91=E6=B8=B8=E6=88=8F=E5=88=97=E8=A1=A8-?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=E5=8D=A1=E7=89=87=E6=98=BE=E7=A4=BA=E4=BC=98?= =?UTF-8?q?=E5=8C=96=20https://jira.shanqu.cc/browse/GHZS-372?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gh/common/databind/BindingAdapters.java | 3 +- .../common/view/NoEllipsizeSpaceTextView.kt | 38 +++++++++++++++++++ .../adapter/viewholder/GameViewHolder.java | 3 +- .../gh/gamecenter/game/vertical/GameItemUi.kt | 5 ++- .../main/res/layout/amway_comment_item.xml | 2 +- .../main/res/layout/category_game_item.xml | 2 +- .../main/res/layout/discovery_game_item.xml | 2 +- app/src/main/res/layout/game_attach_item.xml | 2 +- app/src/main/res/layout/game_item.xml | 2 +- app/src/main/res/layout/game_test_item.xml | 2 +- app/src/main/res/layout/home_amway_item.xml | 2 +- app/src/main/res/layout/home_game_item.xml | 2 +- .../item_game_detail_related_version.xml | 2 +- .../layout/item_vgame_download_manager.xml | 2 +- app/src/main/res/layout/libao_item.xml | 2 +- .../main/res/layout/libaodetail_item_top.xml | 2 +- app/src/main/res/layout/news_digest_item.xml | 2 +- 17 files changed, 58 insertions(+), 17 deletions(-) create mode 100644 app/src/main/java/com/gh/common/view/NoEllipsizeSpaceTextView.kt diff --git a/app/src/main/java/com/gh/common/databind/BindingAdapters.java b/app/src/main/java/com/gh/common/databind/BindingAdapters.java index 1ec5e3cf25..7dfbeb6d43 100644 --- a/app/src/main/java/com/gh/common/databind/BindingAdapters.java +++ b/app/src/main/java/com/gh/common/databind/BindingAdapters.java @@ -50,6 +50,7 @@ import com.gh.common.util.PlatformUtils; import com.gh.common.util.ReservationHelper; import com.gh.common.view.DownloadButton; import com.gh.common.view.GameIconView; +import com.gh.common.view.NoEllipsizeSpaceTextView; import com.gh.download.DownloadManager; import com.gh.download.dialog.DownloadDialog; import com.gh.gamecenter.DownloadManagerActivity; @@ -784,7 +785,7 @@ public class BindingAdapters { } } - public static void setGameName(TextView view, GameEntity game, boolean isShowPlatform, @Nullable Boolean isShowSuffix) { + public static void setGameName(NoEllipsizeSpaceTextView view, GameEntity game, boolean isShowPlatform, @Nullable Boolean isShowSuffix) { if (isShowSuffix == null) isShowSuffix = true; // 默认显示 if (isShowPlatform && game.getApk().size() > 0) { view.setText(String.format("%s - %s", !isShowSuffix ? game.getNameWithoutSuffix() : game.getName(), diff --git a/app/src/main/java/com/gh/common/view/NoEllipsizeSpaceTextView.kt b/app/src/main/java/com/gh/common/view/NoEllipsizeSpaceTextView.kt new file mode 100644 index 0000000000..d46b1ede37 --- /dev/null +++ b/app/src/main/java/com/gh/common/view/NoEllipsizeSpaceTextView.kt @@ -0,0 +1,38 @@ +package com.gh.common.view + +import android.content.Context +import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatTextView + +/** + * 去除省略号后面空白的TextView + */ +class NoEllipsizeSpaceTextView @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : + AppCompatTextView(context, attrs, defStyleAttr) { + override fun setText(text: CharSequence?, type: BufferType?) { + super.setText(text, type) + post { + if (layout != null) { + val rawText = layout.text.toString() + if (rawText.contains(ELLIPSIS_NORMAL)) { + val index = rawText.indexOf(ELLIPSIS_BLANK) + var trimText = rawText + if (index > 0) { + trimText = rawText.substring(0, index) + } + trimText = rawText.substring(0, trimText.length - 1) + ELLIPSIS_NORMAL + setText(trimText) + } + } + } + } + + companion object { + private const val ELLIPSIS_NORMAL = "\u2026" // 省略号字符(...) + private const val ELLIPSIS_BLANK = "\uFEFF" // 空白字符 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameViewHolder.java b/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameViewHolder.java index 348772b08c..7da9515237 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameViewHolder.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameViewHolder.java @@ -13,6 +13,7 @@ import com.airbnb.lottie.LottieAnimationView; import com.facebook.drawee.view.SimpleDraweeView; import com.gh.common.view.DownloadButton; import com.gh.common.view.GameIconView; +import com.gh.common.view.NoEllipsizeSpaceTextView; import com.gh.gamecenter.R; import com.gh.gamecenter.common.utils.ExtensionsKt; import com.gh.gamecenter.common.view.DrawableView; @@ -23,7 +24,7 @@ import com.gh.gamecenter.entity.GameEntity; public class GameViewHolder extends RecyclerView.ViewHolder { public GameIconView gameThumb; - public TextView gameName; + public NoEllipsizeSpaceTextView gameName; public DownloadButton gameDownloadBtn; public TextView gameDes; public LinearLayout gameLabelList; diff --git a/app/src/main/java/com/gh/gamecenter/game/vertical/GameItemUi.kt b/app/src/main/java/com/gh/gamecenter/game/vertical/GameItemUi.kt index eca68f1207..c7e48cf73a 100644 --- a/app/src/main/java/com/gh/gamecenter/game/vertical/GameItemUi.kt +++ b/app/src/main/java/com/gh/gamecenter/game/vertical/GameItemUi.kt @@ -18,6 +18,7 @@ import com.airbnb.lottie.LottieDrawable import com.facebook.drawee.view.SimpleDraweeView import com.gh.common.view.DownloadButton import com.gh.common.view.GameIconView +import com.gh.common.view.NoEllipsizeSpaceTextView import com.gh.gamecenter.R import com.gh.gamecenter.common.utils.setDrawableEnd import com.gh.gamecenter.common.view.GameTagContainerView @@ -45,7 +46,7 @@ import splitties.views.startPadding class GameItemUi(override val ctx: Context) : Ui { var iconIv: GameIconView - var gameNameTv: TextView + var gameNameTv: NoEllipsizeSpaceTextView var gameSubtitleTv: TextView var adLabelTv: TextView var downloadTv: DownloadButton @@ -182,7 +183,7 @@ class GameItemUi(override val ctx: Context) : Ui { } } - private fun initGameNameTv() = textView { + private fun initGameNameTv() = NoEllipsizeSpaceTextView(ctx).apply { id = R.id.game_name setSingleLine() includeFontPadding = false diff --git a/app/src/main/res/layout/amway_comment_item.xml b/app/src/main/res/layout/amway_comment_item.xml index 7fb486518a..7f9c0eb504 100644 --- a/app/src/main/res/layout/amway_comment_item.xml +++ b/app/src/main/res/layout/amway_comment_item.xml @@ -36,7 +36,7 @@ app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toTopOf="parent" /> - - - - - - - - - - - - -