Fix grid spacing

This commit is contained in:
Koitharu
2021-01-24 09:02:17 +02:00
parent 5cbc592d23
commit 42f0fa9bbf
6 changed files with 15 additions and 26 deletions

View File

@@ -3,26 +3,16 @@ package org.koitharu.kotatsu.base.ui.list.decor
import android.graphics.Rect
import android.view.View
import androidx.annotation.Px
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
class SpacingItemDecoration(@Px private val spacing: Int) : RecyclerView.ItemDecoration() {
private val halfSpacing = spacing / 2
override fun getItemOffsets(
outRect: Rect,
view: View,
parent: RecyclerView,
state: RecyclerView.State
) {
val spans = (parent.layoutManager as? GridLayoutManager)?.spanCount ?: 1
val position = parent.getChildAdapterPosition(view)
outRect.set(
if (position % spans == 0) spacing else halfSpacing,
if (position < spans) spacing else halfSpacing,
if ((position + 1) % spans == 0) spacing else halfSpacing,
spacing //TODO check bottom
)
outRect.set(spacing, spacing, spacing, spacing)
}
}

View File

@@ -186,7 +186,7 @@ abstract class MangaListFragment : BaseFragment<FragmentListBinding>(),
@CallSuper
protected open fun onLoadingStateChanged(isLoading: Boolean) {
binding.swipeRefreshLayout.isEnabled = binding.swipeRefreshLayout.isRefreshing ||
isSwipeRefreshEnabled && !isLoading
isSwipeRefreshEnabled && !isLoading
if (!isLoading) {
binding.swipeRefreshLayout.isRefreshing = false
}
@@ -249,24 +249,21 @@ abstract class MangaListFragment : BaseFragment<FragmentListBinding>(),
RecyclerView.VERTICAL
)
)
updatePadding(left = 0, right = 0)
}
ListMode.DETAILED_LIST -> {
layoutManager = LinearLayoutManager(context)
addItemDecoration(
SpacingItemDecoration(
resources.getDimensionPixelOffset(R.dimen.grid_spacing)
)
)
val spacing = resources.getDimensionPixelOffset(R.dimen.grid_spacing)
updatePadding(left = spacing, right = spacing)
addItemDecoration(SpacingItemDecoration(spacing))
}
ListMode.GRID -> {
layoutManager = GridLayoutManager(context, spanResolver.spanCount).also {
it.spanSizeLookup = spanSizeLookup
}
addItemDecoration(
SpacingItemDecoration(
resources.getDimensionPixelOffset(R.dimen.grid_spacing)
)
)
val spacing = resources.getDimensionPixelOffset(R.dimen.grid_spacing)
addItemDecoration(SpacingItemDecoration(spacing))
updatePadding(left = spacing, right = spacing)
addOnLayoutChangeListener(spanResolver)
}
}

View File

@@ -19,7 +19,6 @@ import org.koitharu.kotatsu.databinding.SheetPagesBinding
import org.koitharu.kotatsu.list.ui.MangaListSpanResolver
import org.koitharu.kotatsu.reader.ui.thumbnails.adapter.PageThumbnailAdapter
import org.koitharu.kotatsu.utils.ext.mangaRepositoryOf
import org.koitharu.kotatsu.utils.ext.resolveDp
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
import org.koitharu.kotatsu.utils.ext.withArgs
@@ -55,7 +54,9 @@ class PagesThumbnailsSheet : BaseBottomSheet<SheetPagesBinding>(),
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
with(binding.recyclerView) {
addItemDecoration(SpacingItemDecoration(view.resources.resolveDp(8)))
addItemDecoration(
SpacingItemDecoration(view.resources.getDimensionPixelOffset(R.dimen.grid_spacing))
)
adapter = PageThumbnailAdapter(
thumbnails,
get(),

View File

@@ -44,6 +44,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:padding="@dimen/grid_spacing"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="3"
tools:listitem="@layout/item_page_thumb" />

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="grid_spacing">7dp</dimen>
<dimen name="grid_spacing">4dp</dimen>
<dimen name="preferred_grid_width">140dp</dimen>
</resources>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="grid_spacing">5dp</dimen>
<dimen name="grid_spacing">2dp</dimen>
<dimen name="manga_list_item_height">84dp</dimen>
<dimen name="manga_list_details_item_height">120dp</dimen>
<dimen name="chapter_list_item_height">46dp</dimen>