mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-05 01:35:10 +01:00
jump to last chapter now moves to where to you last tapped
This commit is contained in:
parent
2c7f0743db
commit
1265a3a790
@ -4,6 +4,7 @@ import android.content.Context
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
@ -59,6 +60,8 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
||||
*/
|
||||
private var subscriptions = CompositeSubscription()
|
||||
|
||||
private var lastTouchUpY = 0f
|
||||
|
||||
fun onCreate(controller: LibraryController) {
|
||||
this.controller = controller
|
||||
|
||||
@ -210,11 +213,18 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
||||
toggleSelection(position)
|
||||
return true
|
||||
} else {
|
||||
openManga(item.manga)
|
||||
openManga(item.manga, lastTouchUpY)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
|
||||
when (ev?.action) {
|
||||
MotionEvent.ACTION_UP -> lastTouchUpY = ev?.y
|
||||
}
|
||||
return super.dispatchTouchEvent(ev)
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a manga is long clicked.
|
||||
*
|
||||
@ -230,8 +240,8 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
||||
*
|
||||
* @param manga the manga to open.
|
||||
*/
|
||||
private fun openManga(manga: Manga) {
|
||||
controller.openManga(manga)
|
||||
private fun openManga(manga: Manga, startY:Float?) {
|
||||
controller.openManga(manga, startY)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -428,11 +428,11 @@ class LibraryController(
|
||||
actionMode = null
|
||||
}
|
||||
|
||||
fun openManga(manga: Manga) {
|
||||
fun openManga(manga: Manga, startY: Float?) {
|
||||
// Notify the presenter a manga is being opened.
|
||||
presenter.onOpenManga()
|
||||
|
||||
router.pushController(MangaController(manga).withFadeTransaction())
|
||||
router.pushController(MangaController(manga, startY).withFadeTransaction())
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,6 +48,17 @@ class MangaController : RxController, TabbedController {
|
||||
}
|
||||
}
|
||||
|
||||
constructor(manga: Manga?, startY:Float?) : super(Bundle().apply {
|
||||
putLong(MANGA_EXTRA, manga?.id ?: 0)
|
||||
putBoolean(FROM_CATALOGUE_EXTRA, false)
|
||||
}) {
|
||||
this.manga = manga
|
||||
startingChapterYPos = startY
|
||||
if (manga != null) {
|
||||
source = Injekt.get<SourceManager>().getOrStub(manga.source)
|
||||
}
|
||||
}
|
||||
|
||||
constructor(mangaId: Long) : this(
|
||||
Injekt.get<DatabaseHelper>().getManga(mangaId).executeAsBlocking())
|
||||
|
||||
@ -60,6 +71,8 @@ class MangaController : RxController, TabbedController {
|
||||
var source: Source? = null
|
||||
private set
|
||||
|
||||
var startingChapterYPos:Float? = null
|
||||
|
||||
private var adapter: MangaDetailAdapter? = null
|
||||
|
||||
val fromCatalogue = args.getBoolean(FROM_CATALOGUE_EXTRA, false)
|
||||
@ -164,7 +177,7 @@ class MangaController : RxController, TabbedController {
|
||||
if (!router.hasRootController()) {
|
||||
val controller = when (position) {
|
||||
INFO_CONTROLLER -> MangaInfoController()
|
||||
CHAPTERS_CONTROLLER -> ChaptersController()
|
||||
CHAPTERS_CONTROLLER -> ChaptersController(startingChapterYPos)
|
||||
TRACK_CONTROLLER -> TrackController()
|
||||
else -> error("Wrong position $position")
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ import androidx.core.view.ViewCompat
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kotlin.math.*
|
||||
|
||||
class ChaptersController : NucleusController<ChaptersPresenter>(),
|
||||
class ChaptersController() : NucleusController<ChaptersPresenter>(),
|
||||
ActionMode.Callback,
|
||||
FlexibleAdapter.OnItemClickListener,
|
||||
FlexibleAdapter.OnItemLongClickListener,
|
||||
@ -47,6 +47,10 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
|
||||
DownloadCustomChaptersDialog.Listener,
|
||||
DeleteChaptersDialog.Listener {
|
||||
|
||||
constructor(startY: Float?) : this() {
|
||||
this.startingChapterYPos = startY
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapter containing a list of chapters.
|
||||
*/
|
||||
@ -69,6 +73,7 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
|
||||
setHasOptionsMenu(true)
|
||||
setOptionsMenuHidden(true)
|
||||
}
|
||||
var startingChapterYPos:Float? = null
|
||||
|
||||
override fun createPresenter(): ChaptersPresenter {
|
||||
val ctrl = parentController as MangaController
|
||||
@ -233,11 +238,15 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
|
||||
}
|
||||
|
||||
private fun scrollToUnread() {
|
||||
if (adapter?.items.isNullOrEmpty()) return
|
||||
if (scrollToUnread) {
|
||||
val index = presenter.getFirstUnreadIndex()
|
||||
val centerOfScreen = recycler.height / 2 - 96
|
||||
(recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(index,
|
||||
centerOfScreen)
|
||||
val centerOfScreen =
|
||||
if (startingChapterYPos != null) startingChapterYPos!!.toInt() - recycler.top - 96
|
||||
else recycler.height / 2 - 96
|
||||
(recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(
|
||||
index, centerOfScreen
|
||||
)
|
||||
}
|
||||
scrollToUnread = false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user