diff --git a/app/src/main/java/com/huanchengfly/tieba/post/BaseApplication.kt b/app/src/main/java/com/huanchengfly/tieba/post/BaseApplication.kt index cdddc335..65ce4b0a 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/BaseApplication.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/BaseApplication.kt @@ -27,7 +27,6 @@ import com.huanchengfly.tieba.post.utils.QuickPreviewUtil.getForumName import com.huanchengfly.tieba.post.utils.QuickPreviewUtil.getPreviewInfo import com.huanchengfly.tieba.post.utils.QuickPreviewUtil.isForumUrl import com.huanchengfly.tieba.post.utils.QuickPreviewUtil.isThreadUrl -import com.scwang.smart.refresh.layout.SmartRefreshLayout import org.intellij.lang.annotations.RegExp import org.litepal.LitePal import java.util.* @@ -171,9 +170,7 @@ class BaseApplication : Application() { override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {} override fun onActivityDestroyed(activity: Activity) {} }) - CrashUtil.CrashHandler.getInstance().init(this) - //CrashUtil.CrashHandler crashHandler = CrashUtil.CrashHandler.getInstance(); - //crashHandler.init(this); + //CrashUtil.CrashHandler.getInstance().init(this) } /** 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 ae0fb816..5539ce07 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 @@ -322,9 +322,9 @@ class NewSearchActivity : BaseActivity(), TabLayout.OnTabSelectedListener { position, itemCount, positionOffset = 1, + colors = intArrayOf(R.color.default_color_card, R.color.default_color_divider), radius = context.resources.getDimension(R.dimen.card_radius) ) - viewHolder.itemView.backgroundTintList = ColorStateListUtils.createColorStateList(context, R.color.default_color_card) } override fun getItemLayoutId(): Int { 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 cd6d7d0c..6df7a8e8 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 @@ -4,21 +4,24 @@ import android.content.Context import android.view.View import com.alibaba.android.vlayout.layout.GridLayoutHelper import com.huanchengfly.tieba.post.R -import com.huanchengfly.tieba.post.adapters.base.BaseSingleTypeDelegateAdapter +import com.huanchengfly.tieba.post.adapters.base.BaseMultiTypeDelegateAdapter import com.huanchengfly.tieba.post.api.models.ForumRecommend import com.huanchengfly.tieba.post.components.MyViewHolder import com.huanchengfly.tieba.post.dpToPx -import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils -import com.huanchengfly.tieba.post.utils.ImageUtil -import com.huanchengfly.tieba.post.utils.ThemeUtil -import com.huanchengfly.tieba.post.utils.getRadiusDrawable +import com.huanchengfly.tieba.post.ui.theme.utils.ColorStateListUtils +import com.huanchengfly.tieba.post.utils.* class MainForumListAdapter( context: Context, span: Int = 1 -) : BaseSingleTypeDelegateAdapter( +) : BaseMultiTypeDelegateAdapter( context, GridLayoutHelper(span) ) { + companion object { + const val TYPE_LIST = 1 + const val TYPE_GRID = 2 + } + var spanCount = span set(value) { field = value @@ -26,51 +29,58 @@ class MainForumListAdapter( notifyDataSetChanged() } - override fun getItemLayoutId(): Int = R.layout.item_forum_list + override fun getItemLayoutId(itemType: Int): Int = if (itemType == TYPE_LIST) R.layout.item_forum_list_single else R.layout.item_forum_list - override fun convert(viewHolder: MyViewHolder, item: ForumRecommend.LikeForum, position: Int) { - viewHolder.itemView.setBackgroundColor(ThemeUtils.getColorByAttr(context, R.attr.colorCard)) + override fun convert(viewHolder: MyViewHolder, item: ForumRecommend.LikeForum, position: Int, viewType: Int) { val cardRadius = context.resources.getDimension(R.dimen.card_radius) when { //单列 spanCount == 1 -> { - if (position == getCount() - 1) { - viewHolder.itemView.background = getRadiusDrawable(bottomLeftPx = cardRadius, bottomRightPx = cardRadius) + viewHolder.itemView.background = wrapRipple( + Util.getColorByAttr(context, R.attr.colorControlHighlight, R.color.transparent), + if (position == getCount() - 1) { + getRadiusDrawable(bottomLeftPx = cardRadius, bottomRightPx = cardRadius) + } else { + getRadiusDrawable() + } + ) + if (position % 2 == 1) { + viewHolder.itemView.backgroundTintList = ColorStateListUtils.createColorStateList(context, R.color.default_color_card) } else { - viewHolder.itemView.background = getRadiusDrawable() + viewHolder.itemView.backgroundTintList = ColorStateListUtils.createColorStateList(context, R.color.default_color_divider) } } //双列左 position % spanCount == 0 -> { - when (position) { - //最后一行,左 - getCount() - 2 -> { - viewHolder.itemView.background = getRadiusDrawable(bottomLeftPx = cardRadius) - } - //最后一项 - getCount() - 1 -> { - viewHolder.itemView.background = getRadiusDrawable(bottomLeftPx = cardRadius, bottomRightPx = cardRadius) - } - //其他 - else -> { - viewHolder.itemView.background = getRadiusDrawable() - } - } + viewHolder.itemView.backgroundTintList = ColorStateListUtils.createColorStateList(context, R.color.default_color_card) + viewHolder.itemView.background = wrapRipple( + Util.getColorByAttr(context, R.attr.colorControlHighlight, R.color.transparent), + when (position) { + //最后一行,左 + getCount() - 2 -> getRadiusDrawable(bottomLeftPx = cardRadius) + //最后一项 + getCount() - 1 -> getRadiusDrawable(bottomLeftPx = cardRadius, bottomRightPx = cardRadius) + //其他 + else -> getRadiusDrawable() + } + ) } //双列右 else -> { - if (position == getCount() - 1) { - viewHolder.itemView.background = getRadiusDrawable(bottomRightPx = cardRadius) - } else { - viewHolder.itemView.background = getRadiusDrawable() - } + viewHolder.itemView.backgroundTintList = ColorStateListUtils.createColorStateList(context, R.color.default_color_card) + viewHolder.itemView.background = wrapRipple( + Util.getColorByAttr(context, R.attr.colorControlHighlight, R.color.transparent), + if (position == getCount() - 1) { + getRadiusDrawable(bottomRightPx = cardRadius) + } else { + getRadiusDrawable() + } + ) } } if (spanCount > 1) { - viewHolder.setVisibility(R.id.forum_list_item_avatar, View.GONE) ImageUtil.clear(viewHolder.getView(R.id.forum_list_item_avatar)) } else { - viewHolder.setVisibility(R.id.forum_list_item_avatar, View.VISIBLE) ImageUtil.load(viewHolder.getView(R.id.forum_list_item_avatar), ImageUtil.LOAD_TYPE_AVATAR, item.avatar) } ThemeUtil.setChipThemeByLevel(item.levelId, @@ -82,4 +92,8 @@ class MainForumListAdapter( viewHolder.setVisibility(R.id.forum_list_item_sign_status, if ("1" == item.isSign) View.VISIBLE else View.GONE) viewHolder.getView(R.id.forum_list_item_status).minimumWidth = (if ("1" == item.isSign) 50 else 32).dpToPx() } + + override fun getViewType(position: Int, item: ForumRecommend.LikeForum): Int { + return if (spanCount == 1) TYPE_LIST else TYPE_GRID + } } \ No newline at end of file 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 0fcc4e53..bc3eeba4 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 @@ -23,6 +23,7 @@ class SearchForumAdapter(context: Context?) : BaseMultiTypeDelegateAdapter - if (hasFocus) { - v.clearFocus() - attachContext.goToActivity() - } + searchBar.setOnClickListener { + attachContext.goToActivity() } btnOkSign.setOnClickListener { TiebaUtil.startSign(attachContext) 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 102ca097..db54d435 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 @@ -7,6 +7,7 @@ import android.graphics.drawable.Drawable import android.graphics.drawable.GradientDrawable import android.graphics.drawable.RippleDrawable import com.huanchengfly.tieba.post.R +import com.huanchengfly.tieba.post.ui.theme.utils.ColorStateListUtils @JvmOverloads fun getItemBackgroundDrawable( @@ -15,12 +16,13 @@ fun getItemBackgroundDrawable( itemCount: Int, positionOffset: Int = 0, radius: Float = 10f, + colors: IntArray = intArrayOf(R.color.default_color_card), ripple: Boolean = true ): Drawable { val realPos = position + positionOffset val maxPos = itemCount - 1 + positionOffset val shape = GradientDrawable().apply { - color = ColorStateList.valueOf(Color.WHITE) + color = ColorStateListUtils.createColorStateList(context, colors[realPos % colors.size]) if (realPos == 0 && realPos == maxPos) { cornerRadius = radius } else if (realPos == 0) { @@ -44,8 +46,7 @@ fun getItemBackgroundDrawable( } } return if (ripple) { - val rippleColor = ColorStateList.valueOf(Util.getColorByAttr(context, R.attr.colorControlHighlight, R.color.transparent)) - RippleDrawable(rippleColor, shape, shape) + wrapRipple(Util.getColorByAttr(context, R.attr.colorControlHighlight, R.color.transparent), shape) } else { shape } @@ -55,7 +56,8 @@ fun getRadiusDrawable( topLeftPx: Float = 0f, topRightPx: Float = 0f, bottomLeftPx: Float = 0f, - bottomRightPx: Float = 0f + bottomRightPx: Float = 0f, + ripple: Boolean = false ): Drawable { return GradientDrawable().apply { color = ColorStateList.valueOf(Color.WHITE) @@ -67,3 +69,7 @@ fun getRadiusDrawable( ) } } + +fun wrapRipple(rippleColor: Int, drawable: Drawable): Drawable { + return RippleDrawable(ColorStateList.valueOf(rippleColor), drawable, drawable) +} diff --git a/app/src/main/res/drawable/bg_bottom_radius_10dp_ripple.xml b/app/src/main/res/drawable/bg_bottom_radius_10dp_ripple.xml new file mode 100644 index 00000000..673e77f2 --- /dev/null +++ b/app/src/main/res/drawable/bg_bottom_radius_10dp_ripple.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_top_radius_10dp.xml b/app/src/main/res/drawable/bg_top_radius_10dp.xml new file mode 100644 index 00000000..df219526 --- /dev/null +++ b/app/src/main/res/drawable/bg_top_radius_10dp.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_top_radius_10dp_ripple.xml b/app/src/main/res/drawable/bg_top_radius_10dp_ripple.xml new file mode 100644 index 00000000..e9364594 --- /dev/null +++ b/app/src/main/res/drawable/bg_top_radius_10dp_ripple.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_main_forum_list.xml b/app/src/main/res/layout/fragment_main_forum_list.xml index 5fd43353..d2e22363 100644 --- a/app/src/main/res/layout/fragment_main_forum_list.xml +++ b/app/src/main/res/layout/fragment_main_forum_list.xml @@ -38,33 +38,33 @@ android:layout_height="wrap_content" app:layoutDescription="@xml/fragment_main_forum_list_scene"> - + android:layout_height="wrap_content" + android:orientation="horizontal" + android:id="@+id/search_bar"> - + + - + android:layout_gravity="center_vertical" + android:text="@string/hint_search" /> + - - - + - - + - - + - - - + + - - - + - - - + + diff --git a/app/src/main/res/layout/item_forum_list.xml b/app/src/main/res/layout/item_forum_list.xml index 37422d8c..f101b033 100644 --- a/app/src/main/res/layout/item_forum_list.xml +++ b/app/src/main/res/layout/item_forum_list.xml @@ -4,7 +4,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" xmlns:app="http://schemas.android.com/apk/res-auto" - android:foreground="?attr/selectableItemBackground" app:backgroundTint="@color/default_color_card" android:paddingStart="@dimen/padding_start_default" android:paddingEnd="@dimen/padding_end_default" diff --git a/app/src/main/res/layout/item_forum_list_single.xml b/app/src/main/res/layout/item_forum_list_single.xml new file mode 100644 index 00000000..b6185f3c --- /dev/null +++ b/app/src/main/res/layout/item_forum_list_single.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_search_forum.xml b/app/src/main/res/layout/item_search_forum.xml index 3b4c0f2c..9e886caf 100644 --- a/app/src/main/res/layout/item_search_forum.xml +++ b/app/src/main/res/layout/item_search_forum.xml @@ -1,6 +1,5 @@ - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/item_search_forum_exact.xml b/app/src/main/res/layout/item_search_forum_exact.xml index 2e762a88..aa1f0a01 100644 --- a/app/src/main/res/layout/item_search_forum_exact.xml +++ b/app/src/main/res/layout/item_search_forum_exact.xml @@ -1,9 +1,7 @@ - @@ -36,4 +34,4 @@ app:tint="@color/default_color_text_secondary" android:textSize="13sp" tools:text="Sub Title" /> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/item_search_user.xml b/app/src/main/res/layout/item_search_user.xml index 1d378631..8f447469 100644 --- a/app/src/main/res/layout/item_search_user.xml +++ b/app/src/main/res/layout/item_search_user.xml @@ -1,11 +1,9 @@ - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 9b2f7373..bd4eec37 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -58,7 +58,7 @@ #FF4477E0 #FFF0F3F5 #FFFFFFFF - #FFF0F3F5 + #FFF7FBFE #FEE9E9E9 #FF545967 #FFFFFFFF @@ -152,7 +152,7 @@ #FF252525 #FF1C1C1C - @color/color_divider + #FFF7FBFE #10FFFFFF #15000000 #FF10171D @@ -164,7 +164,7 @@ #FFC51100 - #FFF0F3F5 + #FFF7FBFE #ffffff #FF3373EE diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 04e9d2bb..6b6b05e2 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -14,7 +14,7 @@ 16sp 14sp 14sp - 36dp + 42dp 36dp 8dp 16dp