优化
This commit is contained in:
@@ -58,6 +58,9 @@ interface BookGroupDao {
|
||||
@get:Query("SELECT * FROM book_groups ORDER BY `order`")
|
||||
val all: List<BookGroup>
|
||||
|
||||
@get:Query("select count(*) < 64 from book_groups where groupId >= 0 or groupId == ${Long.MIN_VALUE}")
|
||||
val canAddGroup: Boolean
|
||||
|
||||
@Query("update book_groups set show = 1 where groupId = :groupId")
|
||||
fun enableGroup(groupId: Long)
|
||||
|
||||
|
||||
@@ -77,24 +77,23 @@ class TTS {
|
||||
}
|
||||
|
||||
private fun addTextToSpeakList() {
|
||||
textToSpeech?.let { tts ->
|
||||
kotlin.runCatching {
|
||||
var result = tts.speak("", TextToSpeech.QUEUE_FLUSH, null, null)
|
||||
if (result == TextToSpeech.ERROR) {
|
||||
clearTts()
|
||||
textToSpeech = TextToSpeech(appCtx, initListener)
|
||||
return
|
||||
}
|
||||
text?.splitNotBlank("\n")?.forEachIndexed { i, s ->
|
||||
result = tts.speak(s, TextToSpeech.QUEUE_ADD, null, tag + i)
|
||||
if (result == TextToSpeech.ERROR) {
|
||||
AppLog.put("tts朗读出错:$text")
|
||||
}
|
||||
}
|
||||
}.onFailure {
|
||||
AppLog.put("tts朗读出错", it)
|
||||
appCtx.toastOnUi(it.localizedMessage)
|
||||
val tts = textToSpeech ?: return
|
||||
kotlin.runCatching {
|
||||
var result = tts.speak("", TextToSpeech.QUEUE_FLUSH, null, null)
|
||||
if (result == TextToSpeech.ERROR) {
|
||||
clearTts()
|
||||
textToSpeech = TextToSpeech(appCtx, initListener)
|
||||
return
|
||||
}
|
||||
text?.splitNotBlank("\n")?.forEachIndexed { i, s ->
|
||||
result = tts.speak(s, TextToSpeech.QUEUE_ADD, null, tag + i)
|
||||
if (result == TextToSpeech.ERROR) {
|
||||
AppLog.put("tts朗读出错:$text")
|
||||
}
|
||||
}
|
||||
}.onFailure {
|
||||
AppLog.put("tts朗读出错", it)
|
||||
appCtx.toastOnUi(it.localizedMessage)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import androidx.documentfile.provider.DocumentFile
|
||||
import io.legado.app.constant.AppLog
|
||||
import io.legado.app.constant.PreferKey
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.exception.NoStackTraceException
|
||||
import io.legado.app.help.AppWebDav
|
||||
import io.legado.app.help.DirectLinkUpload
|
||||
import io.legado.app.help.config.AppConfig
|
||||
@@ -186,6 +187,7 @@ object Backup {
|
||||
}
|
||||
AppWebDav.backUpWebDav(zipFileName)
|
||||
}
|
||||
FileUtils.delete(backupPath)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,12 +205,15 @@ object Backup {
|
||||
@Throws(Exception::class)
|
||||
@Suppress("SameParameterValue")
|
||||
private fun copyBackup(context: Context, uri: Uri, fileName: String) {
|
||||
DocumentFile.fromTreeUri(context, uri)?.let { treeDoc ->
|
||||
treeDoc.findFile(fileName)?.delete()
|
||||
treeDoc.createFile("", fileName)?.openOutputStream()?.use { outputS ->
|
||||
FileInputStream(File(zipFilePath)).use { inputS ->
|
||||
inputS.copyTo(outputS)
|
||||
}
|
||||
val treeDoc = DocumentFile.fromTreeUri(context, uri)!!
|
||||
treeDoc.findFile(fileName)?.delete()
|
||||
val fileDoc = treeDoc.createFile("", fileName)
|
||||
?: throw NoStackTraceException("创建文件失败")
|
||||
val outputS = fileDoc.openOutputStream()
|
||||
?: throw NoStackTraceException("打开OutputStream失败")
|
||||
outputS.use {
|
||||
FileInputStream(zipFilePath).use { inputS ->
|
||||
inputS.copyTo(outputS)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import io.legado.app.ui.widget.recycler.VerticalDivider
|
||||
import io.legado.app.utils.applyTint
|
||||
import io.legado.app.utils.setLayout
|
||||
import io.legado.app.utils.showDialogFragment
|
||||
import io.legado.app.utils.toastOnUi
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
import io.legado.app.utils.visible
|
||||
import kotlinx.coroutines.flow.conflate
|
||||
@@ -82,7 +83,13 @@ class GroupManageDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
|
||||
|
||||
override fun onMenuItemClick(item: MenuItem?): Boolean {
|
||||
when (item?.itemId) {
|
||||
R.id.menu_add -> showDialogFragment(GroupEditDialog())
|
||||
R.id.menu_add -> {
|
||||
if (appDb.bookGroupDao.canAddGroup) {
|
||||
showDialogFragment(GroupEditDialog())
|
||||
} else {
|
||||
toastOnUi("分组已达上限(64个)")
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user