mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 20:31:51 +01:00
Always using autofit for single list + start at header on app start/tab return
Moving some classes outside of library controller
This commit is contained in:
parent
da2f3d4524
commit
18cbb72f79
@ -31,20 +31,20 @@ import eu.kanade.tachiyomi.ui.base.controller.SecondaryDrawerController
|
||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||
import eu.kanade.tachiyomi.ui.catalogue.CatalogueController
|
||||
import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog
|
||||
import eu.kanade.tachiyomi.ui.library.HeightTopWindowInsetsListener
|
||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||
import eu.kanade.tachiyomi.ui.webview.WebViewActivity
|
||||
import eu.kanade.tachiyomi.util.system.connectivityManager
|
||||
import eu.kanade.tachiyomi.util.view.HeightTopWindowInsetsListener
|
||||
import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener
|
||||
import eu.kanade.tachiyomi.util.view.gone
|
||||
import eu.kanade.tachiyomi.util.view.inflate
|
||||
import eu.kanade.tachiyomi.util.view.marginBottom
|
||||
import eu.kanade.tachiyomi.util.view.marginTop
|
||||
import eu.kanade.tachiyomi.util.view.snack
|
||||
import eu.kanade.tachiyomi.util.view.updateLayoutParams
|
||||
import eu.kanade.tachiyomi.util.view.updatePaddingRelative
|
||||
import eu.kanade.tachiyomi.util.view.visible
|
||||
import eu.kanade.tachiyomi.util.system.connectivityManager
|
||||
import eu.kanade.tachiyomi.util.view.marginBottom
|
||||
import eu.kanade.tachiyomi.widget.AutofitRecyclerView
|
||||
import kotlinx.android.synthetic.main.catalogue_controller.*
|
||||
import kotlinx.android.synthetic.main.main_activity.*
|
||||
|
@ -5,16 +5,13 @@ import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.WindowInsets
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.Spinner
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.view.ActionMode
|
||||
@ -213,6 +210,8 @@ class LibraryController(
|
||||
*/
|
||||
private lateinit var recycler: RecyclerView
|
||||
|
||||
var libraryLayout = preferences.libraryLayout().getOrDefault()
|
||||
|
||||
private var usePager: Boolean = !preferences.libraryAsSingleList().getOrDefault()
|
||||
|
||||
init {
|
||||
@ -255,26 +254,20 @@ class LibraryController(
|
||||
}
|
||||
else {
|
||||
adapter = LibraryCategoryAdapter(this)
|
||||
recycler = if (preferences.libraryLayout().getOrDefault() == 0) {
|
||||
(recycler_layout.inflate(R.layout.library_list_recycler) as RecyclerView).apply {
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
}
|
||||
} else {
|
||||
(recycler_layout.inflate(R.layout.library_grid_recycler) as AutofitRecyclerView).apply {
|
||||
spanCount = mangaPerRow
|
||||
manager.spanSizeLookup = (object : GridLayoutManager.SpanSizeLookup() {
|
||||
override fun getSpanSize(position: Int): Int {
|
||||
val item = this@LibraryController.adapter.getItem(position)
|
||||
return if (item is LibraryHeaderItem)
|
||||
manager.spanCount else 1
|
||||
}
|
||||
})
|
||||
}
|
||||
recycler = (recycler_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@LibraryController.adapter.getItem(position)
|
||||
return if (item is LibraryHeaderItem) manager.spanCount else 1
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
recycler.setHasFixedSize(true)
|
||||
recycler.adapter = adapter
|
||||
//adapter.setStickyHeaders(true)
|
||||
recycler_layout.addView(recycler)
|
||||
adapter.fastScroller = fast_scroller
|
||||
recycler.addOnScrollListener(scrollListener)
|
||||
@ -286,8 +279,6 @@ class LibraryController(
|
||||
arrayOf(resources!!.getString(R.string.label_library)))
|
||||
spinnerAdapter?.setDropDownViewResource(R.layout.library_spinner_entry_text)
|
||||
spinner.adapter = spinnerAdapter
|
||||
|
||||
//spinnerAdapter?.setCustomText(resources?.getString(R.string.label_library))
|
||||
}
|
||||
|
||||
|
||||
@ -295,7 +286,6 @@ class LibraryController(
|
||||
createActionModeIfNeeded()
|
||||
}
|
||||
|
||||
|
||||
//bottom_sheet.onCreate(pager_layout)
|
||||
bottom_sheet.onCreate(if (usePager) pager_layout else recycler_layout)
|
||||
|
||||
@ -440,7 +430,6 @@ class LibraryController(
|
||||
}
|
||||
adapter.setItems(mangaMap)
|
||||
|
||||
val position = if (freshStart) adapter.indexOf(activeCategory) + 1 else null
|
||||
|
||||
spinner.onItemSelectedListener = null
|
||||
spinnerAdapter = SpinnerAdapter(view!!.context, R.layout.library_spinner_textview,
|
||||
@ -450,8 +439,6 @@ class LibraryController(
|
||||
|
||||
|
||||
spinner.setSelection(min(presenter.categories.size - 1, activeCategory + 1))
|
||||
/* spinnerAdapter?.setCustomText(presenter.categories.find { it.order == activeCategory
|
||||
}?.name ?: resources?.getString(R.string.label_library))*/
|
||||
if (!freshStart) {
|
||||
justStarted = false
|
||||
if (recycler_layout.alpha == 0f)
|
||||
@ -459,9 +446,10 @@ class LibraryController(
|
||||
|
||||
|
||||
}else {
|
||||
val position = if (freshStart) adapter.indexOf(activeCategory) else null
|
||||
if (position != null)
|
||||
(recycler.layoutManager as LinearLayoutManager)
|
||||
.scrollToPositionWithOffset(position, 0)
|
||||
.scrollToPositionWithOffset(position, (-30).dpToPx)
|
||||
}
|
||||
adapter.isLongPressDragEnabled = canDrag()
|
||||
tabsVisibilityRelay.call(false)
|
||||
@ -476,10 +464,10 @@ class LibraryController(
|
||||
updateScroll = false
|
||||
return@IgnoreFirstSpinnerListener
|
||||
}
|
||||
val headerPosition = adapter.indexOf(pos - 1) + 1
|
||||
val headerPosition = adapter.indexOf(pos - 1)
|
||||
if (headerPosition > -1) {
|
||||
(recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(
|
||||
headerPosition, 0
|
||||
headerPosition, (-30).dpToPx
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -598,45 +586,9 @@ class LibraryController(
|
||||
else {
|
||||
val position =
|
||||
(recycler.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
|
||||
// if switching from list to grid
|
||||
if (recycler is AutofitRecyclerView && preferences.libraryLayout().getOrDefault() == 0
|
||||
|| recycler !is AutofitRecyclerView && preferences.libraryLayout().getOrDefault() > 0) {
|
||||
destroyActionModeIfNeeded()
|
||||
recycler_layout.removeView(recycler)
|
||||
recycler = if (preferences.libraryLayout().getOrDefault() == 0) {
|
||||
(recycler_layout.inflate(R.layout.library_list_recycler) as RecyclerView).apply {
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
}
|
||||
} else {
|
||||
(recycler_layout.inflate(R.layout.library_grid_recycler) as AutofitRecyclerView).apply {
|
||||
spanCount = mangaPerRow
|
||||
manager.spanSizeLookup = (object : GridLayoutManager.SpanSizeLookup() {
|
||||
override fun getSpanSize(position: Int): Int {
|
||||
val item = this@LibraryController.adapter.getItem(position)
|
||||
return if (item is LibraryHeaderItem) manager.spanCount else 1
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
recycler.setHasFixedSize(true)
|
||||
adapter = LibraryCategoryAdapter(this)
|
||||
recycler.adapter = adapter
|
||||
recycler.addOnScrollListener(scrollListener)
|
||||
adapter.isLongPressDragEnabled = canDrag()
|
||||
recycler_layout.addView(recycler)
|
||||
adapter.setItems(presenter.getList())
|
||||
val config = resources?.configuration
|
||||
val phoneLandscape = (config?.orientation == Configuration.ORIENTATION_LANDSCAPE &&
|
||||
(config.screenLayout.and(Configuration.SCREENLAYOUT_SIZE_MASK)) <
|
||||
Configuration.SCREENLAYOUT_SIZE_LARGE)
|
||||
if (!usePager && !phoneLandscape) {
|
||||
val height = recycler.resources.getDimensionPixelSize(R.dimen
|
||||
.rounder_radius) + 4.dpToPx
|
||||
recycler.updatePaddingRelative(bottom = height)
|
||||
}
|
||||
} else {
|
||||
recycler.adapter = adapter
|
||||
}
|
||||
libraryLayout = preferences.libraryLayout().getOrDefault()
|
||||
recycler.adapter = adapter
|
||||
(recycler as? AutofitRecyclerView)?.spanCount = if (libraryLayout == 0) 1 else mangaPerRow
|
||||
|
||||
(recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(position, 0)
|
||||
}
|
||||
@ -924,19 +876,17 @@ class LibraryController(
|
||||
destroyActionModeIfNeeded()
|
||||
}
|
||||
|
||||
/// Method for single list
|
||||
override fun startReading(position: Int) {
|
||||
val activity = activity ?: return
|
||||
val manga = (adapter.getItem(position) as? LibraryItem)?.manga ?: return
|
||||
if (adapter.mode == SelectableAdapter.Mode.MULTI) {
|
||||
toggleSelection(position)
|
||||
return
|
||||
}
|
||||
val chapter = presenter.getFirstUnread(manga) ?: return
|
||||
val intent = ReaderActivity.newIntent(activity, manga, chapter)
|
||||
destroyActionModeIfNeeded()
|
||||
startActivity(intent)
|
||||
val manga = (adapter.getItem(position) as? LibraryItem)?.manga ?: return
|
||||
startReading(manga)
|
||||
}
|
||||
|
||||
/// Method for the category view
|
||||
fun startReading(manga: Manga) {
|
||||
val activity = activity ?: return
|
||||
val chapter = presenter.getFirstUnread(manga) ?: return
|
||||
@ -1057,7 +1007,6 @@ class LibraryController(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun shouldMoveItem(fromPosition: Int, toPosition: Int): Boolean {
|
||||
if (adapter.selectedItemCount > 1)
|
||||
return false
|
||||
@ -1088,48 +1037,4 @@ class LibraryController(
|
||||
presenter.sortCategory(catId, sortBy)
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
object HeightTopWindowInsetsListener : View.OnApplyWindowInsetsListener {
|
||||
override fun onApplyWindowInsets(v: View, insets: WindowInsets): WindowInsets {
|
||||
val topInset = insets.systemWindowInsetTop
|
||||
v.setPadding(0,topInset,0,0)
|
||||
if (v.layoutParams.height != topInset) {
|
||||
v.layoutParams.height = topInset
|
||||
v.requestLayout()
|
||||
}
|
||||
return insets
|
||||
}
|
||||
}
|
||||
|
||||
class SpinnerAdapter(context: Context, layoutId: Int, val array: Array<String>) :
|
||||
ArrayAdapter<String>
|
||||
(context, layoutId, array)
|
||||
|
||||
class ReSpinner : Spinner {
|
||||
constructor(context: Context?) : super(context) {}
|
||||
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {}
|
||||
constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(
|
||||
context, attrs, defStyle
|
||||
)
|
||||
|
||||
override fun setSelection(position: Int, animate: Boolean) {
|
||||
val sameSelected = position == selectedItemPosition
|
||||
super.setSelection(position, animate)
|
||||
if (sameSelected) { // Spinner does not call the OnItemSelectedListener if the same item is selected, so do it manually now
|
||||
onItemSelectedListener?.onItemSelected(
|
||||
this, selectedView, position, selectedItemId
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setSelection(position: Int) {
|
||||
val sameSelected = position == selectedItemPosition
|
||||
super.setSelection(position)
|
||||
if (sameSelected) { // Spinner does not call the OnItemSelectedListener if the same item is selected, so do it manually now
|
||||
onItemSelectedListener?.onItemSelected(
|
||||
this, selectedView, position, selectedItemId
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -90,7 +90,6 @@ class LibraryHeaderItem(val category: Category) : AbstractHeaderItem<LibraryHead
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
when {
|
||||
item.category.id == -1 -> {
|
||||
updateButton.invisible()
|
||||
|
@ -39,32 +39,42 @@ class LibraryItem(val manga: LibraryManga,
|
||||
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): LibraryHolder {
|
||||
val parent = adapter.recyclerView
|
||||
return if (parent is AutofitRecyclerView) {
|
||||
val fixedSize = libraryLayout.getOrDefault() == 1
|
||||
view.apply {
|
||||
val coverHeight = (parent.itemWidth / 3f * 4f).toInt()
|
||||
if (fixedSize) {
|
||||
constraint_layout.layoutParams = FrameLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
val marginParams = card.layoutParams as ConstraintLayout.LayoutParams
|
||||
marginParams.bottomMargin = 6.dpToPx
|
||||
card.layoutParams = marginParams
|
||||
cover_thumbnail.maxHeight = Integer.MAX_VALUE
|
||||
constraint_layout.minHeight = 0
|
||||
cover_thumbnail.adjustViewBounds = false
|
||||
cover_thumbnail.layoutParams =
|
||||
FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, coverHeight)
|
||||
}
|
||||
else {
|
||||
constraint_layout.minHeight = coverHeight
|
||||
cover_thumbnail.maxHeight = (parent.itemWidth / 3f * 6f).toInt()
|
||||
constraint_layout.background = ContextCompat.getDrawable(context,
|
||||
R.drawable.library_item_selector)
|
||||
}
|
||||
val libraryLayout = libraryLayout.getOrDefault()
|
||||
if (libraryLayout == 0) {
|
||||
LibraryListHolder(view, adapter as LibraryCategoryAdapter)
|
||||
}
|
||||
else {
|
||||
view.apply {
|
||||
val coverHeight = (parent.itemWidth / 3f * 4f).toInt()
|
||||
if (libraryLayout == 1) {
|
||||
constraint_layout.layoutParams = FrameLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
val marginParams = card.layoutParams as ConstraintLayout.LayoutParams
|
||||
marginParams.bottomMargin = 6.dpToPx
|
||||
card.layoutParams = marginParams
|
||||
cover_thumbnail.maxHeight = Integer.MAX_VALUE
|
||||
constraint_layout.minHeight = 0
|
||||
cover_thumbnail.adjustViewBounds = false
|
||||
cover_thumbnail.layoutParams = FrameLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
coverHeight
|
||||
)
|
||||
} else if (libraryLayout == 2) {
|
||||
constraint_layout.minHeight = coverHeight
|
||||
cover_thumbnail.maxHeight = (parent.itemWidth / 3f * 6f).toInt()
|
||||
constraint_layout.background = ContextCompat.getDrawable(
|
||||
context, R.drawable.library_item_selector
|
||||
)
|
||||
}
|
||||
}
|
||||
LibraryGridHolder(
|
||||
view,
|
||||
adapter as LibraryCategoryAdapter,
|
||||
parent.itemWidth,
|
||||
libraryLayout == 1
|
||||
)
|
||||
}
|
||||
LibraryGridHolder(view, adapter as LibraryCategoryAdapter, parent.itemWidth, fixedSize)
|
||||
|
||||
} else {
|
||||
LibraryListHolder(view, adapter as LibraryCategoryAdapter)
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
package eu.kanade.tachiyomi.ui.library
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.Spinner
|
||||
|
||||
class ReSpinner : Spinner {
|
||||
constructor(context: Context?) : super(context) {}
|
||||
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {}
|
||||
constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(
|
||||
context, attrs, defStyle
|
||||
)
|
||||
|
||||
override fun setSelection(position: Int, animate: Boolean) {
|
||||
val sameSelected = position == selectedItemPosition
|
||||
super.setSelection(position, animate)
|
||||
if (sameSelected) { // Spinner does not call the OnItemSelectedListener if the same item is selected, so do it manually now
|
||||
onItemSelectedListener?.onItemSelected(
|
||||
this, selectedView, position, selectedItemId
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setSelection(position: Int) {
|
||||
val sameSelected = position == selectedItemPosition
|
||||
super.setSelection(position)
|
||||
if (sameSelected) { // Spinner does not call the OnItemSelectedListener if the same item is selected, so do it manually now
|
||||
onItemSelectedListener?.onItemSelected(
|
||||
this, selectedView, position, selectedItemId
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SpinnerAdapter(context: Context, layoutId: Int, val array: Array<String>) :
|
||||
ArrayAdapter<String>
|
||||
(context, layoutId, array)
|
@ -6,11 +6,8 @@ import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.customview.customView
|
||||
import com.afollestad.materialdialogs.internal.main.DialogLayout
|
||||
import com.bluelinelabs.conductor.Router
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import com.bumptech.glide.signature.ObjectKey
|
||||
import eu.kanade.tachiyomi.R
|
||||
@ -60,7 +57,7 @@ class EditMangaDialog : DialogController {
|
||||
positiveButton(R.string.action_save) { onPositiveButtonClick() }
|
||||
}
|
||||
dialogView = dialog.view
|
||||
onViewCreated(dialog.view, savedViewState)
|
||||
onViewCreated(dialog.view)
|
||||
dialog.setOnShowListener {
|
||||
val dView = (it as? MaterialDialog)?.view
|
||||
dView?.contentLayout?.scrollView?.scrollTo(0, 0)
|
||||
@ -68,7 +65,7 @@ class EditMangaDialog : DialogController {
|
||||
return dialog
|
||||
}
|
||||
|
||||
fun onViewCreated(view: View, savedState: Bundle?) {
|
||||
fun onViewCreated(view: View) {
|
||||
GlideApp.with(view.context)
|
||||
.asDrawable()
|
||||
.load(manga)
|
||||
|
@ -15,7 +15,6 @@ import android.view.ViewGroup
|
||||
import android.view.WindowInsets
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.Px
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.graphics.ColorUtils
|
||||
@ -161,6 +160,18 @@ object RecyclerWindowInsetsListener : View.OnApplyWindowInsetsListener {
|
||||
}
|
||||
}
|
||||
|
||||
object HeightTopWindowInsetsListener : View.OnApplyWindowInsetsListener {
|
||||
override fun onApplyWindowInsets(v: View, insets: WindowInsets): WindowInsets {
|
||||
val topInset = insets.systemWindowInsetTop
|
||||
v.setPadding(0,topInset,0,0)
|
||||
if (v.layoutParams.height != topInset) {
|
||||
v.layoutParams.height = topInset
|
||||
v.requestLayout()
|
||||
}
|
||||
return insets
|
||||
}
|
||||
}
|
||||
|
||||
fun View.doOnApplyWindowInsets(f: (View, WindowInsets, ViewPaddingState) -> Unit) {
|
||||
// Create a snapshot of the view's padding state
|
||||
if (MainActivity.usingBottomNav) return
|
||||
|
@ -63,7 +63,7 @@
|
||||
android:id="@+id/side_layout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:paddingStart="23dp"
|
||||
android:paddingEnd="20dp"
|
||||
android:baselineAligned="true"
|
||||
@ -74,7 +74,6 @@
|
||||
android:id="@+id/sorting_layout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:baselineAligned="false"
|
||||
android:gravity="center|start"
|
||||
|
Loading…
Reference in New Issue
Block a user