Browse Source

fix parse mistakes in results mode

pull/55/head
Thodoris1999 6 years ago
parent
commit
cd6d4e07c8
  1. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  2. 14
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java
  3. 6
      app/src/main/res/layout/activity_topic_poll.xml

2
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

@ -150,7 +150,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
return new EditMessageViewHolder(view); return new EditMessageViewHolder(view);
} else if (viewType == Poll.TYPE_POLL) { } else if (viewType == Poll.TYPE_POLL) {
View view = LayoutInflater.from(parent.getContext()). View view = LayoutInflater.from(parent.getContext()).
inflate(R.layout.activity_topic_edit_row, parent, false); inflate(R.layout.activity_topic_poll, parent, false);
return new PollViewHolder(view); return new PollViewHolder(view);
} else { } else {
throw new IllegalArgumentException("Unknown view type"); throw new IllegalArgumentException("Unknown view type");

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

@ -153,9 +153,12 @@ public class TopicParser {
//Method's variables //Method's variables
final int NO_INDEX = -1; final int NO_INDEX = -1;
ArrayList<TopicItem> parsedPostsList = new ArrayList<>();
Poll poll = findPoll(topic); Poll poll = findPoll(topic);
if (poll != null)
parsedPostsList.add(poll);
ArrayList<TopicItem> parsedPostsList = new ArrayList<>();
Elements postRows; Elements postRows;
//Each row is a post //Each row is a post
@ -491,7 +494,7 @@ public class TopicParser {
Element secondRow = tables.get(i).select("tr[class=windowbg]").first(); Element secondRow = tables.get(i).select("tr[class=windowbg]").first();
Element secondColumn = secondRow.child(1); Element secondColumn = secondRow.child(1);
String columnString = secondColumn.outerHtml(); String columnString = secondColumn.outerHtml();
question = columnString.substring(columnString.indexOf('>'), columnString.indexOf('<', 2)).trim(); question = columnString.substring(columnString.indexOf('>') + 1, columnString.indexOf('<', 2)).trim();
Element form = secondColumn.select("form").first(); Element form = secondColumn.select("form").first();
if (form != null) { if (form != null) {
@ -518,11 +521,12 @@ public class TopicParser {
} }
} else { } else {
// english poll in results mode // english poll in results mode
Elements optionRows = secondColumn.child(0).select("table").first().children(); Elements optionRows = secondColumn.child(0).child(0).select("table").first().child(0).children();
for (int j = 0; j < optionRows.size(); j++) { for (int j = 0; j < optionRows.size(); j++) {
String optionName = optionRows.get(i).child(0).text(); String optionName = optionRows.get(j).child(0).text();
String voteCountDescription = optionRows.get(i).child(1).text(); String voteCountDescription = optionRows.get(j).child(1).text();
Matcher integerMatcher = integerPattern.matcher(voteCountDescription); Matcher integerMatcher = integerPattern.matcher(voteCountDescription);
integerMatcher.find();
int voteCount = Integer.parseInt(voteCountDescription.substring(integerMatcher.start(), int voteCount = Integer.parseInt(voteCountDescription.substring(integerMatcher.start(),
integerMatcher.end())); integerMatcher.end()));
entries.add(new Poll.Entry(optionName, voteCount)); entries.add(new Poll.Entry(optionName, voteCount));

6
app/src/main/res/layout/activity_topic_poll.xml

@ -4,7 +4,7 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="wrap_content">
<TextView <TextView
android:id="@+id/question_textview" android:id="@+id/question_textview"
@ -13,8 +13,8 @@
<com.github.mikephil.charting.charts.HorizontalBarChart <com.github.mikephil.charting.charts.HorizontalBarChart
android:id="@+id/vote_chart" android:id="@+id/vote_chart"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="250dp" />
<TextView <TextView
android:id="@+id/error_too_many_checked" android:id="@+id/error_too_many_checked"

Loading…
Cancel
Save