|
|
@ -8,24 +8,23 @@ import io.legado.app.data.entities.RssSource |
|
|
|
import io.legado.app.utils.GSON |
|
|
|
import io.legado.app.utils.GSON |
|
|
|
import io.legado.app.utils.fromJsonObject |
|
|
|
import io.legado.app.utils.fromJsonObject |
|
|
|
import io.legado.app.utils.getClipText |
|
|
|
import io.legado.app.utils.getClipText |
|
|
|
|
|
|
|
import io.legado.app.utils.msg |
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
|
|
|
|
|
|
|
|
class RssSourceEditViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
class RssSourceEditViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
|
|
|
|
|
|
|
var rssSource: RssSource? = null |
|
|
|
var rssSource: RssSource = RssSource() |
|
|
|
private var oldSourceUrl: String? = null |
|
|
|
private var oldSourceUrl: String = "" |
|
|
|
|
|
|
|
|
|
|
|
fun initData(intent: Intent, onFinally: () -> Unit) { |
|
|
|
fun initData(intent: Intent, onFinally: () -> Unit) { |
|
|
|
execute { |
|
|
|
execute { |
|
|
|
val key = intent.getStringExtra("data") |
|
|
|
val key = intent.getStringExtra("data") |
|
|
|
var source: RssSource? = null |
|
|
|
|
|
|
|
if (key != null) { |
|
|
|
if (key != null) { |
|
|
|
source = App.db.rssSourceDao().getByKey(key) |
|
|
|
App.db.rssSourceDao().getByKey(key)?.let { |
|
|
|
} |
|
|
|
rssSource = it |
|
|
|
source?.let { |
|
|
|
} |
|
|
|
oldSourceUrl = it.sourceUrl |
|
|
|
|
|
|
|
rssSource = it |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
oldSourceUrl = rssSource.sourceUrl |
|
|
|
}.onFinally { |
|
|
|
}.onFinally { |
|
|
|
onFinally() |
|
|
|
onFinally() |
|
|
|
} |
|
|
|
} |
|
|
@ -33,14 +32,11 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati |
|
|
|
|
|
|
|
|
|
|
|
fun save(source: RssSource, success: (() -> Unit)) { |
|
|
|
fun save(source: RssSource, success: (() -> Unit)) { |
|
|
|
execute { |
|
|
|
execute { |
|
|
|
oldSourceUrl?.let { |
|
|
|
if (oldSourceUrl != source.sourceUrl) { |
|
|
|
if (oldSourceUrl != source.sourceUrl) { |
|
|
|
App.db.rssSourceDao().delete(oldSourceUrl) |
|
|
|
App.db.rssSourceDao().delete(it) |
|
|
|
oldSourceUrl = source.sourceUrl |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
oldSourceUrl = source.sourceUrl |
|
|
|
|
|
|
|
App.db.rssSourceDao().insert(source) |
|
|
|
App.db.rssSourceDao().insert(source) |
|
|
|
rssSource = source |
|
|
|
|
|
|
|
}.onSuccess { |
|
|
|
}.onSuccess { |
|
|
|
success() |
|
|
|
success() |
|
|
|
}.onError { |
|
|
|
}.onError { |
|
|
@ -74,7 +70,7 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati |
|
|
|
finally.invoke(it) |
|
|
|
finally.invoke(it) |
|
|
|
} |
|
|
|
} |
|
|
|
}.onError { |
|
|
|
}.onError { |
|
|
|
toast(it.localizedMessage ?: "Error") |
|
|
|
toast(it.msg) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|