Comfortable grid code cleanup
This commit is contained in:
+13
-15
@@ -22,9 +22,7 @@ import eu.davidea.flexibleadapter.items.IFlexible
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Category
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DISPLAY_COMFORTABLE_GRID
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DISPLAY_COMPACT_GRID
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DISPLAY_LIST
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DisplayMode
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
|
||||
import eu.kanade.tachiyomi.databinding.SourceControllerBinding
|
||||
@@ -190,7 +188,7 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||
binding.catalogueView.removeView(oldRecycler)
|
||||
}
|
||||
|
||||
val recycler = if (preferences.catalogueDisplayMode().get() == DISPLAY_LIST) {
|
||||
val recycler = if (preferences.catalogueDisplayMode().get() == DisplayMode.LIST.value) {
|
||||
RecyclerView(view.context).apply {
|
||||
id = R.id.recycler
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
@@ -208,7 +206,7 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||
(layoutManager as GridLayoutManager).spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
|
||||
override fun getSpanSize(position: Int): Int {
|
||||
return when (adapter?.getItemViewType(position)) {
|
||||
R.layout.source_grid_item, R.layout.source_comfortable_grid_item, null -> 1
|
||||
R.layout.source_compact_grid_item, R.layout.source_comfortable_grid_item, null -> 1
|
||||
else -> spanCount
|
||||
}
|
||||
}
|
||||
@@ -270,10 +268,10 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||
)
|
||||
|
||||
val displayItem = when (preferences.catalogueDisplayMode().get()) {
|
||||
DISPLAY_COMPACT_GRID -> R.id.action_compact_grid
|
||||
DISPLAY_LIST -> R.id.action_list
|
||||
DISPLAY_COMFORTABLE_GRID -> R.id.action_comfortable_grid
|
||||
else -> throw NotImplementedError("Unimplemented display")
|
||||
DisplayMode.COMPACT_GRID.value -> R.id.action_compact_grid
|
||||
DisplayMode.COMFORTABLE_GRID.value -> R.id.action_comfortable_grid
|
||||
DisplayMode.LIST.value -> R.id.action_list
|
||||
else -> throw NotImplementedError("Unknown display mode")
|
||||
}
|
||||
menu.findItem(displayItem).isChecked = true
|
||||
}
|
||||
@@ -291,9 +289,9 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.action_search -> expandActionViewFromInteraction = true
|
||||
R.id.action_compact_grid -> setDisplayMode(DISPLAY_COMPACT_GRID)
|
||||
R.id.action_list -> setDisplayMode(DISPLAY_LIST)
|
||||
R.id.action_comfortable_grid -> setDisplayMode(DISPLAY_COMFORTABLE_GRID)
|
||||
R.id.action_compact_grid -> setDisplayMode(DisplayMode.COMPACT_GRID)
|
||||
R.id.action_comfortable_grid -> setDisplayMode(DisplayMode.COMFORTABLE_GRID)
|
||||
R.id.action_list -> setDisplayMode(DisplayMode.LIST)
|
||||
R.id.action_open_in_web_view -> openInWebView()
|
||||
R.id.action_local_source_help -> openLocalSourceHelpGuide()
|
||||
}
|
||||
@@ -440,15 +438,15 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||
*
|
||||
* @param mode the mode to change to
|
||||
*/
|
||||
private fun setDisplayMode(mode: Int) {
|
||||
private fun setDisplayMode(mode: DisplayMode) {
|
||||
val view = view ?: return
|
||||
val adapter = adapter ?: return
|
||||
|
||||
preferences.catalogueDisplayMode().set(mode)
|
||||
preferences.catalogueDisplayMode().set(mode.value)
|
||||
presenter.refreshDisplayMode()
|
||||
activity?.invalidateOptionsMenu()
|
||||
setupRecycler(view)
|
||||
if (mode == DISPLAY_LIST || !view.context.connectivityManager.isActiveNetworkMetered) {
|
||||
if (mode == DisplayMode.LIST || !view.context.connectivityManager.isActiveNetworkMetered) {
|
||||
// Initialize mangas if going to grid view or if over wifi when going to list view
|
||||
val mangas = (0 until adapter.itemCount).mapNotNull {
|
||||
(adapter.getItem(it) as? SourceItem)?.manga
|
||||
|
||||
@@ -7,10 +7,10 @@ import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.glide.GlideApp
|
||||
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
|
||||
import eu.kanade.tachiyomi.widget.StateImageViewTarget
|
||||
import kotlinx.android.synthetic.main.source_grid_item.card
|
||||
import kotlinx.android.synthetic.main.source_grid_item.progress
|
||||
import kotlinx.android.synthetic.main.source_grid_item.thumbnail
|
||||
import kotlinx.android.synthetic.main.source_grid_item.title
|
||||
import kotlinx.android.synthetic.main.source_compact_grid_item.card
|
||||
import kotlinx.android.synthetic.main.source_compact_grid_item.progress
|
||||
import kotlinx.android.synthetic.main.source_compact_grid_item.thumbnail
|
||||
import kotlinx.android.synthetic.main.source_compact_grid_item.title
|
||||
|
||||
/**
|
||||
* Class used to hold the displayed data of a manga in the catalogue, like the cover or the title.
|
||||
|
||||
@@ -12,20 +12,20 @@ import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
||||
import eu.davidea.flexibleadapter.items.IFlexible
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DISPLAY_COMPACT_GRID
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DISPLAY_LIST
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DisplayMode
|
||||
import eu.kanade.tachiyomi.widget.AutofitRecyclerView
|
||||
import kotlinx.android.synthetic.main.source_grid_item.view.card
|
||||
import kotlinx.android.synthetic.main.source_grid_item.view.gradient
|
||||
import kotlinx.android.synthetic.main.source_compact_grid_item.view.card
|
||||
import kotlinx.android.synthetic.main.source_compact_grid_item.view.gradient
|
||||
|
||||
class SourceItem(val manga: Manga, private val catalogueDisplayMode: Preference<Int>) :
|
||||
AbstractFlexibleItem<SourceHolder>() {
|
||||
|
||||
override fun getLayoutRes(): Int {
|
||||
return when (catalogueDisplayMode.get()) {
|
||||
DISPLAY_COMPACT_GRID -> R.layout.source_grid_item
|
||||
DISPLAY_LIST -> R.layout.source_list_item
|
||||
else -> R.layout.source_comfortable_grid_item
|
||||
DisplayMode.COMPACT_GRID.value -> R.layout.source_compact_grid_item
|
||||
DisplayMode.COMFORTABLE_GRID.value -> R.layout.source_comfortable_grid_item
|
||||
DisplayMode.LIST.value -> R.layout.source_list_item
|
||||
else -> throw NotImplementedError("Unknown display mode")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ class SourceItem(val manga: Manga, private val catalogueDisplayMode: Preference<
|
||||
view: View,
|
||||
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>
|
||||
): SourceHolder {
|
||||
val parent = adapter.recyclerView
|
||||
return if (parent is AutofitRecyclerView) {
|
||||
val coverHeight = parent.itemWidth / 3 * 4
|
||||
if (catalogueDisplayMode.get() == DISPLAY_COMPACT_GRID) {
|
||||
return when (catalogueDisplayMode.get()) {
|
||||
DisplayMode.COMPACT_GRID.value -> {
|
||||
val parent = adapter.recyclerView as AutofitRecyclerView
|
||||
val coverHeight = parent.itemWidth / 3 * 4
|
||||
view.apply {
|
||||
card.layoutParams = FrameLayout.LayoutParams(
|
||||
MATCH_PARENT, coverHeight
|
||||
@@ -46,19 +46,21 @@ class SourceItem(val manga: Manga, private val catalogueDisplayMode: Preference<
|
||||
)
|
||||
}
|
||||
SourceGridHolder(view, adapter)
|
||||
} else {
|
||||
}
|
||||
DisplayMode.COMFORTABLE_GRID.value -> {
|
||||
val parent = adapter.recyclerView as AutofitRecyclerView
|
||||
val coverHeight = parent.itemWidth / 3 * 4
|
||||
view.apply {
|
||||
card.layoutParams = ConstraintLayout.LayoutParams(
|
||||
MATCH_PARENT, coverHeight
|
||||
)
|
||||
gradient.layoutParams = FrameLayout.LayoutParams(
|
||||
MATCH_PARENT, coverHeight / 2, Gravity.BOTTOM
|
||||
)
|
||||
}
|
||||
SourceComfortableGridHolder(view, adapter)
|
||||
}
|
||||
} else {
|
||||
SourceListHolder(view, adapter)
|
||||
DisplayMode.LIST.value -> {
|
||||
SourceListHolder(view, adapter)
|
||||
}
|
||||
else -> throw NotImplementedError("Unknown display mode")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user