Browse Source

cleanup

pull/61/merge
oogee 6 years ago
parent
commit
a8762d6629
  1. 12
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java
  2. 5
      app/src/main/java/gr/thmmy/mthmmy/utils/CrashReporter.java
  3. 28
      app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java

12
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java

@ -59,7 +59,7 @@ public class TopicParser {
* @see org.jsoup.Jsoup Jsoup
*/
public static String parseUsersViewingThisTopic(Document topic, ParseHelpers.Language language) {
if (language.is(ParseHelpers.Language.GREEK))
if (language == ParseHelpers.Language.GREEK)
return topic.select("td:containsOwn(διαβάζουν αυτό το θέμα)").first().html();
return topic.select("td:containsOwn(are viewing this topic)").first().html();
}
@ -77,7 +77,7 @@ public class TopicParser {
public static int parseCurrentPageIndex(Document topic, ParseHelpers.Language language) {
int parsedPage = 1;
if (language.is(ParseHelpers.Language.GREEK)) {
if (language == ParseHelpers.Language.GREEK) {
Elements findCurrentPage = topic.select("td:contains(Σελίδες:)>b");
for (Element item : findCurrentPage) {
@ -115,7 +115,7 @@ public class TopicParser {
public static int parseTopicNumberOfPages(Document topic, int currentPage, ParseHelpers.Language language) {
int returnPages = 1;
if (language.is(ParseHelpers.Language.GREEK)) {
if (language == ParseHelpers.Language.GREEK) {
Elements pages = topic.select("td:contains(Σελίδες:)>a.navPages");
if (pages.size() != 0) {
@ -163,7 +163,7 @@ public class TopicParser {
Elements postRows;
//Each row is a post
if (language.is(ParseHelpers.Language.GREEK))
if (language == ParseHelpers.Language.GREEK)
postRows = topic.select("form[id=quickModForm]>table>tbody>tr:matches(στις)");
else {
postRows = topic.select("form[id=quickModForm]>table>tbody>tr:matches(on)");
@ -236,7 +236,7 @@ public class TopicParser {
//Language dependent parsing
Element userName;
if (language.is(ParseHelpers.Language.GREEK)) {
if (language == ParseHelpers.Language.GREEK) {
//Finds username and profile's url
userName = thisRow.select("a[title^=Εμφάνιση προφίλ του μέλους]").first();
if (userName == null) { //Deleted profile
@ -388,7 +388,7 @@ public class TopicParser {
Element usersExtraInfo = userName.parent().nextElementSibling(); //Get sibling "div"
List<String> infoList = Arrays.asList(usersExtraInfo.html().split("<br>"));
if (language.is(ParseHelpers.Language.GREEK)) {
if (language == ParseHelpers.Language.GREEK) {
for (String line : infoList) {
if (line.contains("Μηνύματα:")) {
postsLineIndex = infoList.indexOf(line);

5
app/src/main/java/gr/thmmy/mthmmy/utils/CrashReporter.java

@ -6,6 +6,7 @@ import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import gr.thmmy.mthmmy.base.BaseApplication;
import gr.thmmy.mthmmy.utils.parsing.ParseHelpers;
public class CrashReporter {
@ -43,8 +44,10 @@ public class CrashReporter {
languageValue = "English";
break;
}
Crashlytics.setString(themeKey, themeValue);
Crashlytics.setString(languageKey, languageValue);
Crashlytics.setBool("isLoggedIn", BaseApplication.getInstance().getSessionManager().isLoggedIn());
}
public static void reportDocument(Document document, String key) {
@ -52,7 +55,7 @@ public class CrashReporter {
ParseHelpers.Language language = ParseHelpers.Language.getLanguage(document);
Elements postRows;
if (language.is(ParseHelpers.Language.GREEK))
if (language == 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)");

28
app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java

@ -18,18 +18,12 @@ import timber.log.Timber;
* and obfuscated emails.
*/
public class ParseHelpers {
/**
* Debug Tag for logging debug output to LogCat
*/
@SuppressWarnings("unused")
private static final String TAG = "ParseHelpers";
/**
* An enum describing a forum page's language by defining the types:<ul>
* <li>{@link #PAGE_INCOMPLETE}</li>
* <li>{@link #UNDEFINED_LANGUAGE}</li>
* <li>{@link #ENGLISH}</li>
* <li>{@link #ENGLISH_GUEST}</li>
* <li>{@link #GREEK}</li>
* </ul>
*/
@ -42,10 +36,6 @@ public class ParseHelpers {
* Page language is english.
*/
ENGLISH,
/**
* Page language is english and the user is guest.
*/
ENGLISH_GUEST,
/**
* Page is incomplete. Data are not enough to determine the language.
*/
@ -67,29 +57,13 @@ public class ParseHelpers {
if (welcoming == null) {
Element welcomingGuest = page.select("div[id=myuser]").first();
if (welcomingGuest != null) {
if (welcomingGuest.text().contains("Welcome")) return ENGLISH_GUEST;
if (welcomingGuest.text().contains("Welcome")) return ENGLISH;
}
return PAGE_INCOMPLETE;
} else if (welcoming.text().contains("Καλώς ορίσατε")) return GREEK;
else if (welcoming.text().contains("Hey")) return ENGLISH;
else return UNDEFINED_LANGUAGE;
}
/**
* This method defines a custom equality check for {@link Language} enums.
* <p>Method returns true if parameter's Target is the same as the object and in the specific
* cases described below, false otherwise.</p><ul>
* <li>{@link #ENGLISH}.is({@link #ENGLISH_GUEST}) returns true</li>
* <li>{@link #ENGLISH_GUEST}.is({@link #ENGLISH}) returns true</li>
*
* @param other another Language
* @return true if <b>enums</b> are equal, false otherwise
*/
public boolean is(Language other) {
return this == ENGLISH && other == ENGLISH_GUEST
|| this == ENGLISH_GUEST && other == ENGLISH
|| this == other;
}
}
public enum Theme {

Loading…
Cancel
Save