|
@ -19,7 +19,8 @@ import org.jsoup.nodes.Document; |
|
|
import org.jsoup.nodes.Element; |
|
|
import org.jsoup.nodes.Element; |
|
|
import org.jsoup.select.Elements; |
|
|
import org.jsoup.select.Elements; |
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.HashMap; |
|
|
|
|
|
import java.util.LinkedHashMap; |
|
|
import java.util.Objects; |
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
|
import gr.thmmy.mthmmy.R; |
|
|
import gr.thmmy.mthmmy.R; |
|
@ -35,10 +36,10 @@ public class SummaryFragment extends Fragment { |
|
|
*/ |
|
|
*/ |
|
|
private static final String PROFILE_DOCUMENT = "PROFILE_DOCUMENT"; |
|
|
private static final String PROFILE_DOCUMENT = "PROFILE_DOCUMENT"; |
|
|
/** |
|
|
/** |
|
|
* {@link ArrayList} of Strings used to hold profile's information. Data are added in |
|
|
* {@link HashMap} used to hold profile's information. Data are added in |
|
|
* {@link SummaryTask}. |
|
|
* {@link SummaryTask}. |
|
|
*/ |
|
|
*/ |
|
|
private ArrayList<String> parsedProfileSummaryData; |
|
|
private LinkedHashMap<String, String> parsedProfileSummaryData; |
|
|
/** |
|
|
/** |
|
|
* A {@link Document} holding this profile's source code. |
|
|
* A {@link Document} holding this profile's source code. |
|
|
*/ |
|
|
*/ |
|
@ -69,7 +70,7 @@ public class SummaryFragment extends Fragment { |
|
|
public void onCreate(Bundle savedInstanceState) { |
|
|
public void onCreate(Bundle savedInstanceState) { |
|
|
super.onCreate(savedInstanceState); |
|
|
super.onCreate(savedInstanceState); |
|
|
profileSummaryDocument = Jsoup.parse(requireArguments().getString(PROFILE_DOCUMENT)); |
|
|
profileSummaryDocument = Jsoup.parse(requireArguments().getString(PROFILE_DOCUMENT)); |
|
|
parsedProfileSummaryData = new ArrayList<>(); |
|
|
parsedProfileSummaryData = new LinkedHashMap<>(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -123,36 +124,42 @@ public class SummaryFragment extends Fragment { |
|
|
* @return ArrayList containing this profile's parsed information |
|
|
* @return ArrayList containing this profile's parsed information |
|
|
* @see org.jsoup.Jsoup Jsoup |
|
|
* @see org.jsoup.Jsoup Jsoup |
|
|
*/ |
|
|
*/ |
|
|
ArrayList<String> parseProfileSummary(Document profile) { |
|
|
LinkedHashMap<String, String> parseProfileSummary(Document profile) { |
|
|
//Method's variables
|
|
|
LinkedHashMap<String, String> parsedInformation = new LinkedHashMap<>(); |
|
|
ArrayList<String> parsedInformation = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
//Contains all summary's rows
|
|
|
//Contains all summary's rows
|
|
|
Elements summaryRows = profile.select(".bordercolor > tbody:nth-child(1) > tr:nth-child(2) tr"); |
|
|
Elements summaryRows = profile.select("td.windowbg > table > tbody > tr"); |
|
|
|
|
|
|
|
|
for (Element summaryRow : summaryRows) { |
|
|
for (Element summaryRow : summaryRows) { |
|
|
String rowText = summaryRow.text(), pHtml = ""; |
|
|
String key, value; |
|
|
|
|
|
|
|
|
if (summaryRow.select("td").size() == 1) //Horizontal rule rows
|
|
|
int tdSize = summaryRow.select("td").size(); |
|
|
pHtml = ""; |
|
|
|
|
|
else if (summaryRow.text().contains("Current Status") |
|
|
if (tdSize > 1){ |
|
|
|| summaryRow.text().contains("Κατάσταση")) continue; |
|
|
key = summaryRow.select("td").first().text().trim(); |
|
|
else if (rowText.contains("Signature") || rowText.contains("Υπογραφή")) { |
|
|
|
|
|
//This needs special handling since it may have css
|
|
|
if (key.startsWith("Name") || key.startsWith("Όνομα")) |
|
|
pHtml = ParseHelpers.emojiTagToHtml(ParseHelpers.youtubeEmbeddedFix(summaryRow)); |
|
|
continue; |
|
|
//Add stuff to make it work in WebView
|
|
|
else if (key.startsWith("Signature") || key.startsWith("Υπογραφή")){ |
|
|
//style.css
|
|
|
key = summaryRow.selectFirst("td > table > tbody > tr > td").text().trim(); |
|
|
pHtml = ("<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />\n" + |
|
|
summaryRow.selectFirst("td > table > tbody > tr").remove(); //key not needed, outer html needed for CSS
|
|
|
|
|
|
value = ParseHelpers.emojiTagToHtml(ParseHelpers.youtubeEmbeddedFix(summaryRow)); // Is emojiTagToHtml() really needed here?
|
|
|
|
|
|
if(summaryRow.text().trim().isEmpty()) |
|
|
|
|
|
continue; |
|
|
|
|
|
value = ("<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />\n" + |
|
|
"<link rel=\"stylesheet\" type=\"text/css\" href=\"style_light.css\" />\n" + |
|
|
"<link rel=\"stylesheet\" type=\"text/css\" href=\"style_light.css\" />\n" + |
|
|
"<div class=\"customSignature\">\n" + pHtml + "\n</div>"); |
|
|
"<div class=\"customSignature\">\n" + value + "\n</div>"); |
|
|
} else if (!rowText.contains("Name") && !rowText.contains("Όνομα")) { //Doesn't add username twice
|
|
|
} |
|
|
if (Objects.equals(summaryRow.select("td").get(1).text(), "")) |
|
|
else { |
|
|
|
|
|
if (summaryRow.select("td").get(1).text().isEmpty()) |
|
|
continue; |
|
|
continue; |
|
|
//Style parsed information with html
|
|
|
if (key.startsWith("Date Registered") || key.startsWith("Ημερομηνία εγγραφής") || key.startsWith("Last Active") || key.startsWith("Τελευταία σύνδεση")) |
|
|
pHtml = "<b>" + summaryRow.select("td").first().text() + "</b> " |
|
|
value = summaryRow.select("td").get(1).text().trim(); |
|
|
+ summaryRow.select("td").get(1).text(); |
|
|
else |
|
|
|
|
|
value = summaryRow.select("td").get(1).html().trim(); |
|
|
|
|
|
} |
|
|
|
|
|
parsedInformation.put(key, value); |
|
|
} |
|
|
} |
|
|
parsedInformation.add(pHtml); |
|
|
|
|
|
} |
|
|
} |
|
|
return parsedInformation; |
|
|
return parsedInformation; |
|
|
} |
|
|
} |
|
@ -165,38 +172,54 @@ public class SummaryFragment extends Fragment { |
|
|
* {@link #parsedProfileSummaryData}</p> |
|
|
* {@link #parsedProfileSummaryData}</p> |
|
|
*/ |
|
|
*/ |
|
|
private void populateLayout() { |
|
|
private void populateLayout() { |
|
|
for (String profileSummaryRow : parsedProfileSummaryData) { |
|
|
for (LinkedHashMap.Entry<String, String> entry : parsedProfileSummaryData.entrySet()) { |
|
|
if (profileSummaryRow.contains("Signature") |
|
|
String key = entry.getKey(); |
|
|
|| profileSummaryRow.contains("Υπογραφή")) { //This may contain css
|
|
|
String value = entry.getValue(); |
|
|
ReactiveWebView signatureEntry = new ReactiveWebView(this.getContext()); |
|
|
|
|
|
signatureEntry.setBackgroundColor(Color.argb(1, 255, 255, 255)); |
|
|
if (key.startsWith("Current Status") || key.startsWith("Κατάσταση")){ |
|
|
signatureEntry.loadDataWithBaseURL("file:///android_asset/", profileSummaryRow, |
|
|
addEmptyView(); |
|
|
"text/html", "UTF-8", null); |
|
|
|
|
|
mainContent.addView(signatureEntry); |
|
|
|
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
TextView entry = new TextView(this.getContext()); |
|
|
|
|
|
|
|
|
|
|
|
if (profileSummaryRow.contains("@") && |
|
|
TextView textView = new TextView(this.getContext()); |
|
|
(profileSummaryRow.contains("Email") || profileSummaryRow.contains("E-mail"))) { |
|
|
|
|
|
String email = profileSummaryRow.substring(profileSummaryRow.indexOf(":</b> ") + 6); |
|
|
if (((key.startsWith("Email") || key.startsWith("E-mail")) |
|
|
profileSummaryRow = profileSummaryRow.replace(email, |
|
|
&& value.contains("@")) || key.startsWith("Website") || key.startsWith("Ιστοτόπος")) |
|
|
"<a href=\"mailto:" + email + "\">" + email + "</a>"); |
|
|
textView.setMovementMethod(LinkMovementMethod.getInstance()); |
|
|
entry.setMovementMethod(LinkMovementMethod.getInstance()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) |
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) |
|
|
entry.setTextColor(getResources().getColor(R.color.primary_text, null)); |
|
|
textView.setTextColor(getResources().getColor(R.color.primary_text, null)); |
|
|
else |
|
|
else |
|
|
entry.setTextColor(getResources().getColor(R.color.primary_text)); |
|
|
textView.setTextColor(getResources().getColor(R.color.primary_text)); |
|
|
|
|
|
|
|
|
|
|
|
String textViewContent = "<b>" + key + "</b> " + value; |
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
|
|
if (key.startsWith("Signature") || key.startsWith("Υπογραφή")){ |
|
|
entry.setText(Html.fromHtml(profileSummaryRow, Html.FROM_HTML_MODE_LEGACY)); |
|
|
addEmptyView(); |
|
|
} else { |
|
|
textViewContent = "<b>" + key + "</b>"; |
|
|
entry.setText(Html.fromHtml(profileSummaryRow)); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
mainContent.addView(entry); |
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) |
|
|
|
|
|
textView.setText(Html.fromHtml(textViewContent, Html.FROM_HTML_MODE_LEGACY)); |
|
|
|
|
|
else |
|
|
|
|
|
textView.setText(Html.fromHtml(textViewContent)); |
|
|
|
|
|
|
|
|
|
|
|
mainContent.addView(textView); |
|
|
|
|
|
|
|
|
|
|
|
if (key.startsWith("Last Active") || key.startsWith("Τελευταία σύνδεση")) |
|
|
|
|
|
addEmptyView(); |
|
|
|
|
|
|
|
|
|
|
|
if (key.startsWith("Signature") || key.startsWith("Υπογραφή")) { |
|
|
|
|
|
ReactiveWebView signatureEntry = new ReactiveWebView(this.getContext()); |
|
|
|
|
|
signatureEntry.setBackgroundColor(Color.argb(1, 255, 255, 255)); |
|
|
|
|
|
signatureEntry.loadDataWithBaseURL("file:///android_asset/", value, |
|
|
|
|
|
"text/html", "UTF-8", null); |
|
|
|
|
|
mainContent.addView(signatureEntry); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void addEmptyView(){ |
|
|
|
|
|
mainContent.addView(new TextView(this.getContext())); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|