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