From 40fa8c6279d7addb1f5d0e282d16242cc55aafea Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Sat, 1 Sep 2018 17:28:18 +0300 Subject: [PATCH] document report init --- .../gr/thmmy/mthmmy/utils/CrashReporter.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 app/src/main/java/gr/thmmy/mthmmy/utils/CrashReporter.java diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/CrashReporter.java b/app/src/main/java/gr/thmmy/mthmmy/utils/CrashReporter.java new file mode 100644 index 00000000..81b06769 --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/CrashReporter.java @@ -0,0 +1,42 @@ +package gr.thmmy.mthmmy.utils; + +import com.crashlytics.android.Crashlytics; + +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + +import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; + +public class CrashReporter { + private static final int STRING_BATCH_LENGTH = 250; + + private CrashReporter() {} + + public static void reportDocument(Document document, String key) { + String documentString = document.toString(); + + ParseHelpers.Language language = ParseHelpers.Language.getLanguage(document); + Elements postRows; + if (language.is(ParseHelpers.Language.GREEK)) + postRows = document.select("form[id=quickModForm]>table>tbody>tr:matches(στις)"); + else + postRows = document.select("form[id=quickModForm]>table>tbody>tr:matches(on)"); + for (Element thisRow : postRows) { + String subject = thisRow.select("div[id^=subject_]").first().select("a").first().text(); + documentString = documentString.replace(subject, "subject"); + String post = thisRow.select("div").select(".post").first().text(); + documentString = documentString.replace(post, "post"); + } + + int batchCount = documentString.length() / STRING_BATCH_LENGTH; + for (int i = 0; i < batchCount; i++) { + String batch; + if (i != batchCount - 1) + batch = documentString.substring(i * STRING_BATCH_LENGTH, (i + 1) * STRING_BATCH_LENGTH); + else + batch = documentString.substring(i * STRING_BATCH_LENGTH); + Crashlytics.setString(key + "_" + i + 1, batch); + } + } +}