pull/921/head
gedoor 4 years ago
parent fc03db2ebb
commit 6cda4f49af
  1. 3
      app/src/main/assets/updateLog.md
  2. 10
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt
  3. 6
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt
  4. 24
      app/src/main/java/io/legado/app/utils/UriExtensions.kt
  5. 5
      app/src/main/res/menu/speak_engine.xml

@ -3,9 +3,10 @@
* 关注合作公众号 **[小说拾遗]** 获取好看的小说。
* 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。
**2021/03/26**
**2021/03/31**
* 优化epubLib by ag2s20150909
* 升级库,修改弃用方法
* tts引擎添加导入导出功能
**2021/03/23**
* 修复繁简转换“勐”“十”问题。使用了剥离HanLP简繁代码的民间库。APK减少6M左右

@ -41,11 +41,16 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
private val viewModel: SpeakEngineViewModel by viewModels()
private var httpTTSData: LiveData<List<HttpTTS>>? = null
private var engineId = appCtx.getPrefLong(PreferKey.speakEngine)
private val importDoc = registerForActivityResult(FilePicker()) {
private val importDocResult = registerForActivityResult(FilePicker()) {
it?.let {
viewModel.importLocal(it)
}
}
private val exportDirResult = registerForActivityResult(FilePicker()) {
it?.let {
viewModel.export(it)
}
}
override fun onStart() {
super.onStart()
@ -109,13 +114,14 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
when (item?.itemId) {
R.id.menu_add -> editHttpTTS()
R.id.menu_default -> viewModel.importDefault()
R.id.menu_import_local -> importDoc.launch(
R.id.menu_import_local -> importDocResult.launch(
FilePickerParam(
mode = FilePicker.FILE,
allowExtensions = arrayOf("txt", "json")
)
)
R.id.menu_import_onLine -> importAlert()
R.id.menu_export -> exportDirResult.launch(null)
}
return true
}

@ -60,4 +60,10 @@ class SpeakEngineViewModel(application: Application) : BaseViewModel(application
}
}
fun export(uri: Uri) {
execute {
val httpTTS = appDb.httpTTSDao.all
uri.writeBytes(context, "httpTts.json", GSON.toJson(httpTTS).toByteArray())
}
}
}

@ -2,13 +2,14 @@ package io.legado.app.utils
import android.content.Context
import android.net.Uri
import androidx.documentfile.provider.DocumentFile
import java.io.File
fun Uri.isContentScheme() = this.scheme == "content"
@Throws(Exception::class)
fun Uri.readBytes(context: Context): ByteArray? {
if (this.toString().isContentScheme()) {
if (this.isContentScheme()) {
return DocumentUtils.readBytes(context, this)
} else {
val path = RealPathUtil.getPath(context, this)
@ -32,7 +33,7 @@ fun Uri.writeBytes(
context: Context,
byteArray: ByteArray
): Boolean {
if (this.toString().isContentScheme()) {
if (this.isContentScheme()) {
return DocumentUtils.writeBytes(context, byteArray, this)
} else {
val path = RealPathUtil.getPath(context, this)
@ -48,3 +49,22 @@ fun Uri.writeBytes(
fun Uri.writeText(context: Context, text: String): Boolean {
return writeBytes(context, text.toByteArray())
}
fun Uri.writeBytes(
context: Context,
fileName: String,
byteArray: ByteArray
): Boolean {
if (this.isContentScheme()) {
DocumentFile.fromTreeUri(context, this)?.let { pDoc ->
DocumentUtils.createFileIfNotExist(pDoc, fileName)?.let {
return it.uri.writeBytes(context, byteArray)
}
}
} else {
FileUtils.createFileWithReplace(path + File.separatorChar + fileName)
.writeBytes(byteArray)
return true
}
return false
}

@ -25,4 +25,9 @@
android:title="@string/import_on_line"
app:showAsAction="never" />
<item
android:id="@+id/menu_export"
android:title="@string/export"
app:showAsAction="never" />
</menu>
Loading…
Cancel
Save