From 11264dd98d45126d6f494f7e1008550ed4f4a238 Mon Sep 17 00:00:00 2001 From: HuanChengFly <609486518@qq.com> Date: Sat, 12 Jun 2021 22:06:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E4=BA=A4=E9=94=99=E6=95=88=E6=9E=9C=E5=BC=80?= =?UTF-8?q?=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/activities/NewSearchActivity.kt | 4 +-- .../post/adapters/MainForumListAdapter.kt | 10 ++++--- .../tieba/post/adapters/SearchForumAdapter.kt | 4 +-- .../tieba/post/adapters/SearchUserAdapter.kt | 4 +-- .../tieba/post/fragments/MyInfoFragment.kt | 14 ++++++++++ .../tieba/post/utils/AppPreferencesUtils.kt | 2 ++ .../huanchengfly/tieba/post/utils/utils.kt | 26 +++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/preferences.xml | 5 ++++ 9 files changed, 61 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/activities/NewSearchActivity.kt b/app/src/main/java/com/huanchengfly/tieba/post/activities/NewSearchActivity.kt index 4e47496f..5c4214a7 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/activities/NewSearchActivity.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/activities/NewSearchActivity.kt @@ -41,7 +41,7 @@ import com.huanchengfly.tieba.post.ui.theme.utils.ColorStateListUtils import com.huanchengfly.tieba.post.utils.AnimUtil import com.huanchengfly.tieba.post.utils.NavigationHelper import com.huanchengfly.tieba.post.utils.anim.animSet -import com.huanchengfly.tieba.post.utils.getItemBackgroundDrawable +import com.huanchengfly.tieba.post.utils.getIntermixedColorBackground import com.huanchengfly.tieba.post.widgets.MyViewPager import org.litepal.LitePal import retrofit2.Call @@ -321,7 +321,7 @@ class NewSearchActivity : BaseActivity(), TabLayout.OnTabSelectedListener { textView.setTextColor(context.getColorCompat(R.color.red_accent)) } viewHolder.setVisibility(R.id.hot_desc, View.GONE) - viewHolder.itemView.background = getItemBackgroundDrawable( + viewHolder.itemView.background = getIntermixedColorBackground( context, position, itemCount, diff --git a/app/src/main/java/com/huanchengfly/tieba/post/adapters/MainForumListAdapter.kt b/app/src/main/java/com/huanchengfly/tieba/post/adapters/MainForumListAdapter.kt index 6df7a8e8..6082157f 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/adapters/MainForumListAdapter.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/adapters/MainForumListAdapter.kt @@ -44,10 +44,14 @@ class MainForumListAdapter( getRadiusDrawable() } ) - if (position % 2 == 1) { - viewHolder.itemView.backgroundTintList = ColorStateListUtils.createColorStateList(context, R.color.default_color_card) + if (context.appPreferences.listItemsBackgroundIntermixed) { + if (position % 2 == 1) { + viewHolder.itemView.backgroundTintList = ColorStateListUtils.createColorStateList(context, R.color.default_color_card) + } else { + viewHolder.itemView.backgroundTintList = ColorStateListUtils.createColorStateList(context, R.color.default_color_divider) + } } else { - viewHolder.itemView.backgroundTintList = ColorStateListUtils.createColorStateList(context, R.color.default_color_divider) + viewHolder.itemView.backgroundTintList = ColorStateListUtils.createColorStateList(context, R.color.default_color_card) } } //双列左 diff --git a/app/src/main/java/com/huanchengfly/tieba/post/adapters/SearchForumAdapter.kt b/app/src/main/java/com/huanchengfly/tieba/post/adapters/SearchForumAdapter.kt index bc3eeba4..cd2f22a6 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/adapters/SearchForumAdapter.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/adapters/SearchForumAdapter.kt @@ -8,7 +8,7 @@ import com.huanchengfly.tieba.post.api.models.SearchForumBean import com.huanchengfly.tieba.post.api.models.SearchForumBean.ExactForumInfoBean import com.huanchengfly.tieba.post.components.MyViewHolder import com.huanchengfly.tieba.post.utils.ImageUtil -import com.huanchengfly.tieba.post.utils.getItemBackgroundDrawable +import com.huanchengfly.tieba.post.utils.getIntermixedColorBackground class SearchForumAdapter(context: Context?) : BaseMultiTypeDelegateAdapter(context!!, LinearLayoutHelper()) { override fun convert(viewHolder: MyViewHolder, item: SearchForumBean.ForumInfoBean, position: Int, viewType: Int) { @@ -18,7 +18,7 @@ class SearchForumAdapter(context: Context?) : BaseMultiTypeDelegateAdapter(it).apply { + backgroundTintList = if (appPreferences.listItemsBackgroundIntermixed) { + ColorStateListUtils.createColorStateList(attachContext, R.color.default_color_divider) + } else { + ColorStateListUtils.createColorStateList(attachContext, R.color.default_color_card) + } + } + } } override fun onClick(v: View) { diff --git a/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt b/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt index 9df2aedf..0818b798 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt @@ -38,6 +38,8 @@ open class AppPreferencesUtils(context: Context) { var imageLoadType by SharedPreferenceDelegates.string(key = "image_load_type", defaultValue = "0") + var listItemsBackgroundIntermixed by SharedPreferenceDelegates.boolean(defaultValue = true) + var listSingle by SharedPreferenceDelegates.boolean(defaultValue = false) var littleTail by SharedPreferenceDelegates.string(key = "little_tail") diff --git a/app/src/main/java/com/huanchengfly/tieba/post/utils/utils.kt b/app/src/main/java/com/huanchengfly/tieba/post/utils/utils.kt index 7774bdfc..73f31f7f 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/utils/utils.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/utils/utils.kt @@ -85,3 +85,29 @@ fun getRadiusDrawable( fun wrapRipple(rippleColor: Int, drawable: Drawable): Drawable { return RippleDrawable(ColorStateList.valueOf(rippleColor), drawable, drawable) } + + +@JvmOverloads +fun getIntermixedColorBackground( + context: Context, + position: Int, + itemCount: Int, + positionOffset: Int = 0, + radius: Float = 8f.dpToPxFloat(), + colors: IntArray = intArrayOf(R.color.default_color_card), + ripple: Boolean = true +): Drawable { + return getItemBackgroundDrawable( + context, + position, + itemCount, + positionOffset, + radius, + if (context.appPreferences.listItemsBackgroundIntermixed) { + colors + } else { + intArrayOf(colors[0]) + }, + ripple + ) +} \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b7191c21..529e7601 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -446,4 +446,5 @@ 正在获取吧列表 没有可签到的吧 关于本吧 + 列表背景颜色交错效果 diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 19bf2810..8f41c8ef 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -140,6 +140,11 @@ android:title="@string/settings_status_bar_darker" android:summary="@string/tip_status_bar_darker" /> + +