|
@ -10,7 +10,6 @@ import android.view.ViewGroup; |
|
|
import android.widget.LinearLayout; |
|
|
import android.widget.LinearLayout; |
|
|
import android.widget.ProgressBar; |
|
|
import android.widget.ProgressBar; |
|
|
import android.widget.TextView; |
|
|
import android.widget.TextView; |
|
|
import android.widget.Toast; |
|
|
|
|
|
|
|
|
|
|
|
import androidx.fragment.app.Fragment; |
|
|
import androidx.fragment.app.Fragment; |
|
|
|
|
|
|
|
@ -43,6 +42,7 @@ import javax.net.ssl.SSLHandshakeException; |
|
|
|
|
|
|
|
|
import gr.thmmy.mthmmy.R; |
|
|
import gr.thmmy.mthmmy.R; |
|
|
import gr.thmmy.mthmmy.base.BaseActivity; |
|
|
import gr.thmmy.mthmmy.base.BaseActivity; |
|
|
|
|
|
import gr.thmmy.mthmmy.utils.parsing.ParseException; |
|
|
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; |
|
|
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; |
|
|
import okhttp3.Request; |
|
|
import okhttp3.Request; |
|
|
import okhttp3.Response; |
|
|
import okhttp3.Response; |
|
@ -148,87 +148,73 @@ public class StatsFragment extends Fragment { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//TODO: better parse error handling (ParseException etc.)
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
protected void onPostExecute(Boolean result) { |
|
|
protected void onPostExecute(Boolean result) { |
|
|
if (!result) { //Parse failed!
|
|
|
progressBar.setVisibility(ProgressBar.INVISIBLE); |
|
|
Timber.d("Parse failed!"); |
|
|
if (!result) |
|
|
Toast.makeText(getContext() |
|
|
Timber.e(new ParseException("Parsing failed (user stats)"),"ParseException"); //TODO: This is inaccurate (e.g. can also have an I/O cause)
|
|
|
, "Fatal error!\n Aborting...", Toast.LENGTH_LONG).show(); |
|
|
else |
|
|
getActivity().finish(); |
|
|
populateLayout(); |
|
|
} |
|
|
|
|
|
//Parse was successful
|
|
|
|
|
|
populateLayout(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//TODO: better parse error handling (ParseException etc.)
|
|
|
private boolean parseStats(Document statsPage) { |
|
|
private boolean parseStats(Document statsPage) { |
|
|
//Doesn't go through all the parsing if this user has no posts
|
|
|
//Doesn't go through all the parsing if this user has no posts
|
|
|
if (!statsPage.select("td:contains(No posts to speak of!)").isEmpty()) { |
|
|
if (!statsPage.select("td:contains(No posts to speak of!), td:contains(Δεν υπάρχει καμία αποστολή μηνύματος!)").isEmpty()) |
|
|
userHasPosts = false; |
|
|
|
|
|
} |
|
|
|
|
|
if (!statsPage.select("td:contains(Δεν υπάρχει καμία αποστολή μηνύματος!)").isEmpty()) { |
|
|
|
|
|
userHasPosts = false; |
|
|
userHasPosts = false; |
|
|
} |
|
|
|
|
|
if (statsPage.select("table.bordercolor[align]>tbody>tr").size() != 6) |
|
|
if (statsPage.select("table.bordercolor[align]>tbody>tr").size() != 6) |
|
|
return false; |
|
|
return false; |
|
|
{ |
|
|
|
|
|
Elements titleRows = statsPage.select("table.bordercolor[align]>tbody>tr.titlebg"); |
|
|
Elements titleRows = statsPage.select("table.bordercolor[align]>tbody>tr.titlebg"); |
|
|
generalStatisticsTitle = titleRows.first().text(); |
|
|
generalStatisticsTitle = titleRows.first().text(); |
|
|
Pattern pattern = Pattern.compile("(.+)\\s-"); |
|
|
Pattern pattern = Pattern.compile("(.+)\\s-"); |
|
|
Matcher matcher = pattern.matcher(generalStatisticsTitle); |
|
|
Matcher matcher = pattern.matcher(generalStatisticsTitle); |
|
|
if (matcher.find()) |
|
|
if (matcher.find()) |
|
|
generalStatisticsTitle = matcher.group(1); |
|
|
generalStatisticsTitle = matcher.group(1); |
|
|
|
|
|
|
|
|
if (userHasPosts) { |
|
|
if (userHasPosts) { |
|
|
postingActivityByTimeTitle = titleRows.get(1).text(); |
|
|
postingActivityByTimeTitle = titleRows.get(1).text(); |
|
|
mostPopularBoardsByPostsTitle = titleRows.last().select("td").first().text(); |
|
|
mostPopularBoardsByPostsTitle = titleRows.last().select("td").first().text(); |
|
|
mostPopularBoardsByActivityTitle = titleRows.last().select("td").last().text(); |
|
|
mostPopularBoardsByActivityTitle = titleRows.last().select("td").last().text(); |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
{ |
|
|
|
|
|
Elements statsRows = statsPage.select("table.bordercolor[align]>tbody>tr:not(.titlebg)"); |
|
|
Elements statsRows = statsPage.select("table.bordercolor[align]>tbody>tr:not(.titlebg)"); |
|
|
{ |
|
|
Elements generalStatisticsRows = statsRows.first().select("tbody>tr"); |
|
|
Elements generalStatisticsRows = statsRows.first().select("tbody>tr"); |
|
|
for (Element generalStatisticsRow : generalStatisticsRows) |
|
|
for (Element generalStatisticsRow : generalStatisticsRows) |
|
|
generalStatistics += generalStatisticsRow.text() + "\n"; |
|
|
generalStatistics += generalStatisticsRow.text() + "\n"; |
|
|
generalStatistics = generalStatistics.trim(); |
|
|
generalStatistics = generalStatistics.trim(); |
|
|
|
|
|
|
|
|
if (userHasPosts) { |
|
|
|
|
|
Elements postingActivityByTimeCols = statsRows.get(1).select(">td").last() |
|
|
|
|
|
.select("tr").first().select("td[width=4%]"); |
|
|
|
|
|
int i = -1; |
|
|
|
|
|
for (Element postingActivityByTimeColumn : postingActivityByTimeCols) |
|
|
|
|
|
postingActivityByTime.add(new Entry(++i, Float.parseFloat(postingActivityByTimeColumn |
|
|
|
|
|
.select("img").first().attr("height")))); |
|
|
|
|
|
|
|
|
|
|
|
Elements mostPopularBoardsByPostsRows = statsRows.last().select(">td").get(1) |
|
|
|
|
|
.select(">table>tbody>tr"); |
|
|
|
|
|
i = mostPopularBoardsByPostsRows.size(); |
|
|
|
|
|
for (Element mostPopularBoardsByPostsRow : mostPopularBoardsByPostsRows) { |
|
|
|
|
|
Elements dataCols = mostPopularBoardsByPostsRow.select("td"); |
|
|
|
|
|
mostPopularBoardsByPosts.add(new BarEntry(--i, |
|
|
|
|
|
Integer.parseInt(dataCols.last().text()))); |
|
|
|
|
|
mostPopularBoardsByPostsLabels.add(dataCols.first().text()); |
|
|
} |
|
|
} |
|
|
if (userHasPosts) { |
|
|
Collections.reverse(mostPopularBoardsByPostsLabels); |
|
|
{ |
|
|
|
|
|
Elements postingActivityByTimeCols = statsRows.get(1).select(">td").last() |
|
|
Elements mostPopularBoardsByActivityRows = statsRows.last().select(">td").last() |
|
|
.select("tr").first().select("td[width=4%]"); |
|
|
.select(">table>tbody>tr"); |
|
|
int i = -1; |
|
|
i = mostPopularBoardsByActivityRows.size(); |
|
|
for (Element postingActivityByTimeColumn : postingActivityByTimeCols) { |
|
|
for (Element mostPopularBoardsByActivityRow : mostPopularBoardsByActivityRows) { |
|
|
postingActivityByTime.add(new Entry(++i, Float.parseFloat(postingActivityByTimeColumn |
|
|
Elements dataCols = mostPopularBoardsByActivityRow.select("td"); |
|
|
.select("img").first().attr("height")))); |
|
|
String tmp = dataCols.last().text(); |
|
|
} |
|
|
mostPopularBoardsByActivity.add(new BarEntry(--i, |
|
|
} |
|
|
Float.parseFloat(tmp.substring(0, tmp.indexOf("%"))))); |
|
|
{ |
|
|
mostPopularBoardsByActivityLabels.add(dataCols.first().text()); |
|
|
Elements mostPopularBoardsByPostsRows = statsRows.last().select(">td").get(1) |
|
|
|
|
|
.select(">table>tbody>tr"); |
|
|
|
|
|
int i = mostPopularBoardsByPostsRows.size(); |
|
|
|
|
|
for (Element mostPopularBoardsByPostsRow : mostPopularBoardsByPostsRows) { |
|
|
|
|
|
Elements dataCols = mostPopularBoardsByPostsRow.select("td"); |
|
|
|
|
|
mostPopularBoardsByPosts.add(new BarEntry(--i, |
|
|
|
|
|
Integer.parseInt(dataCols.last().text()))); |
|
|
|
|
|
mostPopularBoardsByPostsLabels.add(dataCols.first().text()); |
|
|
|
|
|
} |
|
|
|
|
|
Collections.reverse(mostPopularBoardsByPostsLabels); |
|
|
|
|
|
} |
|
|
|
|
|
{ |
|
|
|
|
|
Elements mostPopularBoardsByActivityRows = statsRows.last().select(">td").last() |
|
|
|
|
|
.select(">table>tbody>tr"); |
|
|
|
|
|
int i = mostPopularBoardsByActivityRows.size(); |
|
|
|
|
|
for (Element mostPopularBoardsByActivityRow : mostPopularBoardsByActivityRows) { |
|
|
|
|
|
Elements dataCols = mostPopularBoardsByActivityRow.select("td"); |
|
|
|
|
|
String tmp = dataCols.last().text(); |
|
|
|
|
|
mostPopularBoardsByActivity.add(new BarEntry(--i, |
|
|
|
|
|
Float.parseFloat(tmp.substring(0, tmp.indexOf("%"))))); |
|
|
|
|
|
mostPopularBoardsByActivityLabels.add(dataCols.first().text()); |
|
|
|
|
|
} |
|
|
|
|
|
Collections.reverse(mostPopularBoardsByActivityLabels); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
Collections.reverse(mostPopularBoardsByActivityLabels); |
|
|
} |
|
|
} |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
@ -243,7 +229,6 @@ public class StatsFragment extends Fragment { |
|
|
|
|
|
|
|
|
if (!userHasPosts) { |
|
|
if (!userHasPosts) { |
|
|
mainContent.removeViews(2, mainContent.getChildCount() - 2); |
|
|
mainContent.removeViews(2, mainContent.getChildCount() - 2); |
|
|
//mainContent.removeViews(2, 6);
|
|
|
|
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|