diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 8247f0a0..1b3345f1 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -21,7 +21,7 @@ android { minSdk = 24 targetSdk = 34 versionCode = 10 - versionName = "1.1-beta03" + versionName = "1.1-beta04" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/java/com/skyd/anivu/ui/adapter/decoration/AniVuItemDecoration.kt b/app/src/main/java/com/skyd/anivu/ui/adapter/decoration/AniVuItemDecoration.kt index 8b6e8c6f..de710d2f 100644 --- a/app/src/main/java/com/skyd/anivu/ui/adapter/decoration/AniVuItemDecoration.kt +++ b/app/src/main/java/com/skyd/anivu/ui/adapter/decoration/AniVuItemDecoration.kt @@ -10,7 +10,10 @@ import com.skyd.anivu.ui.adapter.variety.VarietyAdapter import kotlin.math.roundToInt -class AniVuItemDecoration : RecyclerView.ItemDecoration() { +class AniVuItemDecoration( + private val hItemSpace: Int = H_ITEM_SPACE, + private val horizontalSpace: Int = HORIZONTAL_PADDING, +) : RecyclerView.ItemDecoration() { override fun getItemOffsets( outRect: Rect, view: View, @@ -27,45 +30,41 @@ class AniVuItemDecoration : RecyclerView.ItemDecoration() { // 注意这里使用getChildLayoutPosition的目的 // 如果使用getChildAdapterPosition,刷新的时候可能会(边框)闪动一下,(返回-1) ?.getOrNull(parent.getChildLayoutPosition(view)) - if (needVerticalMargin(item?.javaClass)) { - outRect.top = 10.dp - outRect.bottom = 2.dp - } if (spanSize == MAX_SPAN_SIZE) { /** * 只有一列 */ if (noHorizontalMargin(item?.javaClass)) return - outRect.left = HORIZONTAL_PADDING - outRect.right = HORIZONTAL_PADDING + outRect.left = horizontalSpace + outRect.right = horizontalSpace } else if (spanSize == MAX_SPAN_SIZE / 2) { /** * 只有两列,没有在中间的item - * 2x = ITEM_SPACING + * 2x = hItemSpace */ - val x: Int = (ITEM_SPACING / 2f).roundToInt() + val x: Int = (hItemSpace / 2f).roundToInt() if (spanIndex == 0) { - outRect.left = HORIZONTAL_PADDING + outRect.left = horizontalSpace outRect.right = x } else { outRect.left = x - outRect.right = HORIZONTAL_PADDING + outRect.right = horizontalSpace } } else if (spanSize == MAX_SPAN_SIZE / 3) { /** * 只有三列,一个在中间的item - * HORIZONTAL_PADDING + x = 2y - * x + y = ITEM_SPACING + * horizontalSpace + x = 2y + * x + y = hItemSpace */ - val y: Int = ((HORIZONTAL_PADDING + ITEM_SPACING) / 3f).roundToInt() - val x: Int = ITEM_SPACING - y + val y: Int = ((horizontalSpace + hItemSpace) / 3f).roundToInt() + val x: Int = hItemSpace - y if (spanIndex == 0) { - outRect.left = HORIZONTAL_PADDING + outRect.left = horizontalSpace outRect.right = x } else if (spanIndex + spanSize == MAX_SPAN_SIZE) { // 最右侧最后一个 outRect.left = x - outRect.right = HORIZONTAL_PADDING + outRect.right = horizontalSpace } else { outRect.left = y outRect.right = y @@ -73,21 +72,21 @@ class AniVuItemDecoration : RecyclerView.ItemDecoration() { } else if (spanSize == MAX_SPAN_SIZE / 5) { /** * 只有五列 - * HORIZONTAL_PADDING + x = y + z - * x + y = ITEM_SPACING - * z + (HORIZONTAL_PADDING + x) / 2 = ITEM_SPACING + * horizontalSpace + x = y + z + * x + y = hItemSpace + * z + (horizontalSpace + x) / 2 = hItemSpace */ - val x: Int = ((4 * ITEM_SPACING - 3 * HORIZONTAL_PADDING) / 5f).roundToInt() - val y: Int = ITEM_SPACING - x - val z: Int = HORIZONTAL_PADDING + x - y + val x: Int = ((4 * hItemSpace - 3 * horizontalSpace) / 5f).roundToInt() + val y: Int = hItemSpace - x + val z: Int = horizontalSpace + x - y if (spanIndex == 0) { // 最左侧第一个 - outRect.left = HORIZONTAL_PADDING + outRect.left = horizontalSpace outRect.right = x } else if (spanIndex + spanSize == MAX_SPAN_SIZE) { // 最右侧最后一个 outRect.left = x - outRect.right = HORIZONTAL_PADDING + outRect.right = horizontalSpace } else if (spanIndex == spanSize) { // 第二个 outRect.left = y @@ -98,8 +97,8 @@ class AniVuItemDecoration : RecyclerView.ItemDecoration() { outRect.right = y } else { // 最中间的 - outRect.left = ((HORIZONTAL_PADDING + x) / 2f).roundToInt() - outRect.right = ((HORIZONTAL_PADDING + x) / 2f).roundToInt() + outRect.left = ((horizontalSpace + x) / 2f).roundToInt() + outRect.right = ((horizontalSpace + x) / 2f).roundToInt() } } else { /** @@ -108,28 +107,28 @@ class AniVuItemDecoration : RecyclerView.ItemDecoration() { if ((MAX_SPAN_SIZE / spanSize) % 2 == 0) { /** * 偶数个item - * HORIZONTAL_PADDING + x = y + ITEM_SPACING / 2 - * x + y = ITEM_SPACING + * horizontalSpace + x = y + hItemSpace / 2 + * x + y = hItemSpace */ - val y: Int = ((HORIZONTAL_PADDING + ITEM_SPACING / 2f) / 2f).roundToInt() - val x: Int = ITEM_SPACING - y + val y: Int = ((horizontalSpace + hItemSpace / 2f) / 2f).roundToInt() + val x: Int = hItemSpace - y if (spanIndex == 0) { // 最左侧第一个 - outRect.left = HORIZONTAL_PADDING + outRect.left = horizontalSpace outRect.right = x } else if (spanIndex + spanSize == MAX_SPAN_SIZE) { // 最右侧最后一个 outRect.left = x - outRect.right = HORIZONTAL_PADDING + outRect.right = horizontalSpace } else { // 中间的项目 if (spanIndex < MAX_SPAN_SIZE / 2) { // 左侧部分 outRect.left = y - outRect.right = ITEM_SPACING / 2 + outRect.right = hItemSpace / 2 } else { // 右侧部分 - outRect.left = ITEM_SPACING / 2 + outRect.left = hItemSpace / 2 outRect.right = y } } @@ -142,8 +141,9 @@ class AniVuItemDecoration : RecyclerView.ItemDecoration() { } companion object { - val ITEM_SPACING: Int = 12.dp + val H_ITEM_SPACE: Int = 12.dp val HORIZONTAL_PADDING: Int = 16.dp + val VERTICAL_PADDING: Int = 16.dp private val noHorizontalMarginType: Set> = setOf( @@ -153,14 +153,5 @@ class AniVuItemDecoration : RecyclerView.ItemDecoration() { clz ?: return true return clz in noHorizontalMarginType } - - private val needVerticalMarginType: Set> = setOf( - - ) - - fun needVerticalMargin(clz: Class<*>?): Boolean { - clz ?: return false - return clz in needVerticalMarginType - } } } \ No newline at end of file diff --git a/app/src/main/java/com/skyd/anivu/ui/adapter/variety/AniSpanSize.kt b/app/src/main/java/com/skyd/anivu/ui/adapter/variety/AniSpanSize.kt index 01a7bfdf..0ef9b3ea 100644 --- a/app/src/main/java/com/skyd/anivu/ui/adapter/variety/AniSpanSize.kt +++ b/app/src/main/java/com/skyd/anivu/ui/adapter/variety/AniSpanSize.kt @@ -5,6 +5,7 @@ import com.skyd.anivu.appContext import com.skyd.anivu.ext.screenIsLand import com.skyd.anivu.model.bean.FeedBean import com.skyd.anivu.model.bean.MoreBean +import com.skyd.anivu.model.bean.OtherWorksBean class AniSpanSize( private val adapter: VarietyAdapter, @@ -18,6 +19,7 @@ class AniSpanSize( when (data) { is FeedBean -> MAX_SPAN_SIZE is MoreBean -> MAX_SPAN_SIZE / 3 + is OtherWorksBean -> MAX_SPAN_SIZE / 2 else -> MAX_SPAN_SIZE } } else { diff --git a/app/src/main/java/com/skyd/anivu/ui/fragment/MainFragment.kt b/app/src/main/java/com/skyd/anivu/ui/fragment/MainFragment.kt index 950ef3d9..4aa4f0b3 100644 --- a/app/src/main/java/com/skyd/anivu/ui/fragment/MainFragment.kt +++ b/app/src/main/java/com/skyd/anivu/ui/fragment/MainFragment.kt @@ -6,6 +6,7 @@ import android.view.View import android.view.ViewGroup import androidx.navigation.fragment.NavHostFragment import androidx.navigation.ui.setupWithNavController +import com.google.android.material.navigation.NavigationBarView import com.skyd.anivu.base.BaseFragment import com.skyd.anivu.databinding.FragmentMainBinding import dagger.hilt.android.AndroidEntryPoint @@ -21,6 +22,6 @@ class MainFragment : BaseFragment() { val navHostFragment = binding.navHostFragment.getFragment() val navController = navHostFragment.navController - binding.bottomNavigation.setupWithNavController(navController) + (binding.bottomNavigation as NavigationBarView).setupWithNavController(navController) } } \ No newline at end of file diff --git a/app/src/main/java/com/skyd/anivu/ui/fragment/about/AboutFragment.kt b/app/src/main/java/com/skyd/anivu/ui/fragment/about/AboutFragment.kt index fc026950..77452f96 100644 --- a/app/src/main/java/com/skyd/anivu/ui/fragment/about/AboutFragment.kt +++ b/app/src/main/java/com/skyd/anivu/ui/fragment/about/AboutFragment.kt @@ -18,6 +18,7 @@ import com.skyd.anivu.ext.getAppVersionName import com.skyd.anivu.ext.openBrowser import com.skyd.anivu.ext.popBackStackWithLifecycle import com.skyd.anivu.model.bean.OtherWorksBean +import com.skyd.anivu.ui.adapter.decoration.AniVuItemDecoration import com.skyd.anivu.ui.adapter.variety.AniSpanSize import com.skyd.anivu.ui.adapter.variety.VarietyAdapter import com.skyd.anivu.ui.adapter.variety.proxy.OtherWorks1Proxy @@ -96,6 +97,7 @@ class AboutFragment : BaseFragment() { ).apply { spanSizeLookup = AniSpanSize(adapter) } + rvAboutFragment.addItemDecoration(AniVuItemDecoration(hItemSpace = 20.dp)) rvAboutFragment.adapter = adapter } diff --git a/app/src/main/java/com/skyd/anivu/ui/fragment/feed/FeedFragment.kt b/app/src/main/java/com/skyd/anivu/ui/fragment/feed/FeedFragment.kt index 555b81f5..d71bd7f3 100644 --- a/app/src/main/java/com/skyd/anivu/ui/fragment/feed/FeedFragment.kt +++ b/app/src/main/java/com/skyd/anivu/ui/fragment/feed/FeedFragment.kt @@ -22,6 +22,7 @@ import com.skyd.anivu.ext.addInsetsByPadding import com.skyd.anivu.ext.collectIn import com.skyd.anivu.ext.findMainNavController import com.skyd.anivu.ext.gone +import com.skyd.anivu.ext.screenIsLand import com.skyd.anivu.ext.showSnackbar import com.skyd.anivu.ext.startWith import com.skyd.anivu.ui.adapter.variety.AniSpanSize @@ -199,10 +200,11 @@ class FeedFragment : BaseFragment() { } override fun FragmentFeedBinding.setWindowInsets() { - ablFeedFragment.addInsetsByPadding(top = true, left = true, right = true) - fabFeedFragment.addInsetsByMargin(left = true, right = true) + val isLand = requireContext().screenIsLand + ablFeedFragment.addInsetsByPadding(top = true, left = !isLand, right = true) + fabFeedFragment.addInsetsByMargin(left = !isLand, right = true) rvFeedFragment.addInsetsByPadding( - left = true, + left = !isLand, right = true, hook = ::addFabBottomPaddingHook, ) diff --git a/app/src/main/java/com/skyd/anivu/ui/fragment/media/MediaFragment.kt b/app/src/main/java/com/skyd/anivu/ui/fragment/media/MediaFragment.kt index e103d7a8..2efc3cb4 100644 --- a/app/src/main/java/com/skyd/anivu/ui/fragment/media/MediaFragment.kt +++ b/app/src/main/java/com/skyd/anivu/ui/fragment/media/MediaFragment.kt @@ -23,6 +23,7 @@ import com.skyd.anivu.ext.addInsetsByPadding import com.skyd.anivu.ext.collectIn import com.skyd.anivu.ext.findMainNavController import com.skyd.anivu.ext.popBackStackWithLifecycle +import com.skyd.anivu.ext.screenIsLand import com.skyd.anivu.ext.showSnackbar import com.skyd.anivu.ext.toUri import com.skyd.anivu.model.bean.ParentDirBean @@ -176,10 +177,11 @@ class MediaFragment : BaseFragment() { } override fun FragmentMediaBinding.setWindowInsets() { - ablMediaFragment.addInsetsByPadding(top = true, left = true, right = true) - fabMediaFragment.addInsetsByMargin(left = true, right = true, bottom = hasParentDir) + val leftPadding = hasParentDir || !requireContext().screenIsLand + ablMediaFragment.addInsetsByPadding(top = true, left = leftPadding, right = true) + fabMediaFragment.addInsetsByMargin(left = leftPadding, right = true, bottom = hasParentDir) rvMediaFragment.addInsetsByPadding( - left = true, + left = leftPadding, right = true, hook = ::addFabBottomPaddingHook, ) diff --git a/app/src/main/java/com/skyd/anivu/ui/fragment/more/MoreFragment.kt b/app/src/main/java/com/skyd/anivu/ui/fragment/more/MoreFragment.kt index 8bbf4cf1..aa4071ce 100644 --- a/app/src/main/java/com/skyd/anivu/ui/fragment/more/MoreFragment.kt +++ b/app/src/main/java/com/skyd/anivu/ui/fragment/more/MoreFragment.kt @@ -10,6 +10,7 @@ import com.skyd.anivu.base.BaseFragment import com.skyd.anivu.databinding.FragmentMoreBinding import com.skyd.anivu.ext.addInsetsByPadding import com.skyd.anivu.ext.findMainNavController +import com.skyd.anivu.ext.screenIsLand import com.skyd.anivu.model.bean.MoreBean import com.skyd.anivu.ui.adapter.decoration.AniVuItemDecoration import com.skyd.anivu.ui.adapter.variety.AniSpanSize @@ -43,8 +44,9 @@ class MoreFragment : BaseFragment() { } override fun FragmentMoreBinding.setWindowInsets() { - ablMoreFragment.addInsetsByPadding(top = true, left = true, right = true) - rvMoreFragment.addInsetsByPadding(left = true, right = true) + val isLand = requireContext().screenIsLand + ablMoreFragment.addInsetsByPadding(top = true, left = !isLand, right = true) + rvMoreFragment.addInsetsByPadding(left = !isLand, right = true) } private fun getMoreBeanList(): MutableList { diff --git a/app/src/main/res/layout-land/fragment_about.xml b/app/src/main/res/layout-land/fragment_about.xml new file mode 100644 index 00000000..b9d46098 --- /dev/null +++ b/app/src/main/res/layout-land/fragment_about.xml @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout-land/fragment_main.xml b/app/src/main/res/layout-land/fragment_main.xml new file mode 100644 index 00000000..7623984f --- /dev/null +++ b/app/src/main/res/layout-land/fragment_main.xml @@ -0,0 +1,24 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_about.xml b/app/src/main/res/layout/fragment_about.xml index 3a03a55f..43ecc171 100644 --- a/app/src/main/res/layout/fragment_about.xml +++ b/app/src/main/res/layout/fragment_about.xml @@ -165,8 +165,10 @@ android:id="@+id/rv_about_fragment" android:layout_width="match_parent" android:layout_height="wrap_content" + android:clipToPadding="false" android:descendantFocusability="blocksDescendants" - android:nestedScrollingEnabled="false" /> + android:nestedScrollingEnabled="false" + android:paddingVertical="3dp" /> \ No newline at end of file diff --git a/app/src/main/res/layout/item_other_works_1.xml b/app/src/main/res/layout/item_other_works_1.xml index fe282a19..fb09484b 100644 --- a/app/src/main/res/layout/item_other_works_1.xml +++ b/app/src/main/res/layout/item_other_works_1.xml @@ -4,7 +4,6 @@ style="?attr/materialCardViewFilledStyle" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginHorizontal="16dp" android:layout_marginVertical="10dp">