diff --git a/app/src/main/java/com/huanchengfly/tieba/post/Extensions.kt b/app/src/main/java/com/huanchengfly/tieba/post/Extensions.kt
index e0c0dabe..0ae4eb20 100644
--- a/app/src/main/java/com/huanchengfly/tieba/post/Extensions.kt
+++ b/app/src/main/java/com/huanchengfly/tieba/post/Extensions.kt
@@ -6,6 +6,7 @@ import android.content.Context
import android.content.Intent
import android.content.res.ColorStateList
import android.content.res.Configuration
+import android.content.res.Configuration.SCREENLAYOUT_SIZE_MASK
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
@@ -96,4 +97,10 @@ val Configuration.isPortrait: Boolean
get() = orientation == Configuration.ORIENTATION_PORTRAIT
val Configuration.isLandscape: Boolean
- get() = orientation == Configuration.ORIENTATION_LANDSCAPE
\ No newline at end of file
+ get() = orientation == Configuration.ORIENTATION_LANDSCAPE
+
+val Configuration.isTablet: Boolean
+ get() = (screenLayout and SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE
+
+val Context.isTablet: Boolean
+ get() = resources.configuration.isTablet
\ No newline at end of file
diff --git a/app/src/main/java/com/huanchengfly/tieba/post/activities/ForumActivity.kt b/app/src/main/java/com/huanchengfly/tieba/post/activities/ForumActivity.kt
index 33848849..1ce60c00 100644
--- a/app/src/main/java/com/huanchengfly/tieba/post/activities/ForumActivity.kt
+++ b/app/src/main/java/com/huanchengfly/tieba/post/activities/ForumActivity.kt
@@ -52,6 +52,7 @@ import com.huanchengfly.tieba.post.api.models.ForumPageBean
import com.huanchengfly.tieba.post.api.models.LikeForumResultBean
import com.huanchengfly.tieba.post.api.retrofit.doIfFailure
import com.huanchengfly.tieba.post.api.retrofit.doIfSuccess
+import com.huanchengfly.tieba.post.dpToPxFloat
import com.huanchengfly.tieba.post.fragments.ForumFragment
import com.huanchengfly.tieba.post.fragments.ForumFragment.OnRefreshedListener
import com.huanchengfly.tieba.post.goToActivity
@@ -59,6 +60,9 @@ import com.huanchengfly.tieba.post.interfaces.Refreshable
import com.huanchengfly.tieba.post.interfaces.ScrollTopable
import com.huanchengfly.tieba.post.models.PhotoViewBean
import com.huanchengfly.tieba.post.models.database.History
+import com.huanchengfly.tieba.post.ui.animation.addMaskAnimation
+import com.huanchengfly.tieba.post.ui.animation.addZoomAnimation
+import com.huanchengfly.tieba.post.ui.animation.buildPressAnimator
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils
import com.huanchengfly.tieba.post.utils.*
import com.huanchengfly.tieba.post.utils.ColorUtils.getDarkerColor
@@ -310,18 +314,28 @@ class ForumActivity : BaseActivity(), View.OnClickListener, OnRefreshedListener,
toolbar.setOnClickListener(this)
toolbarEndBtn.setOnClickListener(this)
fab.hide()
+ fab.rippleColor = Color.TRANSPARENT
fab.supportImageTintList = ColorStateList.valueOf(resources.getColor(R.color.white))
fab.setImageResource(when (appPreferences.forumFabFunction) {
"refresh" -> R.drawable.ic_round_refresh
"back_to_top" -> R.drawable.ic_round_vertical_align_top
else -> R.drawable.ic_round_create
- })
- fab.contentDescription = getString(when (appPreferences.forumFabFunction) {
- "refresh" -> R.string.btn_refresh
- "back_to_top" -> R.string.btn_back_to_top
- else -> R.string.btn_post
- })
+ }
+ )
+ fab.contentDescription = getString(
+ when (appPreferences.forumFabFunction) {
+ "refresh" -> R.string.btn_refresh
+ "back_to_top" -> R.string.btn_back_to_top
+ else -> R.string.btn_post
+ }
+ )
fab.setOnClickListener(this)
+ buildPressAnimator(fab) {
+ addZoomAnimation(0.1f)
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ addMaskAnimation(maskRadius = 50f.dpToPxFloat())
+ }
+ }.init()
}
override fun setTitle(newTitle: String?) {
diff --git a/app/src/main/java/com/huanchengfly/tieba/post/activities/MainActivity.kt b/app/src/main/java/com/huanchengfly/tieba/post/activities/MainActivity.kt
index cd6bfec5..1654d2ba 100644
--- a/app/src/main/java/com/huanchengfly/tieba/post/activities/MainActivity.kt
+++ b/app/src/main/java/com/huanchengfly/tieba/post/activities/MainActivity.kt
@@ -129,11 +129,16 @@ open class MainActivity : BaseActivity(), BottomNavigationView.OnNavigationItemS
mViewPager.offscreenPageLimit = mAdapter.count
}
- protected fun initListener() {
+ private fun initListener() {
mBottomNavigationView.setOnNavigationItemSelectedListener(this)
mBottomNavigationView.setOnNavigationItemReselectedListener(this)
mViewPager.addOnPageChangeListener(object : OnPageChangeListener {
- override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}
+ override fun onPageScrolled(
+ position: Int,
+ positionOffset: Float,
+ positionOffsetPixels: Int
+ ) {
+ }
@SuppressLint("RestrictedApi")
override fun onPageSelected(position: Int) {
diff --git a/app/src/main/java/com/huanchengfly/tieba/post/components/dividers/StaggeredDividerItemDecoration.java b/app/src/main/java/com/huanchengfly/tieba/post/components/dividers/StaggeredDividerItemDecoration.java
index 9847594b..9097afb7 100644
--- a/app/src/main/java/com/huanchengfly/tieba/post/components/dividers/StaggeredDividerItemDecoration.java
+++ b/app/src/main/java/com/huanchengfly/tieba/post/components/dividers/StaggeredDividerItemDecoration.java
@@ -23,12 +23,14 @@ public class StaggeredDividerItemDecoration extends RecyclerView.ItemDecoration
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
int position = parent.getChildAdapterPosition(view);
int interval = DisplayUtil.dp2px(context, this.interval);
+ StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) parent.getLayoutManager();
+ int spanCount = layoutManager.getSpanCount();
StaggeredGridLayoutManager.LayoutParams params =
(StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams();
/*
第一行设置上边距
*/
- if (position <= 1) {
+ if (position <= spanCount - 1) {
outRect.top = interval;
} else {
outRect.top = 0;
@@ -37,12 +39,15 @@ public class StaggeredDividerItemDecoration extends RecyclerView.ItemDecoration
根据params.getSpanIndex()来判断左右边确定分割线
第一列设置左边距为interval,右边距为interval/2 (第二列反之)
*/
- if (params.getSpanIndex() % 2 == 0) {
+ if (params.getSpanIndex() % spanCount == 0) {
outRect.left = interval;
outRect.right = interval / 2;
- } else {
+ } else if (params.getSpanIndex() % spanCount == spanCount - 1) {
outRect.left = interval / 2;
outRect.right = interval;
+ } else {
+ outRect.left = interval / 2;
+ outRect.right = interval / 2;
}
outRect.bottom = interval;
}
diff --git a/app/src/main/java/com/huanchengfly/tieba/post/utils/PostListAdapterHelper.kt b/app/src/main/java/com/huanchengfly/tieba/post/utils/PostListAdapterHelper.kt
index 275341b4..ff3a5870 100644
--- a/app/src/main/java/com/huanchengfly/tieba/post/utils/PostListAdapterHelper.kt
+++ b/app/src/main/java/com/huanchengfly/tieba/post/utils/PostListAdapterHelper.kt
@@ -22,6 +22,7 @@ import com.huanchengfly.tieba.post.components.spans.MyImageSpan
import com.huanchengfly.tieba.post.components.spans.MyURLSpan
import com.huanchengfly.tieba.post.components.spans.MyUserSpan
import com.huanchengfly.tieba.post.dpToPx
+import com.huanchengfly.tieba.post.isTablet
import com.huanchengfly.tieba.post.models.PhotoViewBean
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils
import com.huanchengfly.tieba.post.utils.BilibiliUtil.replaceVideoNumberSpan
@@ -31,6 +32,7 @@ import com.huanchengfly.tieba.post.widgets.VoicePlayerView
import com.huanchengfly.tieba.post.widgets.theme.TintMySpannableTextView
import java.util.*
import kotlin.collections.ArrayList
+import kotlin.math.roundToInt
class PostListAdapterHelper(
private val context: Context
@@ -142,6 +144,9 @@ class PostListAdapterHelper(
maxWidth =
BaseApplication.ScreenInfo.EXACT_SCREEN_WIDTH.toFloat() - (16 * 2 + 4).dpToPx()
}
+ if (context.isTablet) {
+ return maxWidth / 2;
+ }
return maxWidth
}
@@ -166,18 +171,25 @@ class PostListAdapterHelper(
heightFloat = java.lang.Float.valueOf(contentBean.height!!)
heightFloat *= widthFloat / width
}
- val width = Math.round(widthFloat)
- val height = Math.round(heightFloat)
+ val width = widthFloat.roundToInt()
+ val height = heightFloat.roundToInt()
val layoutParams = LinearLayout.LayoutParams(width, height)
- layoutParams.gravity = Gravity.CENTER_HORIZONTAL
- val dp16 = DisplayUtil.dp2px(context, 16f)
- val dp4 = DisplayUtil.dp2px(context, 4f)
- val dp2 = DisplayUtil.dp2px(context, 2f)
+ layoutParams.gravity = if (context.isTablet) {
+ Gravity.START
+ } else {
+ Gravity.CENTER_HORIZONTAL
+ }
+ val dp16 = 16f.dpToPx()
+ val dp4 = 4f.dpToPx()
+ val dp2 = 2f.dpToPx()
if ("1" == floor) {
layoutParams.setMargins(dp16, dp2, dp16, dp2)
} else {
layoutParams.setMargins(dp4, dp2, dp4, dp2)
}
+ if (context.isTablet) {
+ layoutParams.setMargins(0, dp2, 0, dp2)
+ }
return layoutParams
}
diff --git a/app/src/main/res/layout/activity_forum.xml b/app/src/main/res/layout/activity_forum.xml
index 3e44ed40..b99ddcd0 100644
--- a/app/src/main/res/layout/activity_forum.xml
+++ b/app/src/main/res/layout/activity_forum.xml
@@ -25,249 +25,12 @@
app:statusBarScrim="@color/transparent"
app:titleEnabled="false">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ layout="@layout/layout_forum_header" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file