|
|
@ -14,14 +14,15 @@ class SourceEditViewModel(application: Application) : BaseViewModel(application) |
|
|
|
|
|
|
|
|
|
|
|
fun setBookSource(key: String) { |
|
|
|
fun setBookSource(key: String) { |
|
|
|
launch(IO) { |
|
|
|
launch(IO) { |
|
|
|
App.db.bookSourceDao().findByKey(key)?.let { sourceLiveData.postValue(it) } |
|
|
|
App.db.bookSourceDao().findByKey(key)?.let { |
|
|
|
|
|
|
|
sourceLiveData.postValue(it) |
|
|
|
|
|
|
|
} ?: sourceLiveData.postValue(BookSource()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun save(bookSource: BookSource, finally: (() -> Unit)? = null) { |
|
|
|
fun save(bookSource: BookSource, finally: (() -> Unit)? = null) { |
|
|
|
launch(IO) { |
|
|
|
launch(IO) { |
|
|
|
val source = App.db.bookSourceDao().findByKey(bookSource.bookSourceUrl) |
|
|
|
if (bookSource.customOrder == 0) { |
|
|
|
if (source == null) { |
|
|
|
|
|
|
|
bookSource.customOrder = App.db.bookSourceDao().allCount() |
|
|
|
bookSource.customOrder = App.db.bookSourceDao().allCount() |
|
|
|
} |
|
|
|
} |
|
|
|
App.db.bookSourceDao().insert(bookSource) |
|
|
|
App.db.bookSourceDao().insert(bookSource) |
|
|
|