From 09e9d3ff5a49461caea98b446464e2845e9cb229 Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Wed, 21 Jun 2023 13:00:32 +0800 Subject: [PATCH] Drop JsoupUtils and LogCat --- .../client/parser/GalleryDetailParser.kt | 19 +++---- .../parser/GalleryNotAvailableParser.kt | 6 +- .../ehviewer/ui/settings/AdvancedScreen.kt | 3 +- .../com/hippo/ehviewer/util/JsoupUtils.java | 56 ------------------- .../java/com/hippo/ehviewer/util/LogCat.java | 39 ------------- 5 files changed, 12 insertions(+), 111 deletions(-) delete mode 100644 app/src/main/java/com/hippo/ehviewer/util/JsoupUtils.java delete mode 100644 app/src/main/java/com/hippo/ehviewer/util/LogCat.java diff --git a/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryDetailParser.kt b/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryDetailParser.kt index d582f12a1..ec6423e97 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryDetailParser.kt +++ b/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryDetailParser.kt @@ -35,7 +35,6 @@ import com.hippo.ehviewer.client.exception.ParseException import com.hippo.ehviewer.client.exception.PiningException import com.hippo.ehviewer.client.getThumbKey import com.hippo.ehviewer.util.ExceptionUtils -import com.hippo.ehviewer.util.JsoupUtils import com.hippo.ehviewer.yorozuya.NumberUtils import com.hippo.ehviewer.yorozuya.StringUtils import com.hippo.ehviewer.yorozuya.trimAnd @@ -141,11 +140,11 @@ object GalleryDetailParser { gd.titleJpn = gm.getElementById("gj")?.text()?.trim() // Category - val gdc = gm.getElementById("gdc") try { - var ce = JsoupUtils.getElementByClass(gdc, "cn") + val gdc = gm.getElementById("gdc")!! + var ce = gdc.getElementsByClass("cn").first() if (ce == null) { - ce = JsoupUtils.getElementByClass(gdc, "cs") + ce = gdc.getElementsByClass("cs").first() } gd.category = getCategory(ce!!.text()) } catch (e: Throwable) { @@ -346,7 +345,7 @@ object GalleryDetailParser { val name = a!!.attr("name") comment.id = name trimAnd { substring(1).toInt().toLong() } // Editable, vote up and vote down - val c4 = JsoupUtils.getElementByClass(element, "c4") + val c4 = element.getElementsByClass("c4").first() if (null != c4) { if ("Uploader Comment" == c4.text()) { comment.uploader = true @@ -368,12 +367,12 @@ object GalleryDetailParser { } } // Vote state - val c7 = JsoupUtils.getElementByClass(element, "c7") + val c7 = element.getElementsByClass("c7").first() if (null != c7) { comment.voteState = StringUtils.trim(c7.text()) } // Score - val c5 = JsoupUtils.getElementByClass(element, "c5") + val c5 = element.getElementsByClass("c5").first() if (null != c5) { val es = c5.children() if (!es.isEmpty()) { @@ -384,7 +383,7 @@ object GalleryDetailParser { } } // time - val c3 = JsoupUtils.getElementByClass(element, "c3") + val c3 = element.getElementsByClass("c3").first() val temp = c3!!.ownText() val time = if (temp.endsWith(':')) { // user @@ -395,7 +394,7 @@ object GalleryDetailParser { } comment.time = Instant.from(WEB_COMMENT_DATE_FORMAT.parse(time)).toEpochMilli() // comment - val c6 = JsoupUtils.getElementByClass(element, "c6") + val c6 = element.getElementsByClass("c6").first() // fix underline support for (e in c6!!.children()) { if ("span" == e.tagName() && "text-decoration:underline;" == e.attr("style")) { @@ -411,7 +410,7 @@ object GalleryDetailParser { } } // last edited - val c8 = JsoupUtils.getElementByClass(element, "c8") + val c8 = element.getElementsByClass("c8").first() if (c8 != null) { val e = c8.children().first() if (e != null) { diff --git a/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryNotAvailableParser.kt b/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryNotAvailableParser.kt index 0c72d440b..28ea9d829 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryNotAvailableParser.kt +++ b/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryNotAvailableParser.kt @@ -18,15 +18,13 @@ package com.hippo.ehviewer.client.parser import com.hippo.ehviewer.util.ExceptionUtils -import com.hippo.ehviewer.util.JsoupUtils import org.jsoup.Jsoup object GalleryNotAvailableParser { fun parse(body: String): String? { return runCatching { - val document = Jsoup.parse(body) - val d = JsoupUtils.getElementByClass(document, "d") - d!!.child(0).html().replace("
", "\n") + val e = Jsoup.parse(body).getElementsByClass("d").first() + e!!.child(0).html().replace("
", "\n") }.getOrElse { ExceptionUtils.throwIfFatal(it) it.printStackTrace() diff --git a/app/src/main/java/com/hippo/ehviewer/ui/settings/AdvancedScreen.kt b/app/src/main/java/com/hippo/ehviewer/ui/settings/AdvancedScreen.kt index be8116141..c4bc2032e 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/settings/AdvancedScreen.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/settings/AdvancedScreen.kt @@ -38,7 +38,6 @@ import com.hippo.ehviewer.client.EhEngine import com.hippo.ehviewer.client.data.FavListUrlBuilder import com.hippo.ehviewer.ui.LocalNavController import com.hippo.ehviewer.ui.tools.observed -import com.hippo.ehviewer.util.LogCat import com.hippo.ehviewer.util.ReadableTime import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay @@ -104,7 +103,7 @@ fun AdvancedScreen() { } val logcatEntry = ZipEntry("logcat-" + ReadableTime.getFilenamableTime(System.currentTimeMillis()) + ".txt") zipOs.putNextEntry(logcatEntry) - LogCat.save(zipOs) + Runtime.getRuntime().exec("logcat -d").inputStream.use { it.copyTo(zipOs) } } launchSnackBar(getString(R.string.settings_advanced_dump_logcat_to, uri.toString())) } diff --git a/app/src/main/java/com/hippo/ehviewer/util/JsoupUtils.java b/app/src/main/java/com/hippo/ehviewer/util/JsoupUtils.java deleted file mode 100644 index 23df75253..000000000 --- a/app/src/main/java/com/hippo/ehviewer/util/JsoupUtils.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2016 Hippo Seven - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.hippo.ehviewer.util; - -import androidx.annotation.Nullable; - -import org.jsoup.nodes.Document; -import org.jsoup.nodes.Element; -import org.jsoup.select.Elements; - -public final class JsoupUtils { - - @Nullable - public static Element getElementByClass(Document doc, String className) { - Elements elements = doc.getElementsByClass(className); - if (elements != null && elements.size() > 0) { - return elements.get(0); - } else { - return null; - } - } - - @Nullable - public static Element getElementByClass(Element element, String className) { - Elements elements = element.getElementsByClass(className); - if (elements != null && elements.size() > 0) { - return elements.get(0); - } else { - return null; - } - } - - @Nullable - public static Element getElementByTag(Element element, String tagName) { - Elements elements = element.getElementsByTag(tagName); - if (elements != null && elements.size() > 0) { - return elements.get(0); - } else { - return null; - } - } -} diff --git a/app/src/main/java/com/hippo/ehviewer/util/LogCat.java b/app/src/main/java/com/hippo/ehviewer/util/LogCat.java deleted file mode 100644 index b2d6cbad0..000000000 --- a/app/src/main/java/com/hippo/ehviewer/util/LogCat.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2015 Hippo Seven - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.hippo.ehviewer.util; - -import com.hippo.ehviewer.yorozuya.IOUtils; - -import java.io.IOException; -import java.io.OutputStream; - -public final class LogCat { - - private LogCat() { - } - - public static boolean save(OutputStream outputStream) { - try { - Process p = Runtime.getRuntime().exec("logcat -d"); - IOUtils.copy(p.getInputStream(), outputStream); - return true; - } catch (IOException e) { - e.printStackTrace(); - return false; - } - } -}