优化
This commit is contained in:
@@ -217,7 +217,8 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
fun syncProgress(
|
fun syncProgress(
|
||||||
newProgressAction: ((progress: BookProgress) -> Unit)? = null,
|
newProgressAction: ((progress: BookProgress) -> Unit)? = null,
|
||||||
uploadSuccessAction: (() -> Unit)? = null,
|
uploadSuccessAction: (() -> Unit)? = null,
|
||||||
syncSuccessAction: (() -> Unit)? = null) {
|
syncSuccessAction: (() -> Unit)? = null
|
||||||
|
) {
|
||||||
if (!AppConfig.syncBookProgress) return
|
if (!AppConfig.syncBookProgress) return
|
||||||
book?.let {
|
book?.let {
|
||||||
Coroutine.async {
|
Coroutine.async {
|
||||||
@@ -227,14 +228,16 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
}.onSuccess { progress ->
|
}.onSuccess { progress ->
|
||||||
if (progress == null || progress.durChapterIndex < it.durChapterIndex ||
|
if (progress == null || progress.durChapterIndex < it.durChapterIndex ||
|
||||||
(progress.durChapterIndex == it.durChapterIndex
|
(progress.durChapterIndex == it.durChapterIndex
|
||||||
&& progress.durChapterPos < it.durChapterPos)) {
|
&& progress.durChapterPos < it.durChapterPos)
|
||||||
|
) {
|
||||||
// 服务器没有进度或者进度比服务器快,上传现有进度
|
// 服务器没有进度或者进度比服务器快,上传现有进度
|
||||||
Coroutine.async {
|
Coroutine.async {
|
||||||
AppWebDav.uploadBookProgress(BookProgress(it), uploadSuccessAction)
|
AppWebDav.uploadBookProgress(BookProgress(it), uploadSuccessAction)
|
||||||
it.save()
|
it.update()
|
||||||
}
|
}
|
||||||
} else if (progress.durChapterIndex > it.durChapterIndex ||
|
} else if (progress.durChapterIndex > it.durChapterIndex ||
|
||||||
progress.durChapterPos > it.durChapterPos) {
|
progress.durChapterPos > it.durChapterPos
|
||||||
|
) {
|
||||||
// 进度比服务器慢,执行传入动作
|
// 进度比服务器慢,执行传入动作
|
||||||
newProgressAction?.invoke(progress)
|
newProgressAction?.invoke(progress)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -7,7 +7,13 @@ import android.content.res.Configuration
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.view.*
|
import android.view.Gravity
|
||||||
|
import android.view.InputDevice
|
||||||
|
import android.view.KeyEvent
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuItem
|
||||||
|
import android.view.MotionEvent
|
||||||
|
import android.view.View
|
||||||
import androidx.activity.addCallback
|
import androidx.activity.addCallback
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
@@ -19,7 +25,12 @@ import androidx.lifecycle.lifecycleScope
|
|||||||
import com.jaredrummler.android.colorpicker.ColorPickerDialogListener
|
import com.jaredrummler.android.colorpicker.ColorPickerDialogListener
|
||||||
import io.legado.app.BuildConfig
|
import io.legado.app.BuildConfig
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.constant.*
|
import io.legado.app.constant.AppConst
|
||||||
|
import io.legado.app.constant.AppLog
|
||||||
|
import io.legado.app.constant.BookType
|
||||||
|
import io.legado.app.constant.EventBus
|
||||||
|
import io.legado.app.constant.PreferKey
|
||||||
|
import io.legado.app.constant.Status
|
||||||
import io.legado.app.data.appDb
|
import io.legado.app.data.appDb
|
||||||
import io.legado.app.data.entities.Book
|
import io.legado.app.data.entities.Book
|
||||||
import io.legado.app.data.entities.BookChapter
|
import io.legado.app.data.entities.BookChapter
|
||||||
@@ -29,7 +40,14 @@ import io.legado.app.exception.NoStackTraceException
|
|||||||
import io.legado.app.help.AppWebDav
|
import io.legado.app.help.AppWebDav
|
||||||
import io.legado.app.help.IntentData
|
import io.legado.app.help.IntentData
|
||||||
import io.legado.app.help.TTS
|
import io.legado.app.help.TTS
|
||||||
import io.legado.app.help.book.*
|
import io.legado.app.help.book.BookHelp
|
||||||
|
import io.legado.app.help.book.ContentProcessor
|
||||||
|
import io.legado.app.help.book.isAudio
|
||||||
|
import io.legado.app.help.book.isEpub
|
||||||
|
import io.legado.app.help.book.isLocal
|
||||||
|
import io.legado.app.help.book.isLocalTxt
|
||||||
|
import io.legado.app.help.book.isMobi
|
||||||
|
import io.legado.app.help.book.removeType
|
||||||
import io.legado.app.help.config.AppConfig
|
import io.legado.app.help.config.AppConfig
|
||||||
import io.legado.app.help.config.ReadBookConfig
|
import io.legado.app.help.config.ReadBookConfig
|
||||||
import io.legado.app.help.config.ReadTipConfig
|
import io.legado.app.help.config.ReadTipConfig
|
||||||
@@ -42,9 +60,9 @@ import io.legado.app.lib.theme.accentColor
|
|||||||
import io.legado.app.model.ReadAloud
|
import io.legado.app.model.ReadAloud
|
||||||
import io.legado.app.model.ReadBook
|
import io.legado.app.model.ReadBook
|
||||||
import io.legado.app.model.analyzeRule.AnalyzeRule
|
import io.legado.app.model.analyzeRule.AnalyzeRule
|
||||||
import io.legado.app.receiver.NetworkChangedListener
|
|
||||||
import io.legado.app.model.localBook.EpubFile
|
import io.legado.app.model.localBook.EpubFile
|
||||||
import io.legado.app.model.localBook.MobiFile
|
import io.legado.app.model.localBook.MobiFile
|
||||||
|
import io.legado.app.receiver.NetworkChangedListener
|
||||||
import io.legado.app.receiver.TimeBatteryReceiver
|
import io.legado.app.receiver.TimeBatteryReceiver
|
||||||
import io.legado.app.service.BaseReadAloudService
|
import io.legado.app.service.BaseReadAloudService
|
||||||
import io.legado.app.ui.about.AppLogDialog
|
import io.legado.app.ui.about.AppLogDialog
|
||||||
@@ -53,7 +71,7 @@ import io.legado.app.ui.book.bookmark.BookmarkDialog
|
|||||||
import io.legado.app.ui.book.changesource.ChangeBookSourceDialog
|
import io.legado.app.ui.book.changesource.ChangeBookSourceDialog
|
||||||
import io.legado.app.ui.book.changesource.ChangeChapterSourceDialog
|
import io.legado.app.ui.book.changesource.ChangeChapterSourceDialog
|
||||||
import io.legado.app.ui.book.info.BookInfoActivity
|
import io.legado.app.ui.book.info.BookInfoActivity
|
||||||
import io.legado.app.ui.book.read.config.*
|
import io.legado.app.ui.book.read.config.AutoReadDialog
|
||||||
import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.BG_COLOR
|
import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.BG_COLOR
|
||||||
import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.TEXT_COLOR
|
import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.TEXT_COLOR
|
||||||
import io.legado.app.ui.book.read.config.MoreConfigDialog
|
import io.legado.app.ui.book.read.config.MoreConfigDialog
|
||||||
@@ -80,10 +98,40 @@ import io.legado.app.ui.replace.ReplaceRuleActivity
|
|||||||
import io.legado.app.ui.replace.edit.ReplaceEditActivity
|
import io.legado.app.ui.replace.edit.ReplaceEditActivity
|
||||||
import io.legado.app.ui.widget.PopupAction
|
import io.legado.app.ui.widget.PopupAction
|
||||||
import io.legado.app.ui.widget.dialog.PhotoDialog
|
import io.legado.app.ui.widget.dialog.PhotoDialog
|
||||||
import io.legado.app.utils.*
|
import io.legado.app.utils.ACache
|
||||||
|
import io.legado.app.utils.Debounce
|
||||||
|
import io.legado.app.utils.LogUtils
|
||||||
|
import io.legado.app.utils.NetworkUtils
|
||||||
|
import io.legado.app.utils.StartActivityContract
|
||||||
|
import io.legado.app.utils.applyOpenTint
|
||||||
|
import io.legado.app.utils.buildMainHandler
|
||||||
|
import io.legado.app.utils.getPrefBoolean
|
||||||
|
import io.legado.app.utils.getPrefString
|
||||||
|
import io.legado.app.utils.hexString
|
||||||
|
import io.legado.app.utils.iconItemOnLongClick
|
||||||
|
import io.legado.app.utils.invisible
|
||||||
|
import io.legado.app.utils.isAbsUrl
|
||||||
|
import io.legado.app.utils.isTrue
|
||||||
|
import io.legado.app.utils.launch
|
||||||
|
import io.legado.app.utils.navigationBarGravity
|
||||||
|
import io.legado.app.utils.observeEvent
|
||||||
|
import io.legado.app.utils.observeEventSticky
|
||||||
|
import io.legado.app.utils.postEvent
|
||||||
|
import io.legado.app.utils.showDialogFragment
|
||||||
|
import io.legado.app.utils.showHelp
|
||||||
|
import io.legado.app.utils.startActivity
|
||||||
|
import io.legado.app.utils.sysScreenOffTime
|
||||||
|
import io.legado.app.utils.throttle
|
||||||
|
import io.legado.app.utils.toastOnUi
|
||||||
|
import io.legado.app.utils.visible
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
import kotlinx.coroutines.Dispatchers.Main
|
import kotlinx.coroutines.Dispatchers.Main
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.Runnable
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.ensureActive
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 阅读界面
|
* 阅读界面
|
||||||
@@ -297,7 +345,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
networkChangedListener.onNetworkChanged = {
|
networkChangedListener.onNetworkChanged = {
|
||||||
// 当网络是可用状态且无需初始化时同步进度(初始化中已有同步进度逻辑)
|
// 当网络是可用状态且无需初始化时同步进度(初始化中已有同步进度逻辑)
|
||||||
if (AppConfig.syncBookProgressPlus && NetworkUtils.isAvailable() && !justInitData) {
|
if (AppConfig.syncBookProgressPlus && NetworkUtils.isAvailable() && !justInitData) {
|
||||||
ReadBook.syncProgress({progress -> sureNewProgress(progress)}, null)
|
ReadBook.syncProgress({ progress -> sureNewProgress(progress) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -782,6 +830,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
1 -> lifecycleScope.launch {
|
1 -> lifecycleScope.launch {
|
||||||
binding.readView.aloudStartSelect()
|
binding.readView.aloudStartSelect()
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> speak(binding.readView.getSelectText())
|
else -> speak(binding.readView.getSelectText())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
ReadBook.chapterChanged = false
|
ReadBook.chapterChanged = false
|
||||||
} else if (!isSameBook || !BaseReadAloudService.isRun) {
|
} else if (!isSameBook || !BaseReadAloudService.isRun) {
|
||||||
if (AppConfig.syncBookProgressPlus) {
|
if (AppConfig.syncBookProgressPlus) {
|
||||||
ReadBook.syncProgress({ progress -> ReadBook.callBack?.sureNewProgress(progress) }, null)
|
ReadBook.syncProgress({ progress -> ReadBook.callBack?.sureNewProgress(progress) })
|
||||||
} else {
|
} else {
|
||||||
syncBookProgress(book)
|
syncBookProgress(book)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -169,11 +169,15 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
val insets =
|
val insets = this.rootWindowInsets.getInsetsIgnoringVisibility(
|
||||||
this.rootWindowInsets.getInsetsIgnoringVisibility(WindowInsets.Type.mandatorySystemGestures())
|
WindowInsets.Type.mandatorySystemGestures()
|
||||||
|
)
|
||||||
val height = activity?.windowManager?.currentWindowMetrics?.bounds?.height()
|
val height = activity?.windowManager?.currentWindowMetrics?.bounds?.height()
|
||||||
if (height != null) {
|
if (height != null) {
|
||||||
if (event.y > height.minus(insets.bottom) && event.action != MotionEvent.ACTION_UP && event.action != MotionEvent.ACTION_CANCEL) {
|
if (event.y > height.minus(insets.bottom)
|
||||||
|
&& event.action != MotionEvent.ACTION_UP
|
||||||
|
&& event.action != MotionEvent.ACTION_CANCEL
|
||||||
|
) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -437,7 +441,8 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
9 -> callBack.changeReplaceRuleState()
|
9 -> callBack.changeReplaceRuleState()
|
||||||
10 -> callBack.openChapterList()
|
10 -> callBack.openChapterList()
|
||||||
11 -> callBack.openSearchActivity(null)
|
11 -> callBack.openSearchActivity(null)
|
||||||
12 -> ReadBook.syncProgress({progress -> callBack.sureNewProgress(progress)},
|
12 -> ReadBook.syncProgress(
|
||||||
|
{ progress -> callBack.sureNewProgress(progress) },
|
||||||
{ context.longToastOnUi(context.getString(R.string.upload_book_success)) },
|
{ context.longToastOnUi(context.getString(R.string.upload_book_success)) },
|
||||||
{ context.longToastOnUi(context.getString(R.string.sync_book_progress_success)) })
|
{ context.longToastOnUi(context.getString(R.string.sync_book_progress_success)) })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user