Comfortable grid code cleanup

This commit is contained in:
arkon 2020-05-25 14:01:17 -04:00
parent 52e82b3548
commit 0af81c7d05
15 changed files with 92 additions and 105 deletions

View File

@ -73,7 +73,7 @@ object PreferenceKeys {
const val lastUsedCategory = "last_used_category"
const val catalogueDisplayMode = "pref_display_catalogue_display_mode"
const val catalogueDisplayMode = "pref_catalogue_display_mode"
const val enabledLanguages = "source_languages"
@ -131,7 +131,7 @@ object PreferenceKeys {
const val downloadNewCategories = "download_new_categories"
const val libraryDisplayMode = "pref_display_library_display_mode"
const val libraryDisplayMode = "pref_library_display_mode"
const val lang = "app_language"

View File

@ -16,7 +16,9 @@ object PreferenceValues {
const val THEME_DARK_BLUE = "blue"
const val THEME_DARK_AMOLED = "amoled"
const val DISPLAY_COMPACT_GRID = 0
const val DISPLAY_LIST = 1
const val DISPLAY_COMFORTABLE_GRID = 2
enum class DisplayMode(val value: Int) {
COMPACT_GRID(0),
COMFORTABLE_GRID(1),
LIST(2),
}
}

View File

@ -7,9 +7,9 @@ import androidx.preference.PreferenceManager
import com.tfcporciuncula.flow.FlowSharedPreferences
import com.tfcporciuncula.flow.Preference
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DISPLAY_COMPACT_GRID
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DisplayMode
import eu.kanade.tachiyomi.data.track.TrackService
import eu.kanade.tachiyomi.data.track.anilist.Anilist
import java.io.File
@ -139,7 +139,7 @@ class PreferencesHelper(val context: Context) {
fun lastVersionCode() = flowPrefs.getInt("last_version_code", 0)
fun catalogueDisplayMode() = flowPrefs.getInt(Keys.catalogueDisplayMode, DISPLAY_COMPACT_GRID)
fun catalogueDisplayMode() = flowPrefs.getInt(Keys.catalogueDisplayMode, DisplayMode.COMPACT_GRID.value)
fun enabledLanguages() = flowPrefs.getStringSet(Keys.enabledLanguages, setOf("en", Locale.getDefault().language))
@ -185,7 +185,7 @@ class PreferencesHelper(val context: Context) {
fun libraryUpdatePrioritization() = flowPrefs.getInt(Keys.libraryUpdatePrioritization, 0)
fun libraryDisplayMode() = flowPrefs.getInt(Keys.libraryDisplayMode, DISPLAY_COMPACT_GRID)
fun libraryDisplayMode() = flowPrefs.getInt(Keys.libraryDisplayMode, DisplayMode.COMPACT_GRID.value)
fun downloadBadge() = flowPrefs.getBoolean(Keys.downloadBadge, false)

View File

@ -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

View File

@ -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.

View File

@ -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")
}
}

View File

@ -12,7 +12,7 @@ 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.library.LibraryUpdateService
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.util.lang.plusAssign
import eu.kanade.tachiyomi.util.system.toast
@ -73,7 +73,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
fun onCreate(controller: LibraryController) {
this.controller = controller
recycler = if (preferences.libraryDisplayMode().get() == DISPLAY_LIST) {
recycler = if (preferences.libraryDisplayMode().get() == DisplayMode.LIST.value) {
(swipe_refresh.inflate(R.layout.library_list_recycler) as RecyclerView).apply {
layoutManager = LinearLayoutManager(context)
}

View File

@ -7,12 +7,12 @@ import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
import eu.kanade.tachiyomi.util.isLocal
import eu.kanade.tachiyomi.util.view.visibleIf
import kotlinx.android.synthetic.main.source_grid_item.card
import kotlinx.android.synthetic.main.source_grid_item.download_text
import kotlinx.android.synthetic.main.source_grid_item.local_text
import kotlinx.android.synthetic.main.source_grid_item.thumbnail
import kotlinx.android.synthetic.main.source_grid_item.title
import kotlinx.android.synthetic.main.source_grid_item.unread_text
import kotlinx.android.synthetic.main.source_compact_grid_item.card
import kotlinx.android.synthetic.main.source_compact_grid_item.download_text
import kotlinx.android.synthetic.main.source_compact_grid_item.local_text
import kotlinx.android.synthetic.main.source_compact_grid_item.thumbnail
import kotlinx.android.synthetic.main.source_compact_grid_item.title
import kotlinx.android.synthetic.main.source_compact_grid_item.unread_text
/**
* Class used to hold the displayed data of a manga in the library, like the cover or the title.

View File

@ -13,12 +13,11 @@ import eu.davidea.flexibleadapter.items.IFilterable
import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.LibraryManga
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.source.SourceManager
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
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
@ -32,17 +31,18 @@ class LibraryItem(val manga: LibraryManga, private val libraryDisplayMode: Prefe
override fun getLayoutRes(): Int {
return when (libraryDisplayMode.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")
}
}
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): LibraryHolder {
val parent = adapter.recyclerView
return if (parent is AutofitRecyclerView) {
val coverHeight = parent.itemWidth / 3 * 4
if (libraryDisplayMode.get() == DISPLAY_COMPACT_GRID) {
return when (libraryDisplayMode.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)
gradient.layoutParams = FrameLayout.LayoutParams(
@ -50,19 +50,21 @@ class LibraryItem(val manga: LibraryManga, private val libraryDisplayMode: Prefe
)
}
LibraryGridHolder(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
)
}
LibraryComfortableGridHolder(view, adapter)
}
} else {
LibraryListHolder(view, adapter)
DisplayMode.LIST.value -> {
LibraryListHolder(view, adapter)
}
else -> throw NotImplementedError("Unknown display mode")
}
}

View File

@ -5,9 +5,7 @@ import android.content.Context
import android.util.AttributeSet
import android.view.View
import eu.kanade.tachiyomi.R
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.widget.ExtendedNavigationView
import eu.kanade.tachiyomi.widget.TabbedBottomSheetDialog
@ -185,19 +183,19 @@ class LibrarySettingsSheet(
inner class DisplayGroup : Group {
private val grid = Item.Radio(R.string.action_display_grid, this)
private val compactGrid = Item.Radio(R.string.action_display_grid, this)
private val comfortableGrid = Item.Radio(R.string.action_display_comfortable_grid, this)
private val list = Item.Radio(R.string.action_display_list, this)
override val header = null
override val items = listOf(grid, comfortableGrid, list)
override val items = listOf(compactGrid, comfortableGrid, list)
override val footer = null
override fun initModels() {
val mode = preferences.libraryDisplayMode().get()
grid.checked = mode == DISPLAY_COMPACT_GRID
list.checked = mode == DISPLAY_LIST
comfortableGrid.checked = mode == DISPLAY_COMFORTABLE_GRID
compactGrid.checked = mode == DisplayMode.COMPACT_GRID.value
comfortableGrid.checked = mode == DisplayMode.COMFORTABLE_GRID.value
list.checked = mode == DisplayMode.LIST.value
}
override fun onItemClicked(item: Item) {
@ -209,9 +207,10 @@ class LibrarySettingsSheet(
preferences.libraryDisplayMode().set(
when (item) {
grid -> DISPLAY_COMPACT_GRID
list -> DISPLAY_LIST
else -> DISPLAY_COMFORTABLE_GRID
compactGrid -> DisplayMode.COMPACT_GRID.value
comfortableGrid -> DisplayMode.COMFORTABLE_GRID.value
list -> DisplayMode.LIST.value
else -> throw NotImplementedError("Unknown display mode")
}
)

View File

@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M4,14h4v-4L4,10v4zM4,19h4v-4L4,15v4zM4,9h4L8,5L4,5v4zM9,14h12v-4L9,10v4zM9,19h12v-4L9,15v4zM9,5v4h12L21,5L9,5z"/>
</vector>

View File

@ -11,4 +11,4 @@
android:paddingTop="5dp"
android:paddingEnd="5dp"
android:paddingBottom="@dimen/action_toolbar_list_padding"
tools:listitem="@layout/source_grid_item" />
tools:listitem="@layout/source_compact_grid_item" />

View File

@ -8,13 +8,12 @@
android:padding="4dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rounded_rectangle">
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/card"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="220dp"
android:background="@drawable/rounded_rectangle"
app:layout_constraintEnd_toEndOf="parent"
@ -29,13 +28,6 @@
tools:ignore="ContentDescription"
tools:src="@mipmap/ic_launcher" />
<View
android:id="@+id/gradient"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@drawable/gradient_shape" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -116,15 +108,16 @@
style="@style/TextAppearance.Regular.Body1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|start|end"
android:ellipsize="end"
android:fontFamily="@font/ptsans_narrow_bold"
android:lineSpacingExtra="-4dp"
android:maxLines="2"
android:padding="8dp"
android:padding="4dp"
android:shadowColor="@color/textColorPrimaryLight"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/card"
tools:text="Sample name" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
</FrameLayout>

View File

@ -8,4 +8,4 @@
android:clipToPadding="false"
android:columnWidth="140dp"
android:padding="5dp"
tools:listitem="@layout/source_grid_item" />
tools:listitem="@layout/source_compact_grid_item" />