|
|
@ -30,15 +30,16 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun save(bookSource: BookSource, success: (() -> Unit)? = null) { |
|
|
|
fun save(source: BookSource, success: (() -> Unit)? = null) { |
|
|
|
execute { |
|
|
|
execute { |
|
|
|
oldSourceUrl?.let { |
|
|
|
oldSourceUrl?.let { |
|
|
|
if (oldSourceUrl != bookSource.bookSourceUrl) { |
|
|
|
if (oldSourceUrl != source.bookSourceUrl) { |
|
|
|
App.db.bookSourceDao().delete(it) |
|
|
|
App.db.bookSourceDao().delete(it) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
oldSourceUrl = bookSource.bookSourceUrl |
|
|
|
oldSourceUrl = source.bookSourceUrl |
|
|
|
App.db.bookSourceDao().insert(bookSource) |
|
|
|
App.db.bookSourceDao().insert(source) |
|
|
|
|
|
|
|
bookSource = source |
|
|
|
}.onSuccess { |
|
|
|
}.onSuccess { |
|
|
|
success?.invoke() |
|
|
|
success?.invoke() |
|
|
|
}.onError { |
|
|
|
}.onError { |
|
|
@ -47,21 +48,25 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun pasteSource(onSuccess: () -> Unit) { |
|
|
|
fun pasteSource(onSuccess: (source: BookSource) -> Unit) { |
|
|
|
execute { |
|
|
|
execute { |
|
|
|
|
|
|
|
var source: BookSource? = null |
|
|
|
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager? |
|
|
|
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager? |
|
|
|
clipboard?.primaryClip?.let { |
|
|
|
clipboard?.primaryClip?.let { |
|
|
|
if (it.itemCount > 0) { |
|
|
|
if (it.itemCount > 0) { |
|
|
|
val json = it.getItemAt(0).text.toString() |
|
|
|
val json = it.getItemAt(0).text.toString() |
|
|
|
OldRule.jsonToBookSource(json)?.let { source -> |
|
|
|
source = OldRule.jsonToBookSource(json) |
|
|
|
bookSource = source |
|
|
|
|
|
|
|
} ?: toast("格式不对") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
source |
|
|
|
}.onError { |
|
|
|
}.onError { |
|
|
|
toast(it.localizedMessage) |
|
|
|
toast(it.localizedMessage) |
|
|
|
}.onSuccess { |
|
|
|
}.onSuccess { |
|
|
|
onSuccess() |
|
|
|
if (it != null) { |
|
|
|
|
|
|
|
onSuccess(it) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
toast("格式不对") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |