mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -19,6 +19,7 @@ import io.legado.app.help.http.CookieStore
|
||||
import io.legado.app.help.http.SSLHelper
|
||||
import io.legado.app.help.http.StrResponse
|
||||
import io.legado.app.help.source.SourceVerificationHelp
|
||||
import io.legado.app.help.source.getSourceType
|
||||
import io.legado.app.model.Debug
|
||||
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
||||
import io.legado.app.model.analyzeRule.QueryTTF
|
||||
@@ -984,6 +985,7 @@ interface JsExtensions : JsEncodeUtils {
|
||||
putExtra("mimeType", mimeType)
|
||||
putExtra("sourceOrigin", source.getKey())
|
||||
putExtra("sourceName", source.getTag())
|
||||
putExtra("sourceType", source.getSourceType())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,6 @@ fun BaseSource.getSourceType(): Int {
|
||||
return when (this) {
|
||||
is BookSource -> SourceType.book
|
||||
is RssSource -> SourceType.rss
|
||||
else -> error("unknown source type.")
|
||||
else -> error("unknown source type: ${this::class.simpleName}.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.legado.app.data.appDb
|
||||
import io.legado.app.data.entities.BaseSource
|
||||
import io.legado.app.data.entities.BookSource
|
||||
import io.legado.app.data.entities.RssSource
|
||||
import io.legado.app.help.config.SourceConfig
|
||||
import io.legado.app.help.coroutine.Coroutine
|
||||
import io.legado.app.model.AudioPlay
|
||||
import io.legado.app.model.ReadBook
|
||||
@@ -52,11 +53,16 @@ object SourceHelp {
|
||||
|
||||
fun deleteSource(key: String, @SourceType.Type type: Int) {
|
||||
when (type) {
|
||||
SourceType.book -> appDb.bookSourceDao.delete(key)
|
||||
SourceType.book -> deleteBookSource(key)
|
||||
SourceType.rss -> appDb.rssSourceDao.delete(key)
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteBookSource(key: String) {
|
||||
appDb.bookSourceDao.delete(key)
|
||||
SourceConfig.removeSource(key)
|
||||
}
|
||||
|
||||
fun enableSource(key: String, @SourceType.Type type: Int, enable: Boolean) {
|
||||
when (type) {
|
||||
SourceType.book -> appDb.bookSourceDao.enable(key, enable)
|
||||
|
||||
@@ -43,6 +43,7 @@ object SourceVerificationHelp {
|
||||
putExtra("imageUrl", url)
|
||||
putExtra("sourceOrigin", source.getKey())
|
||||
putExtra("sourceName", source.getTag())
|
||||
putExtra("sourceType", source.getSourceType())
|
||||
IntentData.put(getVerificationResultKey(source), Thread.currentThread())
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.legado.app.ui.association
|
||||
|
||||
import android.os.Bundle
|
||||
import io.legado.app.base.BaseActivity
|
||||
import io.legado.app.constant.SourceType
|
||||
import io.legado.app.databinding.ActivityTranslucenceBinding
|
||||
import io.legado.app.utils.showDialogFragment
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
@@ -16,7 +17,8 @@ class OpenUrlConfirmActivity :
|
||||
val mimeType = intent.getStringExtra("mimeType")
|
||||
val sourceOrigin = intent.getStringExtra("sourceOrigin")
|
||||
val sourceName = intent.getStringExtra("sourceName")
|
||||
showDialogFragment(OpenUrlConfirmDialog(it, mimeType, sourceOrigin, sourceName))
|
||||
val sourceType = intent.getIntExtra("sourceType", SourceType.book)
|
||||
showDialogFragment(OpenUrlConfirmDialog(it, mimeType, sourceOrigin, sourceName, sourceType))
|
||||
} ?: finish()
|
||||
}
|
||||
|
||||
|
||||
@@ -27,13 +27,15 @@ class OpenUrlConfirmDialog() : BaseDialogFragment(R.layout.dialog_open_url_confi
|
||||
uri: String,
|
||||
mimeType: String?,
|
||||
sourceOrigin: String? = null,
|
||||
sourceName: String? = null
|
||||
sourceName: String? = null,
|
||||
sourceType: Int
|
||||
) : this() {
|
||||
arguments = Bundle().apply {
|
||||
putString("uri", uri)
|
||||
putString("mimeType", mimeType)
|
||||
putString("sourceOrigin", sourceOrigin)
|
||||
putString("sourceName", sourceName)
|
||||
putInt("sourceType", sourceType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,9 @@ package io.legado.app.ui.association
|
||||
import android.app.Application
|
||||
import android.os.Bundle
|
||||
import io.legado.app.base.BaseViewModel
|
||||
import io.legado.app.constant.SourceType
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.help.source.SourceHelp
|
||||
|
||||
class OpenUrlConfirmViewModel(app: Application): BaseViewModel(app) {
|
||||
|
||||
@@ -11,17 +13,19 @@ class OpenUrlConfirmViewModel(app: Application): BaseViewModel(app) {
|
||||
var mimeType: String? = null
|
||||
var sourceOrigin = ""
|
||||
var sourceName = ""
|
||||
var sourceType = SourceType.book
|
||||
|
||||
fun initData(arguments: Bundle) {
|
||||
uri = arguments.getString("uri") ?: ""
|
||||
mimeType = arguments.getString("mimeType")
|
||||
sourceName = arguments.getString("sourceName") ?: ""
|
||||
sourceOrigin = arguments.getString("sourceOrigin") ?: ""
|
||||
sourceType = arguments.getInt("sourceType", SourceType.book)
|
||||
}
|
||||
|
||||
fun disableSource(block: () -> Unit) {
|
||||
execute {
|
||||
appDb.bookSourceDao.enable(sourceOrigin, false)
|
||||
SourceHelp.enableSource(sourceOrigin, sourceType, false)
|
||||
}.onSuccess {
|
||||
block.invoke()
|
||||
}
|
||||
@@ -29,7 +33,7 @@ class OpenUrlConfirmViewModel(app: Application): BaseViewModel(app) {
|
||||
|
||||
fun deleteSource(block: () -> Unit) {
|
||||
execute {
|
||||
appDb.bookSourceDao.delete(sourceOrigin)
|
||||
SourceHelp.deleteSource(sourceOrigin, sourceType)
|
||||
}.onSuccess {
|
||||
block.invoke()
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.legado.app.ui.association
|
||||
|
||||
import android.os.Bundle
|
||||
import io.legado.app.base.BaseActivity
|
||||
import io.legado.app.constant.SourceType
|
||||
import io.legado.app.databinding.ActivityTranslucenceBinding
|
||||
import io.legado.app.utils.showDialogFragment
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
@@ -18,8 +19,9 @@ class VerificationCodeActivity :
|
||||
intent.getStringExtra("imageUrl")?.let {
|
||||
val sourceOrigin = intent.getStringExtra("sourceOrigin")
|
||||
val sourceName = intent.getStringExtra("sourceName")
|
||||
val sourceType = intent.getIntExtra("sourceType", SourceType.book)
|
||||
showDialogFragment(
|
||||
VerificationCodeDialog(it, sourceOrigin, sourceName)
|
||||
VerificationCodeDialog(it, sourceOrigin, sourceName, sourceType)
|
||||
)
|
||||
} ?: finish()
|
||||
}
|
||||
|
||||
@@ -41,12 +41,14 @@ class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification
|
||||
constructor(
|
||||
imageUrl: String,
|
||||
sourceOrigin: String? = null,
|
||||
sourceName: String? = null
|
||||
sourceName: String? = null,
|
||||
sourceType: Int
|
||||
) : this() {
|
||||
arguments = Bundle().apply {
|
||||
putString("imageUrl", imageUrl)
|
||||
putString("sourceOrigin", sourceOrigin)
|
||||
putString("sourceName", sourceName)
|
||||
putInt("sourceType", sourceType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,21 +3,24 @@ package io.legado.app.ui.association
|
||||
import android.app.Application
|
||||
import android.os.Bundle
|
||||
import io.legado.app.base.BaseViewModel
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.constant.SourceType
|
||||
import io.legado.app.help.source.SourceHelp
|
||||
|
||||
class VerificationCodeViewModel(app: Application): BaseViewModel(app) {
|
||||
|
||||
var sourceOrigin = ""
|
||||
var sourceName = ""
|
||||
private var sourceType = SourceType.book
|
||||
|
||||
fun initData(arguments: Bundle) {
|
||||
sourceName = arguments.getString("sourceName") ?: ""
|
||||
sourceOrigin = arguments.getString("sourceOrigin") ?: ""
|
||||
sourceType = arguments.getInt("sourceType", SourceType.book)
|
||||
}
|
||||
|
||||
fun disableSource(block: () -> Unit) {
|
||||
execute {
|
||||
appDb.bookSourceDao.enable(sourceOrigin, false)
|
||||
SourceHelp.enableSource(sourceOrigin, sourceType, false)
|
||||
}.onSuccess {
|
||||
block.invoke()
|
||||
}
|
||||
@@ -25,7 +28,7 @@ class VerificationCodeViewModel(app: Application): BaseViewModel(app) {
|
||||
|
||||
fun deleteSource(block: () -> Unit) {
|
||||
execute {
|
||||
appDb.bookSourceDao.delete(sourceOrigin)
|
||||
SourceHelp.deleteSource(sourceOrigin, sourceType)
|
||||
}.onSuccess {
|
||||
block.invoke()
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ class FontSelectDialog : BaseDialogFragment(R.layout.dialog_font_select),
|
||||
}
|
||||
|
||||
private fun openFolder() {
|
||||
lifecycleScope.launch(Main) {
|
||||
lifecycleScope.launch {
|
||||
val defaultPath = "SD${File.separator}Fonts"
|
||||
selectFontDir.launch {
|
||||
otherActions = arrayListOf(SelectItem(defaultPath, -1))
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.legado.app.base.BaseViewModel
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.data.entities.BookSourcePart
|
||||
import io.legado.app.help.config.SourceConfig
|
||||
import io.legado.app.help.source.SourceHelp
|
||||
|
||||
class ExploreViewModel(application: Application) : BaseViewModel(application) {
|
||||
|
||||
@@ -18,8 +19,7 @@ class ExploreViewModel(application: Application) : BaseViewModel(application) {
|
||||
|
||||
fun deleteSource(source: BookSourcePart) {
|
||||
execute {
|
||||
appDb.bookSourceDao.delete(source.bookSourceUrl)
|
||||
SourceConfig.removeSource(source.bookSourceUrl)
|
||||
SourceHelp.deleteBookSource(source.bookSourceUrl)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.legado.app.ui.rss.source.edit
|
||||
|
||||
import android.app.Activity
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
@@ -127,7 +126,7 @@ class RssSourceEditActivity :
|
||||
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.menu_save -> viewModel.save(getRssSource()) {
|
||||
setResult(Activity.RESULT_OK)
|
||||
setResult(RESULT_OK)
|
||||
finish()
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,12 @@ import io.legado.app.data.entities.RssSource
|
||||
import io.legado.app.exception.NoStackTraceException
|
||||
import io.legado.app.help.RuleComplete
|
||||
import io.legado.app.help.http.CookieStore
|
||||
import io.legado.app.utils.*
|
||||
|
||||
import io.legado.app.utils.GSON
|
||||
import io.legado.app.utils.fromJsonObject
|
||||
import io.legado.app.utils.getClipText
|
||||
import io.legado.app.utils.printOnDebug
|
||||
import io.legado.app.utils.stackTraceStr
|
||||
import io.legado.app.utils.toastOnUi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
||||
|
||||
@@ -39,7 +43,7 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati
|
||||
rssSource?.let {
|
||||
appDb.rssSourceDao.delete(it)
|
||||
//更新收藏的源地址
|
||||
if (it.sourceUrl != source.sourceUrl){
|
||||
if (it.sourceUrl != source.sourceUrl) {
|
||||
appDb.rssStarDao.updateOrigin(source.sourceUrl, it.sourceUrl)
|
||||
appDb.rssArticleDao.updateOrigin(source.sourceUrl, it.sourceUrl)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user