优化
This commit is contained in:
@@ -73,6 +73,7 @@ import kotlinx.coroutines.Dispatchers.IO
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
|
import kotlin.math.ceil
|
||||||
|
|
||||||
class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewModel>(),
|
class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewModel>(),
|
||||||
ReadManga.Callback, ChangeBookSourceDialog.CallBack, MangaMenu.CallBack,
|
ReadManga.Callback, ChangeBookSourceDialog.CallBack, MangaMenu.CallBack,
|
||||||
@@ -428,10 +429,8 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
|
|||||||
if (binding.mRecyclerManga.isAtBottom()) {
|
if (binding.mRecyclerManga.isAtBottom()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
binding.mRecyclerManga.smoothScrollBy(
|
val time = ceil(16f / distance * 10000).toInt()
|
||||||
if (mAdapter.isHorizontal) distance else 0,
|
binding.mRecyclerManga.smoothScrollBy(10000, 10000, mLinearInterpolator, time)
|
||||||
if (mAdapter.isHorizontal) 0 else distance, mLinearInterpolator, 16
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun scrollPage() {
|
override fun scrollPage() {
|
||||||
|
|||||||
@@ -1,21 +1,17 @@
|
|||||||
package io.legado.app.ui.book.manga.recyclerview
|
package io.legado.app.ui.book.manga.recyclerview
|
||||||
|
|
||||||
import androidx.lifecycle.LifecycleCoroutineScope
|
|
||||||
import androidx.lifecycle.LifecycleOwner
|
|
||||||
import androidx.lifecycle.coroutineScope
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE
|
import androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.isActive
|
import kotlinx.coroutines.isActive
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
|
|
||||||
class ScrollTimer(
|
class ScrollTimer(
|
||||||
private val callback: ScrollCallback,
|
private val callback: ScrollCallback,
|
||||||
private val recyclerView: RecyclerView,
|
private val recyclerView: RecyclerView,
|
||||||
private val coroutine: LifecycleCoroutineScope,
|
private val coroutineScope: CoroutineScope,
|
||||||
) : RecyclerView.OnScrollListener() {
|
) : RecyclerView.OnScrollListener() {
|
||||||
private var distance = 1
|
private var distance = 1
|
||||||
private var mScrollPageJob: Job? = null
|
private var mScrollPageJob: Job? = null
|
||||||
@@ -28,6 +24,7 @@ class ScrollTimer(
|
|||||||
startScroll()
|
startScroll()
|
||||||
} else {
|
} else {
|
||||||
recyclerView.removeOnScrollListener(this)
|
recyclerView.removeOnScrollListener(this)
|
||||||
|
recyclerView.stopScroll()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,12 +60,10 @@ class ScrollTimer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun startScrollPage() {
|
private fun startScrollPage() {
|
||||||
mScrollPageJob = coroutine.launch(Dispatchers.Default) {
|
mScrollPageJob = coroutineScope.launch {
|
||||||
while (isActive) {
|
while (isActive) {
|
||||||
delay(distance.times(1000L))
|
delay(distance.times(1000L))
|
||||||
withContext(Dispatchers.Main) {
|
callback.scrollPage()
|
||||||
callback.scrollPage()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user