Fixed bug with uniform gird

Also fixed search text being cleared
This commit is contained in:
Jay 2020-03-05 01:12:01 -08:00
parent 96d322afbe
commit c62ec99aff
8 changed files with 48 additions and 86 deletions

View File

@ -5,6 +5,7 @@ import android.view.View
import android.widget.FrameLayout
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.signature.ObjectKey
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.database.models.MangaImpl
import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.util.view.gone
@ -66,15 +67,28 @@ class LibraryGridHolder(
if (item.manga.thumbnail_url == null) GlideApp.with(view.context).clear(cover_thumbnail)
else {
val id = item.manga.id ?: return
var glide = GlideApp.with(adapter.recyclerView.context).load(item.manga)
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.signature(ObjectKey(MangaImpl.getLastCoverFetch(id).toString()))
glide = if (fixedSize) glide.centerCrop().override(cover_thumbnail.maxHeight)
else glide.override(cover_thumbnail.maxHeight)
glide.into(cover_thumbnail)
if (cover_thumbnail.height == 0) {
val oldPos = adapterPosition
adapter.recyclerView.post {
if (oldPos == adapterPosition)
setCover(item.manga, id)
}
}
else setCover(item.manga, id)
}
}
private fun setCover(manga: Manga, id: Long) {
GlideApp.with(adapter.recyclerView.context).load(manga)
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.signature(ObjectKey(MangaImpl.getLastCoverFetch(id).toString()))
.apply {
if (fixedSize) centerCrop()
else override(cover_thumbnail.maxHeight)
}
.into(cover_thumbnail)
}
private fun playButtonClicked() {
adapter.libraryListener.startReading(adapterPosition)
}

View File

