同步上游更改:感谢 @821938089
This commit is contained in:
@@ -273,7 +273,7 @@ fun Book.updateTo(newBook: Book): Book {
|
||||
newBook.hasVariable(it)
|
||||
}
|
||||
newBook.variableMap.putAll(variableMap)
|
||||
newBook.variable = GSON.toJson(variableMap)
|
||||
newBook.variable = GSON.toJson(newBook.variableMap)
|
||||
return newBook
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +78,7 @@ object AudioPlay : CoroutineScope by MainScope() {
|
||||
chapterSize
|
||||
}
|
||||
if (durChapterIndex != book.durChapterIndex) {
|
||||
stopPlay()
|
||||
durChapterIndex = book.durChapterIndex
|
||||
durChapterPos = book.durChapterPos
|
||||
durPlayUrl = ""
|
||||
@@ -152,6 +153,8 @@ object AudioPlay : CoroutineScope by MainScope() {
|
||||
}.onError {
|
||||
AppLog.put("获取资源链接出错\n$it", it, true)
|
||||
upLoading(false)
|
||||
}.onCancel {
|
||||
removeLoading(index)
|
||||
}.onFinally {
|
||||
removeLoading(index)
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ class WebService : BaseService() {
|
||||
|
||||
private val useWakeLock = appCtx.getPrefBoolean(PreferKey.webServiceWakeLock, false)
|
||||
private val wakeLock: PowerManager.WakeLock by lazy {
|
||||
powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "legado:webService")
|
||||
powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "legado:WebService")
|
||||
.apply {
|
||||
setReferenceCounted(false)
|
||||
}
|
||||
|
||||
@@ -853,7 +853,9 @@ class BookInfoActivity :
|
||||
viewModel.bookSource?.getKey() -> viewModel.bookSource?.setVariable(variable)
|
||||
viewModel.bookData.value?.bookUrl -> viewModel.bookData.value?.let {
|
||||
it.putCustomVariable(variable)
|
||||
viewModel.saveBook(it)
|
||||
if (viewModel.inBookshelf) {
|
||||
viewModel.saveBook(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1386,8 +1386,13 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
ReadAloud.upReadAloudClass()
|
||||
val scrollPageAnim = ReadBook.pageAnim() == 3
|
||||
if (scrollPageAnim) {
|
||||
val startPos = binding.readView.getCurPagePosition()
|
||||
ReadBook.readAloud(startPos = startPos)
|
||||
val line = binding.readView.getCurVisibleFirstLine()
|
||||
if (line != null) {
|
||||
ReadBook.durChapterPos = line.chapterPosition
|
||||
ReadBook.readAloud(startPos = line.pagePosition)
|
||||
} else {
|
||||
ReadBook.readAloud()
|
||||
}
|
||||
} else {
|
||||
ReadBook.readAloud()
|
||||
}
|
||||
@@ -1397,8 +1402,13 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
val scrollPageAnim = ReadBook.pageAnim() == 3
|
||||
if (scrollPageAnim && pageChanged) {
|
||||
pageChanged = false
|
||||
val startPos = binding.readView.getCurPagePosition()
|
||||
ReadBook.readAloud(startPos = startPos)
|
||||
val line = binding.readView.getCurVisibleFirstLine()
|
||||
if (line != null) {
|
||||
ReadBook.durChapterPos = line.chapterPosition
|
||||
ReadBook.readAloud(startPos = line.pagePosition)
|
||||
} else {
|
||||
ReadBook.readAloud()
|
||||
}
|
||||
} else {
|
||||
ReadAloud.resume(this)
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import io.legato.kazusa.utils.share
|
||||
import io.legato.kazusa.utils.toastOnUi
|
||||
import io.legato.kazusa.utils.visible
|
||||
import androidx.core.net.toUri
|
||||
import io.legato.kazusa.constant.AppLog
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
class TextActionMenu(private val context: Context, private val callBack: CallBack) :
|
||||
@@ -218,8 +219,12 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
|
||||
}
|
||||
|
||||
else -> item.intent?.let {
|
||||
it.putExtra(Intent.EXTRA_PROCESS_TEXT, callBack.selectedText)
|
||||
context.startActivity(it)
|
||||
kotlin.runCatching {
|
||||
it.putExtra(Intent.EXTRA_PROCESS_TEXT, callBack.selectedText)
|
||||
context.startActivity(it)
|
||||
}.onFailure { e ->
|
||||
AppLog.put("执行文本菜单操作出错\n$e", e, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import io.legato.kazusa.ui.book.read.page.delegate.SimulationPageDelegate
|
||||
import io.legato.kazusa.ui.book.read.page.delegate.SlidePageDelegate
|
||||
import io.legato.kazusa.ui.book.read.page.entities.PageDirection
|
||||
import io.legato.kazusa.ui.book.read.page.entities.TextChapter
|
||||
import io.legato.kazusa.ui.book.read.page.entities.TextLine
|
||||
import io.legato.kazusa.ui.book.read.page.entities.TextPage
|
||||
import io.legato.kazusa.ui.book.read.page.entities.TextPos
|
||||
import io.legato.kazusa.ui.book.read.page.entities.column.TextColumn
|
||||
@@ -672,8 +673,8 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
||||
return curPage.getCurVisiblePage()
|
||||
}
|
||||
|
||||
fun getCurPagePosition(): Int {
|
||||
return curPage.getCurVisibleFirstLine()?.pagePosition ?: 0
|
||||
fun getCurVisibleFirstLine(): TextLine? {
|
||||
return curPage.getCurVisibleFirstLine()
|
||||
}
|
||||
|
||||
fun invalidateTextPage() {
|
||||
|
||||
@@ -293,7 +293,8 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
scrollToBottom()
|
||||
return
|
||||
}
|
||||
val bottom = abs(lastView.bottom - recyclerView.height)
|
||||
val bottom =
|
||||
abs(lastView.bottom - recyclerView.height) - recyclerView.paddingBottom
|
||||
if (bottom <= 1) {
|
||||
scrollToBottom()
|
||||
}
|
||||
|
||||
+2
@@ -12,6 +12,8 @@ import io.legato.kazusa.data.entities.Book
|
||||
abstract class BaseBooksAdapter<VB : ViewBinding>(context: Context) :
|
||||
DiffRecyclerAdapter<Book, VB>(context) {
|
||||
|
||||
override val keepScrollPosition = true
|
||||
|
||||
override val diffItemCallback: DiffUtil.ItemCallback<Book> =
|
||||
object : DiffUtil.ItemCallback<Book>() {
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.channelFlow
|
||||
import kotlinx.coroutines.flow.conflate
|
||||
import kotlinx.coroutines.flow.filterNotNull
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.flow.flatMapMerge
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
@@ -198,7 +198,9 @@ fun <T> Flow<T>.flowWithLifecycleFirst(
|
||||
minActiveState: Lifecycle.State = Lifecycle.State.STARTED
|
||||
): Flow<T> = callbackFlow {
|
||||
if (!lifecycle.currentState.isAtLeast(minActiveState)) {
|
||||
send(first())
|
||||
firstOrNull()?.let {
|
||||
send(it)
|
||||
}
|
||||
}
|
||||
lifecycle.repeatOnLifecycle(minActiveState) {
|
||||
this@flowWithLifecycleFirst.collect {
|
||||
@@ -244,7 +246,9 @@ fun <T> Flow<T>.flowWithLifecycleAndDatabaseChangeFirst(
|
||||
.onEach { update++ }
|
||||
.produceIn(this)
|
||||
if (!isActive) {
|
||||
send(first())
|
||||
firstOrNull()?.let {
|
||||
send(it)
|
||||
}
|
||||
}
|
||||
lifecycle.repeatOnLifecycle(minActiveState) {
|
||||
if (update == 0) {
|
||||
|
||||
Reference in New Issue
Block a user