Fixing drag and drop stuff

Also changed the order of the themes
This commit is contained in:
Jay 2020-03-11 20:48:38 -07:00
parent 25492e0db8
commit dad12ce216
5 changed files with 47 additions and 65 deletions

View File

@ -53,6 +53,6 @@ abstract class LibraryHolder(
override fun onLongClick(view: View?): Boolean { override fun onLongClick(view: View?): Boolean {
super.onLongClick(view) super.onLongClick(view)
return !adapter.libraryListener.recyclerIsScrolling() return false // !adapter.libraryListener.recyclerIsScrolling()
} }
} }

View File

@ -92,6 +92,7 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
var prevCategory:Int? = null var prevCategory:Int? = null
private val swipeDistance = 300f private val swipeDistance = 300f
var flinging = false var flinging = false
var isDragging = false
/** /**
* Recycler view of the list of manga. * Recycler view of the list of manga.
@ -149,6 +150,11 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
return return
} }
if (flinging) return if (flinging) return
if (isDragging) {
resetScrollingValues()
resetRecyclerY(false)
return
}
val sheetRect = Rect() val sheetRect = Rect()
val recyclerRect = Rect() val recyclerRect = Rect()
bottom_sheet.getGlobalVisibleRect(sheetRect) bottom_sheet.getGlobalVisibleRect(sheetRect)
@ -600,6 +606,8 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
override fun onActionStateChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) { override fun onActionStateChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
val position = viewHolder?.adapterPosition ?: return val position = viewHolder?.adapterPosition ?: return
if (actionState == 2) { if (actionState == 2) {
isDragging = true
activity?.appbar?.y = 0f
if (lastItemPosition != null && position != lastItemPosition if (lastItemPosition != null && position != lastItemPosition
&& lastItem == adapter.getItem(position)) { && lastItem == adapter.getItem(position)) {
// because for whatever reason you can repeatedly tap on a currently dragging manga // 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() invalidateActionMode()
} }
override fun onItemMove(fromPosition: Int, toPosition: Int) { 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) if (lastItemPosition == toPosition)
lastItemPosition = null lastItemPosition = null
else if (lastItemPosition == null) else if (lastItemPosition == null)
lastItemPosition = fromPosition 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) { override fun onItemReleased(position: Int) {
isDragging = false
if (adapter.selectedItemCount > 0) { if (adapter.selectedItemCount > 0) {
lastItemPosition = null lastItemPosition = null
return return
@ -694,18 +720,6 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
lastItemPosition = null 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 { override fun updateCategory(catId: Int): Boolean {
val category = (adapter.getItem(catId) as? LibraryHeaderItem)?.category ?: val category = (adapter.getItem(catId) as? LibraryHeaderItem)?.category ?:
return false return false
@ -768,23 +782,10 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
if (sheetRect.contains(x.toInt(), y.toInt())) if (sheetRect.contains(x.toInt(), y.toInt()))
showFiltersBottomSheet() showFiltersBottomSheet()
} }
override fun onSwipeLeft(x: Float, y: Float) = goToNextCategory(x, y,-1) override fun onSwipeLeft(x: Float, y: Float) = goToNextCategory(x)
override fun onSwipeRight(x: Float, y: Float) = goToNextCategory(x, y,1) override fun onSwipeRight(x: Float, y: Float) = goToNextCategory(x)
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)
private fun goToNextCategory(x: Float) {
if (lockedRecycler && abs(x) > 1000f) { if (lockedRecycler && abs(x) > 1000f) {
val sign = sign(x).roundToInt() val sign = sign(x).roundToInt()
if ((sign < 0 && nextCategory == null) || (sign > 0) && prevCategory == null) 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 override fun recyclerIsScrolling() = switchingCategories || lockedRecycler || lockedY
} }

View File

@ -743,15 +743,12 @@ interface BottomNavBarInterface {
} }
interface RootSearchInterface interface RootSearchInterface
interface SpinnerTitleInterface
interface OnTouchEventInterface { interface OnTouchEventInterface {
fun onTouchEvent(event: MotionEvent?) fun onTouchEvent(event: MotionEvent?)
} }
interface SpinnerTitleInterface {
fun popUpMenu(): PopupMenu
}
interface SwipeGestureInterface { interface SwipeGestureInterface {
fun onSwipeRight(x: Float, y: Float) fun onSwipeRight(x: Float, y: Float)
fun onSwipeLeft(x: Float, y: Float) fun onSwipeLeft(x: Float, y: Float)

View File

@ -45,11 +45,11 @@ class SettingsGeneralController : SettingsController() {
intListPreference(activity) { intListPreference(activity) {
key = Keys.theme key = Keys.theme
titleRes = R.string.pref_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.amoled_theme, R.string.darkblue_theme,
R.string.system_theme, R.string.sysyem_white_theme, R.string.system_amoled_theme, R.string R.string.sysyem_white_theme, R.string.system_theme, R.string.system_amoled_theme,
.system_darkblue_theme) R.string.system_darkblue_theme)
entryValues = listOf(1, 8, 2, 3, 4, 5, 9, 6, 7) entryValues = listOf(8, 1, 2, 3, 4, 9, 5, 6, 7)
defaultValue = 9 defaultValue = 9
onChange { onChange {

View File

@ -314,25 +314,28 @@ fun Controller.setOnQueryTextChangeListener(searchView: SearchView, onlyOnSubmit
}) })
} }
fun Controller.scrollViewWith(recycler: RecyclerView, fun Controller.scrollViewWith(
recycler: RecyclerView,
padBottom: Boolean = false, padBottom: Boolean = false,
swipeRefreshLayout: SwipeRefreshLayout? = null, swipeRefreshLayout: SwipeRefreshLayout? = null,
f: ((WindowInsets) -> Unit)? = null) { afterInsets: ((WindowInsets) -> Unit)? = null) {
var statusBarHeight = -1 var statusBarHeight = -1
activity?.appbar?.y = 0f activity?.appbar?.y = 0f
recycler.doOnApplyWindowInsets { view, insets, _ ->
val attrsArray = intArrayOf(android.R.attr.actionBarSize) val attrsArray = intArrayOf(android.R.attr.actionBarSize)
val array = view.context.obtainStyledAttributes(attrsArray) val array = recycler.context.obtainStyledAttributes(attrsArray)
val headerHeight = insets.systemWindowInsetTop + array.getDimensionPixelSize(0, 0) val appBarHeight = array.getDimensionPixelSize(0, 0)
array.recycle()
recycler.doOnApplyWindowInsets { view, insets, _ ->
val headerHeight = insets.systemWindowInsetTop + appBarHeight
view.updatePaddingRelative( view.updatePaddingRelative(
top = headerHeight, top = headerHeight,
bottom = if (padBottom) insets.systemWindowInsetBottom else view.paddingBottom bottom = if (padBottom) insets.systemWindowInsetBottom else view.paddingBottom
) )
swipeRefreshLayout?.setProgressViewOffset(false, headerHeight + (-60).dpToPx, swipeRefreshLayout?.setProgressViewOffset(
headerHeight) false, headerHeight + (-60).dpToPx, headerHeight
)
statusBarHeight = insets.systemWindowInsetTop statusBarHeight = insets.systemWindowInsetTop
array.recycle() afterInsets?.invoke(insets)
f?.invoke(insets)
} }
recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() { recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {