|
|
@ -1,8 +1,6 @@ |
|
|
|
package io.legado.app.ui.book.source.edit |
|
|
|
package io.legado.app.ui.book.source.edit |
|
|
|
|
|
|
|
|
|
|
|
import android.app.Application |
|
|
|
import android.app.Application |
|
|
|
import android.content.ClipboardManager |
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
|
|
|
|
import android.content.Intent |
|
|
|
import android.content.Intent |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
@ -10,6 +8,7 @@ import io.legado.app.data.entities.BookSource |
|
|
|
import io.legado.app.help.storage.OldRule |
|
|
|
import io.legado.app.help.storage.OldRule |
|
|
|
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 kotlinx.coroutines.Dispatchers |
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
|
|
|
|
|
|
|
|
class BookSourceEditViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
class BookSourceEditViewModel(application: Application) : BaseViewModel(application) { |
|
|
@ -54,12 +53,8 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat |
|
|
|
fun pasteSource(onSuccess: (source: BookSource) -> Unit) { |
|
|
|
fun pasteSource(onSuccess: (source: BookSource) -> Unit) { |
|
|
|
execute(context = Dispatchers.Main) { |
|
|
|
execute(context = Dispatchers.Main) { |
|
|
|
var source: BookSource? = null |
|
|
|
var source: BookSource? = null |
|
|
|
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager? |
|
|
|
context.getClipText()?.let { json -> |
|
|
|
clipboard?.primaryClip?.let { |
|
|
|
source = OldRule.jsonToBookSource(json) |
|
|
|
if (it.itemCount > 0) { |
|
|
|
|
|
|
|
val json = it.getItemAt(0).text.toString() |
|
|
|
|
|
|
|
source = OldRule.jsonToBookSource(json) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
source |
|
|
|
source |
|
|
|
}.onError { |
|
|
|
}.onError { |
|
|
|