mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2025-01-11 06:19:08 +01:00
Fixing drag and drop stuff
Also changed the order of the themes
This commit is contained in:
parent
25492e0db8
commit
dad12ce216
@ -53,6 +53,6 @@ abstract class LibraryHolder(
|
||||
|
||||
override fun onLongClick(view: View?): Boolean {
|
||||
super.onLongClick(view)
|
||||
return !adapter.libraryListener.recyclerIsScrolling()
|
||||
return false // !adapter.libraryListener.recyclerIsScrolling()
|
||||
}
|
||||
}
|
||||
|
@ -92,6 +92,7 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
|
||||
var prevCategory:Int? = null
|
||||
private val swipeDistance = 300f
|
||||
var flinging = false
|
||||
var isDragging = false
|
||||
|
||||
/**
|
||||
* Recycler view of the list of manga.
|
||||
@ -149,6 +150,11 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
|
||||
return
|
||||
}
|
||||
if (flinging) return
|
||||
if (isDragging) {
|
||||
resetScrollingValues()
|
||||
resetRecyclerY(false)
|
||||
return
|
||||
}
|
||||
val sheetRect = Rect()
|
||||
val recyclerRect = Rect()
|
||||
bottom_sheet.getGlobalVisibleRect(sheetRect)
|
||||
@ -600,6 +606,8 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
|
||||
override fun onActionStateChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
|
||||
val position = viewHolder?.adapterPosition ?: return
|
||||
if (actionState == 2) {
|
||||
isDragging = true
|
||||
activity?.appbar?.y = 0f
|
||||
if (lastItemPosition != null && position != lastItemPosition
|
||||
&& lastItem == adapter.getItem(position)) {
|
||||
// because for whatever reason you can repeatedly tap on a currently dragging manga
|
||||
@ -627,13 +635,31 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
|
||||
invalidateActionMode()
|
||||
}
|
||||
override fun onItemMove(fromPosition: Int, toPosition: Int) {
|
||||
// Because padding a recycler causes it to scroll up we have to scroll it back down... wild
|
||||
if ((adapter.getItem(fromPosition) is LibraryItem &&
|
||||
adapter.getItem(fromPosition) is LibraryItem) ||
|
||||
adapter.getItem(fromPosition) == null)
|
||||
recycler.scrollBy(0, recycler.paddingTop)
|
||||
activity?.appbar?.y = 0f
|
||||
if (lastItemPosition == toPosition)
|
||||
lastItemPosition = null
|
||||
else if (lastItemPosition == null)
|
||||
lastItemPosition = fromPosition
|
||||
}
|
||||
|
||||
override fun shouldMoveItem(fromPosition: Int, toPosition: Int): Boolean {
|
||||
if (adapter.isSelected(fromPosition))
|
||||
toggleSelection(fromPosition)
|
||||
val item = adapter.getItem(fromPosition) as? LibraryItem ?: return false
|
||||
val newHeader = adapter.getSectionHeader(toPosition) as? LibraryHeaderItem
|
||||
if (toPosition <= 1) return false
|
||||
return (adapter.getItem(toPosition) !is LibraryHeaderItem)&&
|
||||
(newHeader?.category?.id == item.manga.category ||
|
||||
!presenter.mangaIsInCategory(item.manga, newHeader?.category?.id))
|
||||
}
|
||||
|
||||
override fun onItemReleased(position: Int) {
|
||||
isDragging = false
|
||||
if (adapter.selectedItemCount > 0) {
|
||||
lastItemPosition = null
|
||||
return
|
||||
@ -694,18 +720,6 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
|
||||
lastItemPosition = null
|
||||
}
|
||||
|
||||
override fun shouldMoveItem(fromPosition: Int, toPosition: Int): Boolean {
|
||||
//if (adapter.selectedItemCount > 1)
|
||||
// return false
|
||||
if (adapter.isSelected(fromPosition))
|
||||
toggleSelection(fromPosition)
|
||||
val item = adapter.getItem(fromPosition) as? LibraryItem ?: return false
|
||||
val newHeader = adapter.getSectionHeader(toPosition) as? LibraryHeaderItem
|
||||
//if (adapter.getItem(toPosition) is LibraryHeaderItem) return false
|
||||
return newHeader?.category?.id == item.manga.category ||
|
||||
!presenter.mangaIsInCategory(item.manga, newHeader?.category?.id)
|
||||
}
|
||||
|
||||
override fun updateCategory(catId: Int): Boolean {
|
||||
val category = (adapter.getItem(catId) as? LibraryHeaderItem)?.category ?:
|
||||
return false
|
||||
@ -768,23 +782,10 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
|
||||
if (sheetRect.contains(x.toInt(), y.toInt()))
|
||||
showFiltersBottomSheet()
|
||||
}
|
||||
override fun onSwipeLeft(x: Float, y: Float) = goToNextCategory(x, y,-1)
|
||||
override fun onSwipeRight(x: Float, y: Float) = goToNextCategory(x, y,1)
|
||||
|
||||
private fun goToNextCategory(x: Float, y: Float, offset: Int) {
|
||||
/*
|
||||
val sheetRect = Rect()
|
||||
val recyclerRect = Rect()
|
||||
bottom_sheet.getGlobalVisibleRect(sheetRect)
|
||||
recycler.getGlobalVisibleRect(recyclerRect)
|
||||
|
||||
if (sheetRect.contains(x.toInt(), y.toInt()) ||
|
||||
!recyclerRect.contains(x.toInt(), y.toInt())) {
|
||||
return
|
||||
}*/
|
||||
//jumpToCategory(offset)
|
||||
|
||||
override fun onSwipeLeft(x: Float, y: Float) = goToNextCategory(x)
|
||||
override fun onSwipeRight(x: Float, y: Float) = goToNextCategory(x)
|
||||
|
||||
private fun goToNextCategory(x: Float) {
|
||||
if (lockedRecycler && abs(x) > 1000f) {
|
||||
val sign = sign(x).roundToInt()
|
||||
if ((sign < 0 && nextCategory == null) || (sign > 0) && prevCategory == null)
|
||||
@ -829,24 +830,5 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
|
||||
}
|
||||
}
|
||||
|
||||
private fun jumpToCategory(offset: Int) {
|
||||
val position =
|
||||
(recycler.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
|
||||
val order = when (val item = adapter.getItem(position)) {
|
||||
is LibraryHeaderItem -> item.category.order
|
||||
is LibraryItem -> presenter.categories.find { it.id == item.manga.category }?.order
|
||||
else -> null
|
||||
}
|
||||
if (order != null) {
|
||||
var newOffset = order + offset
|
||||
while (adapter.indexOf(newOffset) == -1 && presenter.categories.any { it.order == newOffset }) {
|
||||
newOffset += offset
|
||||
}
|
||||
scrollToHeader(newOffset)
|
||||
}
|
||||
}
|
||||
|
||||
override fun popUpMenu(): PopupMenu = titlePopupMenu
|
||||
|
||||
override fun recyclerIsScrolling() = switchingCategories || lockedRecycler || lockedY
|
||||
}
|
@ -743,15 +743,12 @@ interface BottomNavBarInterface {
|
||||
}
|
||||
|
||||
interface RootSearchInterface
|
||||
interface SpinnerTitleInterface
|
||||
|
||||
interface OnTouchEventInterface {
|
||||
fun onTouchEvent(event: MotionEvent?)
|
||||
}
|
||||
|
||||
interface SpinnerTitleInterface {
|
||||
fun popUpMenu(): PopupMenu
|
||||
}
|
||||
|
||||
interface SwipeGestureInterface {
|
||||
fun onSwipeRight(x: Float, y: Float)
|
||||
fun onSwipeLeft(x: Float, y: Float)
|
||||
|
@ -45,11 +45,11 @@ class SettingsGeneralController : SettingsController() {
|
||||
intListPreference(activity) {
|
||||
key = Keys.theme
|
||||
titleRes = R.string.pref_theme
|
||||
entriesRes = arrayOf(R.string.light_theme, R.string.white_theme, R.string.dark_theme,
|
||||
entriesRes = arrayOf(R.string.white_theme, R.string.light_theme, R.string.dark_theme,
|
||||
R.string.amoled_theme, R.string.darkblue_theme,
|
||||
R.string.system_theme, R.string.sysyem_white_theme, R.string.system_amoled_theme, R.string
|
||||
.system_darkblue_theme)
|
||||
entryValues = listOf(1, 8, 2, 3, 4, 5, 9, 6, 7)
|
||||
R.string.sysyem_white_theme, R.string.system_theme, R.string.system_amoled_theme,
|
||||
R.string.system_darkblue_theme)
|
||||
entryValues = listOf(8, 1, 2, 3, 4, 9, 5, 6, 7)
|
||||
defaultValue = 9
|
||||
|
||||
onChange {
|
||||
|
@ -314,25 +314,28 @@ fun Controller.setOnQueryTextChangeListener(searchView: SearchView, onlyOnSubmit
|
||||
})
|
||||
}
|
||||
|
||||
fun Controller.scrollViewWith(recycler: RecyclerView,
|
||||
fun Controller.scrollViewWith(
|
||||
recycler: RecyclerView,
|
||||
padBottom: Boolean = false,
|
||||
swipeRefreshLayout: SwipeRefreshLayout? = null,
|
||||
f: ((WindowInsets) -> Unit)? = null) {
|
||||
afterInsets: ((WindowInsets) -> Unit)? = null) {
|
||||
var statusBarHeight = -1
|
||||
activity?.appbar?.y = 0f
|
||||
val attrsArray = intArrayOf(android.R.attr.actionBarSize)
|
||||
val array = recycler.context.obtainStyledAttributes(attrsArray)
|
||||
val appBarHeight = array.getDimensionPixelSize(0, 0)
|
||||
array.recycle()
|
||||
recycler.doOnApplyWindowInsets { view, insets, _ ->
|
||||
val attrsArray = intArrayOf(android.R.attr.actionBarSize)
|
||||
val array = view.context.obtainStyledAttributes(attrsArray)
|
||||
val headerHeight = insets.systemWindowInsetTop + array.getDimensionPixelSize(0, 0)
|
||||
val headerHeight = insets.systemWindowInsetTop + appBarHeight
|
||||
view.updatePaddingRelative(
|
||||
top = headerHeight,
|
||||
bottom = if (padBottom) insets.systemWindowInsetBottom else view.paddingBottom
|
||||
)
|
||||
swipeRefreshLayout?.setProgressViewOffset(false, headerHeight + (-60).dpToPx,
|
||||
headerHeight)
|
||||
swipeRefreshLayout?.setProgressViewOffset(
|
||||
false, headerHeight + (-60).dpToPx, headerHeight
|
||||
)
|
||||
statusBarHeight = insets.systemWindowInsetTop
|
||||
array.recycle()
|
||||
f?.invoke(insets)
|
||||
afterInsets?.invoke(insets)
|
||||
}
|
||||
recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user