From 209350ae347df193b33c146de3d3de3c4854c785 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 8 Sep 2020 16:10:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/book/source/edit/BookSourceEditViewModel.kt | 11 +++-------- .../app/ui/rss/source/edit/RssSourceEditViewModel.kt | 11 +++-------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt index 81f3d22f0..7e1f70089 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt @@ -1,8 +1,6 @@ package io.legado.app.ui.book.source.edit import android.app.Application -import android.content.ClipboardManager -import android.content.Context import android.content.Intent import io.legado.app.App 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.utils.GSON import io.legado.app.utils.fromJsonObject +import io.legado.app.utils.getClipText import kotlinx.coroutines.Dispatchers class BookSourceEditViewModel(application: Application) : BaseViewModel(application) { @@ -54,12 +53,8 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat fun pasteSource(onSuccess: (source: BookSource) -> Unit) { execute(context = Dispatchers.Main) { var source: BookSource? = null - val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager? - clipboard?.primaryClip?.let { - if (it.itemCount > 0) { - val json = it.getItemAt(0).text.toString() - source = OldRule.jsonToBookSource(json) - } + context.getClipText()?.let { json -> + source = OldRule.jsonToBookSource(json) } source }.onError { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index eb9c4e034..88a9a78dd 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -1,14 +1,13 @@ package io.legado.app.ui.rss.source.edit import android.app.Application -import android.content.ClipboardManager -import android.content.Context import android.content.Intent import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.RssSource import io.legado.app.utils.GSON import io.legado.app.utils.fromJsonObject +import io.legado.app.utils.getClipText import kotlinx.coroutines.Dispatchers class RssSourceEditViewModel(application: Application) : BaseViewModel(application) { @@ -53,12 +52,8 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati fun pasteSource(onSuccess: (source: RssSource) -> Unit) { execute(context = Dispatchers.Main) { var source: RssSource? = null - val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager? - clipboard?.primaryClip?.let { - if (it.itemCount > 0) { - val json = it.getItemAt(0).text.toString().trim() - source = GSON.fromJsonObject(json) - } + context.getClipText()?.let { json -> + source = GSON.fromJsonObject(json) } source }.onError {