|
|
@ -36,12 +36,15 @@ import splitties.init.appCtx |
|
|
|
|
|
|
|
|
|
|
|
class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { |
|
|
|
class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { |
|
|
|
private val binding by viewBinding(DialogRecyclerViewBinding::bind) |
|
|
|
private val binding by viewBinding(DialogRecyclerViewBinding::bind) |
|
|
|
|
|
|
|
private val ttsUrlKey = "ttsUrlKey" |
|
|
|
lateinit var adapter: Adapter |
|
|
|
lateinit var adapter: Adapter |
|
|
|
private val viewModel: SpeakEngineViewModel by viewModels() |
|
|
|
private val viewModel: SpeakEngineViewModel by viewModels() |
|
|
|
private var httpTTSData: LiveData<List<HttpTTS>>? = null |
|
|
|
private var httpTTSData: LiveData<List<HttpTTS>>? = null |
|
|
|
var engineId = appCtx.getPrefLong(PreferKey.speakEngine) |
|
|
|
private var engineId = appCtx.getPrefLong(PreferKey.speakEngine) |
|
|
|
private val importDoc = registerForActivityResult(FilePicker()) { |
|
|
|
private val importDoc = registerForActivityResult(FilePicker()) { |
|
|
|
|
|
|
|
it?.let { |
|
|
|
|
|
|
|
viewModel.importLocal(it) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onStart() { |
|
|
|
override fun onStart() { |
|
|
@ -112,20 +115,38 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener |
|
|
|
allowExtensions = arrayOf("txt", "json") |
|
|
|
allowExtensions = arrayOf("txt", "json") |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
R.id.menu_import_onLine -> alert(R.string.import_on_line) { |
|
|
|
R.id.menu_import_onLine -> importAlert() |
|
|
|
val alertBinding = DialogEditTextBinding.inflate(layoutInflater) |
|
|
|
|
|
|
|
customView { alertBinding.root } |
|
|
|
|
|
|
|
okButton { |
|
|
|
|
|
|
|
alertBinding.editView.text?.toString()?.let { url -> |
|
|
|
|
|
|
|
viewModel.importOnLine(url) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}.show() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun importAlert() { |
|
|
|
|
|
|
|
val aCache = ACache.get(requireContext(), cacheDir = false) |
|
|
|
|
|
|
|
val cacheUrls: MutableList<String> = aCache |
|
|
|
|
|
|
|
.getAsString(ttsUrlKey) |
|
|
|
|
|
|
|
?.splitNotBlank(",") |
|
|
|
|
|
|
|
?.toMutableList() ?: mutableListOf() |
|
|
|
|
|
|
|
alert(R.string.import_on_line) { |
|
|
|
|
|
|
|
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { |
|
|
|
|
|
|
|
editView.setFilterValues(cacheUrls) |
|
|
|
|
|
|
|
editView.delCallBack = { |
|
|
|
|
|
|
|
cacheUrls.remove(it) |
|
|
|
|
|
|
|
aCache.put(ttsUrlKey, cacheUrls.joinToString(",")) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
customView { alertBinding.root } |
|
|
|
|
|
|
|
okButton { |
|
|
|
|
|
|
|
alertBinding.editView.text?.toString()?.let { url -> |
|
|
|
|
|
|
|
if (!cacheUrls.contains(url)) { |
|
|
|
|
|
|
|
cacheUrls.add(0, url) |
|
|
|
|
|
|
|
aCache.put(ttsUrlKey, cacheUrls.joinToString(",")) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
viewModel.importOnLine(url) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}.show() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("InflateParams") |
|
|
|
@SuppressLint("InflateParams") |
|
|
|
private fun editHttpTTS(v: HttpTTS? = null) { |
|
|
|
private fun editHttpTTS(v: HttpTTS? = null) { |
|
|
|
val httpTTS = v?.copy() ?: HttpTTS() |
|
|
|
val httpTTS = v?.copy() ?: HttpTTS() |
|
|
@ -190,7 +211,6 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |