Drop JsoupUtils and LogCat

This commit is contained in:
FooIbar authored and tarsin committed 2023-06-22 10:01:41 +08:00
1 parent 7240ca4eba
commit 09e9d3ff5a
5 files changed
+12 -111

No files matched your search

@@ -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) {
@@ -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("<br>", "\n")
val e = Jsoup.parse(body).getElementsByClass("d").first()
e!!.child(0).html().replace("<br>", "\n")
}.getOrElse {
ExceptionUtils.throwIfFatal(it)
it.printStackTrace()
@@ -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()))
}
@@ -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;
}
}
}
@@ -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;
}
}
}