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" /> + +