优化
This commit is contained in:
@@ -192,8 +192,9 @@ data class BookSource(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun equal(source: BookSource) =
|
fun equal(source: BookSource?): Boolean {
|
||||||
equal(bookSourceName, source.bookSourceName)
|
source ?: return false
|
||||||
|
return equal(bookSourceName, source.bookSourceName)
|
||||||
&& equal(bookSourceUrl, source.bookSourceUrl)
|
&& equal(bookSourceUrl, source.bookSourceUrl)
|
||||||
&& equal(bookSourceGroup, source.bookSourceGroup)
|
&& equal(bookSourceGroup, source.bookSourceGroup)
|
||||||
&& bookSourceType == source.bookSourceType
|
&& bookSourceType == source.bookSourceType
|
||||||
@@ -216,6 +217,7 @@ data class BookSource(
|
|||||||
&& getBookInfoRule() == source.getBookInfoRule()
|
&& getBookInfoRule() == source.getBookInfoRule()
|
||||||
&& getTocRule() == source.getTocRule()
|
&& getTocRule() == source.getTocRule()
|
||||||
&& getContentRule() == source.getContentRule()
|
&& getContentRule() == source.getContentRule()
|
||||||
|
}
|
||||||
|
|
||||||
private fun equal(a: String?, b: String?) = a == b || (a.isNullOrEmpty() && b.isNullOrEmpty())
|
private fun equal(a: String?, b: String?) = a == b || (a.isNullOrEmpty() && b.isNullOrEmpty())
|
||||||
|
|
||||||
|
|||||||
@@ -101,7 +101,8 @@ data class RssSource(
|
|||||||
|
|
||||||
override fun hashCode() = sourceUrl.hashCode()
|
override fun hashCode() = sourceUrl.hashCode()
|
||||||
|
|
||||||
fun equal(source: RssSource): Boolean {
|
fun equal(source: RssSource?): Boolean {
|
||||||
|
source ?: return false
|
||||||
return equal(sourceUrl, source.sourceUrl)
|
return equal(sourceUrl, source.sourceUrl)
|
||||||
&& equal(sourceIcon, source.sourceIcon)
|
&& equal(sourceIcon, source.sourceIcon)
|
||||||
&& enabled == source.enabled
|
&& enabled == source.enabled
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ class BookSourceEditActivity :
|
|||||||
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.menu_save -> getSource().let { source ->
|
R.id.menu_save -> getSource().let { source ->
|
||||||
if (!source.equal(viewModel.bookSource ?: BookSource())) {
|
if (!source.equal(viewModel.bookSource)) {
|
||||||
source.lastUpdateTime = System.currentTimeMillis()
|
source.lastUpdateTime = System.currentTimeMillis()
|
||||||
}
|
}
|
||||||
if (checkSource(source)) {
|
if (checkSource(source)) {
|
||||||
@@ -192,12 +192,7 @@ class BookSourceEditActivity :
|
|||||||
|
|
||||||
override fun finish() {
|
override fun finish() {
|
||||||
val source = getSource()
|
val source = getSource()
|
||||||
val source2 = viewModel.bookSource ?: BookSource().apply {
|
if (!source.equal(viewModel.bookSource)) {
|
||||||
enabledExplore = true
|
|
||||||
enabledCookieJar = true
|
|
||||||
enabledReview = true
|
|
||||||
}
|
|
||||||
if (!source.equal(source2)) {
|
|
||||||
alert(R.string.exit) {
|
alert(R.string.exit) {
|
||||||
setMessage(R.string.exit_no_save)
|
setMessage(R.string.exit_no_save)
|
||||||
positiveButton(R.string.yes)
|
positiveButton(R.string.yes)
|
||||||
@@ -599,7 +594,7 @@ class BookSourceEditActivity :
|
|||||||
launch {
|
launch {
|
||||||
val source = viewModel.bookSource
|
val source = viewModel.bookSource
|
||||||
if (source == null) {
|
if (source == null) {
|
||||||
toastOnUi("书源不存在")
|
toastOnUi("先保存书源")
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
val variable = withContext(IO) { source.getVariable() }
|
val variable = withContext(IO) { source.getVariable() }
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
class BookSourceEditViewModel(application: Application) : BaseViewModel(application) {
|
class BookSourceEditViewModel(application: Application) : BaseViewModel(application) {
|
||||||
var autoComplete = false
|
var autoComplete = false
|
||||||
var bookSource: BookSource? = null
|
var bookSource: BookSource? = null
|
||||||
private var oldSourceUrl: String? = null
|
|
||||||
|
|
||||||
fun initData(intent: Intent, onFinally: () -> Unit) {
|
fun initData(intent: Intent, onFinally: () -> Unit) {
|
||||||
execute {
|
execute {
|
||||||
@@ -28,7 +27,6 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat
|
|||||||
source = appDb.bookSourceDao.getBookSource(sourceUrl)
|
source = appDb.bookSourceDao.getBookSource(sourceUrl)
|
||||||
}
|
}
|
||||||
source?.let {
|
source?.let {
|
||||||
oldSourceUrl = it.bookSourceUrl
|
|
||||||
bookSource = it
|
bookSource = it
|
||||||
}
|
}
|
||||||
}.onFinally {
|
}.onFinally {
|
||||||
@@ -38,13 +36,10 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat
|
|||||||
|
|
||||||
fun save(source: BookSource, success: (() -> Unit)? = null) {
|
fun save(source: BookSource, success: (() -> Unit)? = null) {
|
||||||
execute {
|
execute {
|
||||||
oldSourceUrl?.let {
|
bookSource?.let {
|
||||||
if (oldSourceUrl != source.bookSourceUrl) {
|
appDb.bookSourceDao.delete(it)
|
||||||
appDb.bookSourceDao.delete(it)
|
SourceConfig.removeSource(it.bookSourceUrl)
|
||||||
SourceConfig.removeSource(it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
oldSourceUrl = source.bookSourceUrl
|
|
||||||
source.lastUpdateTime = System.currentTimeMillis()
|
source.lastUpdateTime = System.currentTimeMillis()
|
||||||
appDb.bookSourceDao.insert(source)
|
appDb.bookSourceDao.insert(source)
|
||||||
bookSource = source
|
bookSource = source
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ class RssSourceEditActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onMenuOpened(featureId: Int, menu: Menu): Boolean {
|
override fun onMenuOpened(featureId: Int, menu: Menu): Boolean {
|
||||||
menu.findItem(R.id.menu_login)?.isVisible = !viewModel.rssSource.loginUrl.isNullOrBlank()
|
menu.findItem(R.id.menu_login)?.isVisible = !viewModel.rssSource?.loginUrl.isNullOrBlank()
|
||||||
menu.findItem(R.id.menu_auto_complete)?.isChecked = viewModel.autoComplete
|
menu.findItem(R.id.menu_auto_complete)?.isChecked = viewModel.autoComplete
|
||||||
return super.onMenuOpened(featureId, menu)
|
return super.onMenuOpened(featureId, menu)
|
||||||
}
|
}
|
||||||
@@ -251,7 +251,7 @@ class RssSourceEditActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getRssSource(): RssSource {
|
private fun getRssSource(): RssSource {
|
||||||
val source = viewModel.rssSource
|
val source = viewModel.rssSource?.copy() ?: RssSource()
|
||||||
source.enabled = binding.cbIsEnable.isChecked
|
source.enabled = binding.cbIsEnable.isChecked
|
||||||
source.singleUrl = binding.cbSingleUrl.isChecked
|
source.singleUrl = binding.cbSingleUrl.isChecked
|
||||||
source.enabledCookieJar = binding.cbIsEnableCookie.isChecked
|
source.enabledCookieJar = binding.cbIsEnableCookie.isChecked
|
||||||
|
|||||||
@@ -17,8 +17,7 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
|
|
||||||
class RssSourceEditViewModel(application: Application) : BaseViewModel(application) {
|
class RssSourceEditViewModel(application: Application) : BaseViewModel(application) {
|
||||||
var autoComplete = false
|
var autoComplete = false
|
||||||
var rssSource: RssSource = RssSource()
|
var rssSource: RssSource? = null
|
||||||
private var oldSourceUrl: String = ""
|
|
||||||
|
|
||||||
fun initData(intent: Intent, onFinally: () -> Unit) {
|
fun initData(intent: Intent, onFinally: () -> Unit) {
|
||||||
execute {
|
execute {
|
||||||
@@ -28,7 +27,6 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati
|
|||||||
rssSource = it
|
rssSource = it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
oldSourceUrl = rssSource.sourceUrl
|
|
||||||
}.onFinally {
|
}.onFinally {
|
||||||
onFinally()
|
onFinally()
|
||||||
}
|
}
|
||||||
@@ -36,11 +34,11 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati
|
|||||||
|
|
||||||
fun save(source: RssSource, success: (() -> Unit)) {
|
fun save(source: RssSource, success: (() -> Unit)) {
|
||||||
execute {
|
execute {
|
||||||
if (oldSourceUrl != source.sourceUrl) {
|
rssSource?.let {
|
||||||
appDb.rssSourceDao.delete(oldSourceUrl)
|
appDb.rssSourceDao.delete(it)
|
||||||
oldSourceUrl = source.sourceUrl
|
|
||||||
}
|
}
|
||||||
appDb.rssSourceDao.insert(source)
|
appDb.rssSourceDao.insert(source)
|
||||||
|
rssSource = source
|
||||||
}.onSuccess {
|
}.onSuccess {
|
||||||
success()
|
success()
|
||||||
}.onError {
|
}.onError {
|
||||||
|
|||||||
Reference in New Issue
Block a user