Comfortable Grid (#3238)
* Comfortable Grid * Add requested changes * Add more requested changes
This commit is contained in:
@@ -12,6 +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.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.util.lang.plusAssign
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
@@ -72,7 +73,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
||||
fun onCreate(controller: LibraryController) {
|
||||
this.controller = controller
|
||||
|
||||
recycler = if (preferences.libraryAsList().get()) {
|
||||
recycler = if (preferences.libraryDisplayMode().get() == DISPLAY_LIST) {
|
||||
(swipe_refresh.inflate(R.layout.library_list_recycler) as RecyclerView).apply {
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package eu.kanade.tachiyomi.ui.library
|
||||
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.davidea.flexibleadapter.items.IFlexible
|
||||
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_comfortable_grid_item.card
|
||||
import kotlinx.android.synthetic.main.source_comfortable_grid_item.download_text
|
||||
import kotlinx.android.synthetic.main.source_comfortable_grid_item.local_text
|
||||
import kotlinx.android.synthetic.main.source_comfortable_grid_item.thumbnail
|
||||
import kotlinx.android.synthetic.main.source_comfortable_grid_item.title
|
||||
import kotlinx.android.synthetic.main.source_comfortable_grid_item.unread_text
|
||||
|
||||
/**
|
||||
* Class used to hold the displayed data of a manga in the library, like the cover or the title.
|
||||
* All the elements from the layout file "item_source_grid" are available in this class.
|
||||
*
|
||||
* @param view the inflated view for this holder.
|
||||
* @param adapter the adapter handling this holder.
|
||||
* @param listener a listener to react to single tap and long tap events.
|
||||
* @constructor creates a new library holder.
|
||||
*/
|
||||
class LibraryComfortableGridHolder(
|
||||
private val view: View,
|
||||
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>
|
||||
) : LibraryGridHolder(view, adapter) {
|
||||
|
||||
/**
|
||||
* Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this
|
||||
* holder with the given manga.
|
||||
*
|
||||
* @param item the manga item to bind.
|
||||
*/
|
||||
override fun onSetValues(item: LibraryItem) {
|
||||
// Update the title of the manga.
|
||||
title.text = item.manga.title
|
||||
|
||||
// Update the unread count and its visibility.
|
||||
with(unread_text) {
|
||||
visibleIf { item.unreadCount > 0 }
|
||||
text = item.unreadCount.toString()
|
||||
}
|
||||
// Update the download count and its visibility.
|
||||
with(download_text) {
|
||||
visibleIf { item.downloadCount > 0 }
|
||||
text = item.downloadCount.toString()
|
||||
}
|
||||
// set local visibility if its local manga
|
||||
local_text.visibleIf { item.manga.isLocal() }
|
||||
|
||||
// Setting this via XML doesn't work
|
||||
card.clipToOutline = true
|
||||
|
||||
// Update the cover.
|
||||
GlideApp.with(view.context).clear(thumbnail)
|
||||
GlideApp.with(view.context)
|
||||
.load(item.manga.toMangaThumbnail())
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||
.centerCrop()
|
||||
.dontAnimate()
|
||||
.into(thumbnail)
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ import kotlinx.android.synthetic.main.source_grid_item.unread_text
|
||||
* @param listener a listener to react to single tap and long tap events.
|
||||
* @constructor creates a new library holder.
|
||||
*/
|
||||
class LibraryGridHolder(
|
||||
open class LibraryGridHolder(
|
||||
private val view: View,
|
||||
private val adapter: FlexibleAdapter<*>
|
||||
) : LibraryHolder(view, adapter) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
||||
import android.widget.FrameLayout
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.tfcporciuncula.flow.Preference
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
@@ -12,6 +13,8 @@ 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.source.SourceManager
|
||||
import eu.kanade.tachiyomi.widget.AutofitRecyclerView
|
||||
import kotlinx.android.synthetic.main.source_grid_item.view.card
|
||||
@@ -19,7 +22,7 @@ import kotlinx.android.synthetic.main.source_grid_item.view.gradient
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference<Boolean>) :
|
||||
class LibraryItem(val manga: LibraryManga, private val libraryDisplayMode: Preference<Int>) :
|
||||
AbstractFlexibleItem<LibraryHolder>(), IFilterable<String> {
|
||||
|
||||
private val sourceManager: SourceManager = Injekt.get()
|
||||
@@ -28,24 +31,36 @@ class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference
|
||||
var unreadCount = -1
|
||||
|
||||
override fun getLayoutRes(): Int {
|
||||
return if (libraryAsList.get()) {
|
||||
R.layout.source_list_item
|
||||
} else {
|
||||
R.layout.source_grid_item
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): LibraryHolder {
|
||||
val parent = adapter.recyclerView
|
||||
return if (parent is AutofitRecyclerView) {
|
||||
view.apply {
|
||||
val coverHeight = parent.itemWidth / 3 * 4
|
||||
card.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, coverHeight)
|
||||
gradient.layoutParams = FrameLayout.LayoutParams(
|
||||
MATCH_PARENT, coverHeight / 2, Gravity.BOTTOM
|
||||
)
|
||||
val coverHeight = parent.itemWidth / 3 * 4
|
||||
if (libraryDisplayMode.get() == DISPLAY_COMPACT_GRID) {
|
||||
view.apply {
|
||||
card.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, coverHeight)
|
||||
gradient.layoutParams = FrameLayout.LayoutParams(
|
||||
MATCH_PARENT, coverHeight / 2, Gravity.BOTTOM
|
||||
)
|
||||
}
|
||||
LibraryGridHolder(view, adapter)
|
||||
} else {
|
||||
view.apply {
|
||||
card.layoutParams = ConstraintLayout.LayoutParams(
|
||||
MATCH_PARENT, coverHeight
|
||||
)
|
||||
gradient.layoutParams = FrameLayout.LayoutParams(
|
||||
MATCH_PARENT, coverHeight / 2, Gravity.BOTTOM
|
||||
)
|
||||
}
|
||||
LibraryComfortableGridHolder(view, adapter)
|
||||
}
|
||||
LibraryGridHolder(view, adapter)
|
||||
} else {
|
||||
LibraryListHolder(view, adapter)
|
||||
}
|
||||
|
||||
@@ -266,10 +266,10 @@ class LibraryPresenter(
|
||||
* value.
|
||||
*/
|
||||
private fun getLibraryMangasObservable(): Observable<LibraryMap> {
|
||||
val libraryAsList = preferences.libraryAsList()
|
||||
val libraryDisplayMode = preferences.libraryDisplayMode()
|
||||
return db.getLibraryMangas().asRxObservable()
|
||||
.map { list ->
|
||||
list.map { LibraryItem(it, libraryAsList) }.groupBy { it.manga.category }
|
||||
list.map { LibraryItem(it, libraryDisplayMode) }.groupBy { it.manga.category }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,9 @@ 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.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.widget.ExtendedNavigationView
|
||||
import eu.kanade.tachiyomi.widget.TabbedBottomSheetDialog
|
||||
@@ -183,16 +186,18 @@ class LibrarySettingsSheet(
|
||||
inner class DisplayGroup : Group {
|
||||
|
||||
private val grid = 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, list)
|
||||
override val items = listOf(grid, comfortableGrid, list)
|
||||
override val footer = null
|
||||
|
||||
override fun initModels() {
|
||||
val asList = preferences.libraryAsList().get()
|
||||
grid.checked = !asList
|
||||
list.checked = asList
|
||||
val mode = preferences.libraryDisplayMode().get()
|
||||
grid.checked = mode == DISPLAY_COMPACT_GRID
|
||||
list.checked = mode == DISPLAY_LIST
|
||||
comfortableGrid.checked = mode == DISPLAY_COMFORTABLE_GRID
|
||||
}
|
||||
|
||||
override fun onItemClicked(item: Item) {
|
||||
@@ -202,7 +207,13 @@ class LibrarySettingsSheet(
|
||||
item.group.items.forEach { (it as Item.Radio).checked = false }
|
||||
item.checked = true
|
||||
|
||||
preferences.libraryAsList().set(item == list)
|
||||
preferences.libraryDisplayMode().set(
|
||||
when (item) {
|
||||
grid -> DISPLAY_COMPACT_GRID
|
||||
list -> DISPLAY_LIST
|
||||
else -> DISPLAY_COMFORTABLE_GRID
|
||||
}
|
||||
)
|
||||
|
||||
item.group.items.forEach { adapter.notifyItemChanged(it) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user