mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 11:17:25 +01:00
Remove extra padding when using list with Per Category setting (#5997)
* Remove padding when using list with Per Category setting (fixes #5636) * Add view type to RecyclerViewPagerAdapter Correctly this time (ノ◕ヮ◕)ノ*:・゚✧ * Minor tweaks
This commit is contained in:
parent
cc1a317439
commit
372e500590
@ -6,6 +6,7 @@ import android.view.ViewGroup
|
|||||||
import eu.kanade.tachiyomi.data.database.models.Category
|
import eu.kanade.tachiyomi.data.database.models.Category
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.databinding.LibraryCategoryBinding
|
import eu.kanade.tachiyomi.databinding.LibraryCategoryBinding
|
||||||
|
import eu.kanade.tachiyomi.ui.library.setting.DisplayModeSetting
|
||||||
import eu.kanade.tachiyomi.widget.RecyclerViewPagerAdapter
|
import eu.kanade.tachiyomi.widget.RecyclerViewPagerAdapter
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
@ -45,15 +46,18 @@ class LibraryAdapter(
|
|||||||
|
|
||||||
private var boundViews = arrayListOf<View>()
|
private var boundViews = arrayListOf<View>()
|
||||||
|
|
||||||
|
private val isPerCategory by lazy { preferences.categorisedDisplaySettings().get() }
|
||||||
|
private val currentDisplayMode by lazy { preferences.libraryDisplayMode().get() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new view for this adapter.
|
* Creates a new view for this adapter.
|
||||||
*
|
*
|
||||||
* @return a new view.
|
* @return a new view.
|
||||||
*/
|
*/
|
||||||
override fun createView(container: ViewGroup): View {
|
override fun inflateView(container: ViewGroup, viewType: Int): View {
|
||||||
val binding = LibraryCategoryBinding.inflate(LayoutInflater.from(container.context), container, false)
|
val binding = LibraryCategoryBinding.inflate(LayoutInflater.from(container.context), container, false)
|
||||||
val view: LibraryCategoryView = binding.root
|
val view: LibraryCategoryView = binding.root
|
||||||
view.onCreate(controller, binding)
|
view.onCreate(controller, binding, viewType)
|
||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,4 +124,26 @@ class LibraryAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getViewType(position: Int): Int {
|
||||||
|
val category = categories[position]
|
||||||
|
return if (isPerCategory && category.id != 0) {
|
||||||
|
if (DisplayModeSetting.fromFlag(category.displayMode) == DisplayModeSetting.LIST) {
|
||||||
|
LIST_DISPLAY_MODE
|
||||||
|
} else {
|
||||||
|
GRID_DISPLAY_MODE
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (currentDisplayMode == DisplayModeSetting.LIST) {
|
||||||
|
LIST_DISPLAY_MODE
|
||||||
|
} else {
|
||||||
|
GRID_DISPLAY_MODE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val LIST_DISPLAY_MODE = 1
|
||||||
|
const val GRID_DISPLAY_MODE = 2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,14 +5,14 @@ import android.util.AttributeSet
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import dev.chrisbanes.insetter.applyInsetter
|
import dev.chrisbanes.insetter.Insetter
|
||||||
|
import dev.chrisbanes.insetter.windowInsetTypesOf
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
import eu.davidea.flexibleadapter.SelectableAdapter
|
import eu.davidea.flexibleadapter.SelectableAdapter
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.database.models.Category
|
import eu.kanade.tachiyomi.data.database.models.Category
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
|
||||||
import eu.kanade.tachiyomi.databinding.LibraryCategoryBinding
|
import eu.kanade.tachiyomi.databinding.LibraryCategoryBinding
|
||||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||||
import eu.kanade.tachiyomi.util.lang.plusAssign
|
import eu.kanade.tachiyomi.util.lang.plusAssign
|
||||||
@ -27,9 +27,7 @@ import kotlinx.coroutines.flow.onEach
|
|||||||
import reactivecircus.flowbinding.recyclerview.scrollStateChanges
|
import reactivecircus.flowbinding.recyclerview.scrollStateChanges
|
||||||
import reactivecircus.flowbinding.swiperefreshlayout.refreshes
|
import reactivecircus.flowbinding.swiperefreshlayout.refreshes
|
||||||
import rx.subscriptions.CompositeSubscription
|
import rx.subscriptions.CompositeSubscription
|
||||||
import uy.kohesive.injekt.injectLazy
|
|
||||||
import java.util.ArrayDeque
|
import java.util.ArrayDeque
|
||||||
import eu.kanade.tachiyomi.ui.library.setting.DisplayModeSetting as DisplayMode
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fragment containing the library manga for a certain category.
|
* Fragment containing the library manga for a certain category.
|
||||||
@ -41,8 +39,6 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
|
|
||||||
private val scope = MainScope()
|
private val scope = MainScope()
|
||||||
|
|
||||||
private val preferences: PreferencesHelper by injectLazy()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The fragment containing this view.
|
* The fragment containing this view.
|
||||||
*/
|
*/
|
||||||
@ -71,12 +67,10 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
|
|
||||||
private var lastClickPositionStack = ArrayDeque(listOf(-1))
|
private var lastClickPositionStack = ArrayDeque(listOf(-1))
|
||||||
|
|
||||||
fun onCreate(controller: LibraryController, binding: LibraryCategoryBinding) {
|
fun onCreate(controller: LibraryController, binding: LibraryCategoryBinding, viewType: Int) {
|
||||||
this.controller = controller
|
this.controller = controller
|
||||||
|
|
||||||
recycler = if (preferences.libraryDisplayMode().get() == DisplayMode.LIST &&
|
recycler = if (viewType == LibraryAdapter.LIST_DISPLAY_MODE) {
|
||||||
!preferences.categorisedDisplaySettings().get()
|
|
||||||
) {
|
|
||||||
(binding.swipeRefresh.inflate(R.layout.library_list_recycler) as AutofitRecyclerView).apply {
|
(binding.swipeRefresh.inflate(R.layout.library_list_recycler) as AutofitRecyclerView).apply {
|
||||||
spanCount = 1
|
spanCount = 1
|
||||||
}
|
}
|
||||||
@ -86,11 +80,9 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
recycler.applyInsetter {
|
Insetter.builder()
|
||||||
type(navigationBars = true) {
|
.paddingBottom(windowInsetTypesOf(navigationBars = true))
|
||||||
padding()
|
.applyToView(recycler)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
adapter = LibraryCategoryAdapter(this)
|
adapter = LibraryCategoryAdapter(this)
|
||||||
|
|
||||||
@ -129,15 +121,6 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
fun onBind(category: Category) {
|
fun onBind(category: Category) {
|
||||||
this.category = category
|
this.category = category
|
||||||
|
|
||||||
// If displayMode should be set from category adjust manga count per row
|
|
||||||
if (preferences.categorisedDisplaySettings().get()) {
|
|
||||||
recycler.spanCount = if (DisplayMode.fromFlag(category.displayMode) == DisplayMode.LIST || (preferences.libraryDisplayMode().get() == DisplayMode.LIST && category.id == 0)) {
|
|
||||||
1
|
|
||||||
} else {
|
|
||||||
controller.mangaPerRow
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
adapter.mode = if (controller.selectedMangas.isNotEmpty()) {
|
adapter.mode = if (controller.selectedMangas.isNotEmpty()) {
|
||||||
SelectableAdapter.Mode.MULTI
|
SelectableAdapter.Mode.MULTI
|
||||||
} else {
|
} else {
|
||||||
|
@ -8,7 +8,7 @@ import java.util.Stack
|
|||||||
|
|
||||||
abstract class RecyclerViewPagerAdapter : ViewStatePagerAdapter() {
|
abstract class RecyclerViewPagerAdapter : ViewStatePagerAdapter() {
|
||||||
|
|
||||||
private val pool = Stack<View>()
|
private val pool = HashMap<Int, Stack<View>>()
|
||||||
|
|
||||||
var recycle = true
|
var recycle = true
|
||||||
set(value) {
|
set(value) {
|
||||||
@ -16,17 +16,20 @@ abstract class RecyclerViewPagerAdapter : ViewStatePagerAdapter() {
|
|||||||
field = value
|
field = value
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract fun createView(container: ViewGroup): View
|
protected abstract fun getViewType(position: Int): Int
|
||||||
|
|
||||||
|
protected abstract fun inflateView(container: ViewGroup, viewType: Int): View
|
||||||
|
|
||||||
protected abstract fun bindView(view: View, position: Int)
|
protected abstract fun bindView(view: View, position: Int)
|
||||||
|
|
||||||
protected open fun recycleView(view: View, position: Int) {}
|
protected open fun recycleView(view: View, position: Int) {}
|
||||||
|
|
||||||
override fun createView(container: ViewGroup, position: Int): View {
|
override fun createView(container: ViewGroup, position: Int): View {
|
||||||
val view = if (pool.isNotEmpty()) {
|
val viewType = getViewType(position)
|
||||||
pool.pop().setViewPagerPositionParam(position)
|
val view = if (pool[viewType] != null && pool[viewType]!!.isNotEmpty()) {
|
||||||
|
pool[viewType]!!.pop().setViewPagerPositionParam(position)
|
||||||
} else {
|
} else {
|
||||||
createView(container)
|
inflateView(container, viewType)
|
||||||
}
|
}
|
||||||
bindView(view, position)
|
bindView(view, position)
|
||||||
return view
|
return view
|
||||||
@ -34,7 +37,9 @@ abstract class RecyclerViewPagerAdapter : ViewStatePagerAdapter() {
|
|||||||
|
|
||||||
override fun destroyView(container: ViewGroup, position: Int, view: View) {
|
override fun destroyView(container: ViewGroup, position: Int, view: View) {
|
||||||
recycleView(view, position)
|
recycleView(view, position)
|
||||||
if (recycle) pool.push(view)
|
val viewType = getViewType(position)
|
||||||
|
if (pool[viewType] == null) pool[viewType] = Stack<View>()
|
||||||
|
if (recycle) pool[viewType]!!.push(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user