@ -22,7 +22,6 @@ import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.view.updateLayoutParams
import eu.kanade.tachiyomi.widget.AutofitRecyclerView
import kotlinx.android.synthetic.main.catalogue_grid_item.view.*
import timber.log.Timber
import uy.kohesive.injekt.injectLazy
class LibraryItem(val manga: LibraryManga,
@ -71,8 +70,8 @@ class LibraryItem(val manga: LibraryManga,
constraint_layout.layoutParams = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT
)
cover_thumbnail.maxHeight = (parent.itemWidth / 3f * 3.7f).toInt()
cover_thumbnail.minimumHeight = (parent.itemWidth / 3f * 3.7f).toInt()
cover_thumbnail.maxHeight = Int.MAX_VALUE
cover_thumbnail.minimumHeight = 0
constraint_layout.minHeight = 0
cover_thumbnail.scaleType = ImageView.ScaleType.CENTER_CROP
cover_thumbnail.adjustViewBounds = false

View File

@ -96,31 +96,14 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
activeCategory = order
val category = presenter.categories.find { it.order == order }
//val categortPosition = presenter.categories.indexOf(category)
customTitleSpinner.category_title.text = category?.name ?: ""
/*if (spinner.selectedItemPosition != categortPosition) {
updateScroll = true
spinner.setSelection(categortPosition, true)
}*/
}
}
}
override fun onViewCreated(view: View) {
super.onViewCreated(view)
/*launchUI {
view.updateLayoutParams<FrameLayout.LayoutParams> {
val attrsArray = intArrayOf(android.R.attr.actionBarSize)
val array = view.context.obtainStyledAttributes(attrsArray)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
topMargin =
view.rootWindowInsets.systemWindowInsetTop + array.getDimensionPixelSize(
0, 0
)
}
array.recycle()
}
}*/
// pad the recycler if the filter bottom sheet is visible
if (!phoneLandscape) {
val height = view.context.resources.getDimensionPixelSize(R.dimen.rounder_radius) + 4.dpToPx
@ -135,19 +118,6 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
override fun layoutView(view: View) {
adapter = LibraryCategoryAdapter(this)
/* recycler =
(library_layout.inflate(R.layout.library_grid_recycler) as AutofitRecyclerView).apply {
spanCount = if (libraryLayout == 0) 1 else mangaPerRow
manager.spanSizeLookup = (object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
if (libraryLayout == 0) return 1
val item = this@LibraryListController.adapter.getItem(position)
return if (item is LibraryHeaderItem) manager.spanCount else 1
}
})
}*/
//recycler.spanCount = if (libraryLayout == 0) 1 else mangaPerRow
if (libraryLayout == 0)recycler.spanCount = 1
else recycler.columnWidth = (90 + (preferences.gridSize().getOrDefault() * 30)).dpToPx
recycler.manager.spanSizeLookup = (object : GridLayoutManager.SpanSizeLookup() {
@ -159,22 +129,12 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
})
recycler.setHasFixedSize(true)
recycler.adapter = adapter
//recycler_layout.addView(recycler)
adapter.fastScroller = fast_scroller
recycler.addOnScrollListener(scrollListener)
/* val dropdown = library_layout.inflate(R.layout.expanded_dropdown_menu) as
TextInputLayout // ReSpinner(view .context)
spinner = dropdown.filled_exposed_dropdown*/
val tv = TypedValue()
activity!!.theme.resolveAttribute(R.attr.actionBarTintColor, tv, true)
/*spinner.backgroundTintList = ContextCompat.getColorStateList(
view.context, tv.resourceId
)
(spinner.parent.parent as ViewGroup).removeView(spinner.parent as View)
(activity as MainActivity).supportActionBar?.customView = spinner.parent as View*/
customTitleSpinner = library_layout.inflate(R.layout.spinner_title) as LinearLayout
(activity as MainActivity).supportActionBar?.setDisplayShowCustomEnabled(false)
spinnerAdapter = SpinnerAdapter(
@ -192,9 +152,6 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
true
}
(activity as MainActivity).supportActionBar?.customView = customTitleSpinner
//spinnerAdapter?.setDropDownViewResource(R.layout.library_spinner_entry_text)
//spinner.setAdapter(spinnerAdapter)
// spinner.adapter = spinnerAdapter
}
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
@ -230,15 +187,11 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
}
adapter.setItems(mangaMap)
//spinner.onItemSelectedListener = null
val categoryNames = presenter.categories.map { it.name }.toTypedArray()
spinnerAdapter = SpinnerAdapter(recyclerLayout.context, R.layout.library_spinner_textview,
if (categoryNames.isNotEmpty()) categoryNames
else arrayOf(recyclerLayout.context.getString(R.string.label_library))
)
//spinnerAdapter?.setDropDownViewResource(R.layout.library_spinner_entry_text)
//spinner.setAdapter(spinnerAdapter)
val isCurrentController = router?.backstack?.lastOrNull()?.controller() ==
this
@ -246,7 +199,6 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
?.setDisplayShowCustomEnabled(isCurrentController && presenter.categories.size > 1)
if (isCurrentController) setTitle()
//spinner.setSelection(min(presenter.categories.size - 1, activeCategory))
customTitleSpinner.category_title.text =
presenter.categories[clamp(activeCategory,
0,
@ -265,7 +217,6 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
updateScroll = true
}
adapter.isLongPressDragEnabled = canDrag()
//tabsVisibilityRelay.call(false)
titlePopupMenu.menu.clear()
presenter.categories.forEach { category ->
@ -275,13 +226,6 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
titlePopupMenu.show()
}
/*spinner.onItemSelectedListener = IgnoreFirstSpinnerListener { pos ->
if (updateScroll) {
updateScroll = false
return@IgnoreFirstSpinnerListener
}
scrollToHeader(presenter.categories[pos].order)
}*/
}
private fun scrollToHeader(pos: Int, fade:Boolean = false) {

View File

@ -507,7 +507,7 @@ class LibraryPresenter(
suspend fun updateView(categories: List<Category>, mangaMap: LibraryMap, freshStart:Boolean
= false) {
if (!preferences.libraryAsSingleList().getOrDefault()) {
if (view !is LibraryListController) {
view.onNextLibraryUpdate(categories, mangaMap, freshStart)
}
else {
@ -536,7 +536,7 @@ class LibraryPresenter(
fun updateViewBlocking() {
val mangaMap = currentMangaMap ?: return
if (!preferences.libraryAsSingleList().getOrDefault()) {
if (view !is LibraryListController) {
if (mangaMap.values.firstOrNull()?.firstOrNull()?.header != null)
return
view.onNextLibraryUpdate(categories, mangaMap, true)

View File

@ -161,7 +161,7 @@ class MangaDetailsController : BaseController,
DividerItemDecoration.VERTICAL
)
)
recycler.setHasFixedSize(true)
recycler.setHasFixedSize(false)
adapter?.fastScroller = fast_scroller
val attrsArray = intArrayOf(android.R.attr.actionBarSize)
val array = view.context.obtainStyledAttributes(attrsArray)
@ -290,6 +290,7 @@ class MangaDetailsController : BaseController,
else if (type == ControllerChangeType.PUSH_EXIT || type == ControllerChangeType.POP_EXIT) {
if (router.backstack.lastOrNull()?.controller() is DialogController)
return
if (type == ControllerChangeType.POP_EXIT) setHasOptionsMenu(false)
colorAnimator?.cancel()
(activity as MainActivity).toolbar.setBackgroundColor(activity?.getResourceColor(
@ -333,17 +334,10 @@ class MangaDetailsController : BaseController,
fun refreshAdapter() = adapter?.notifyDataSetChanged()
override fun onItemClick(view: View?, position: Int): Boolean {
val adapter = adapter ?: return false
val chapter = adapter.getItem(position)?.chapter ?: return false
val chapter = adapter?.getItem(position)?.chapter ?: return false
if (chapter.isHeader) return false
/*if (actionMode != null && adapter.mode == SelectableAdapter.Mode.MULTI) {
lastClickPosition = position
toggleSelection(position)
return true
} else {*/
openChapter(chapter)
return false
//}
openChapter(chapter)
return false
}
override fun onItemLongClick(position: Int) {

View File

@ -208,6 +208,19 @@ fun View.applyWindowInsetsForController() {
requestApplyInsetsWhenAttached()
}
fun View.checkHeightThen(f: () -> Unit) {
viewTreeObserver.addOnGlobalLayoutListener(
object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
if (height > 0) {
viewTreeObserver.removeOnGlobalLayoutListener(this)
f()
}
}
}
)
}
fun View.applyWindowInsetsForRootController(bottomNav: View) {
viewTreeObserver.addOnGlobalLayoutListener(
object : ViewTreeObserver.OnGlobalLayoutListener {
@ -279,10 +292,13 @@ fun Controller.setOnQueryTextChangeListener(searchView: SearchView, f: (text: St
if (router.backstack.lastOrNull()?.controller() == this@setOnQueryTextChangeListener) {
return f(newText)
}
return true
return false
}
override fun onQueryTextSubmit(query: String?): Boolean {
if (router.backstack.lastOrNull()?.controller() == this@setOnQueryTextChangeListener) {
return f(query)
}
return true
}
})

View File

@ -36,11 +36,6 @@
android:adjustViewBounds="true"
android:background="?android:attr/colorBackground"
android:maxHeight="250dp"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:background="?android:attr/colorBackground"
tools:ignore="ContentDescription"
tools:src="@mipmap/ic_launcher" />

View File

@ -449,7 +449,7 @@
<string name="remember_choice">Remember this choice</string>
<string name="already_in_category">Manga already in category</string>
<string name="category">Category</string>
<string name="uniform_grid">Uniform Grid</string>
<string name="uniform_grid">Uniform covers</string>
<string name="small">Small</string>
<string name="medium">Medium</string>
<string name="large">Large</string>