From 3189cc93650064fa48ee305fdb8d8dbfbd7419a2 Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Sat, 22 Sep 2018 18:15:06 +0300 Subject: [PATCH] fix vote mode parsing in polls --- .../mthmmy/activities/topic/TopicAdapter.java | 5 +++- .../mthmmy/activities/topic/TopicParser.java | 26 +++++++++++++------ .../main/res/layout/activity_topic_poll.xml | 10 +++++-- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java index ff766e62..43f019da 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java @@ -48,6 +48,7 @@ import com.github.mikephil.charting.data.BarEntry; import com.squareup.picasso.Picasso; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -166,10 +167,11 @@ class TopicAdapter extends RecyclerView.Adapter { holder.question.setText(poll.getQuestion()); if (poll.getAvailableVoteCount() > 1) { LinearLayout optionsLayout = new LinearLayout(context); - optionsLayout.setOrientation(LinearLayout.HORIZONTAL); + optionsLayout.setOrientation(LinearLayout.VERTICAL); for (Poll.Entry entry : entries) { CheckBox checkBox = new CheckBox(context); checkBox.setText(entry.getEntryName()); + checkBox.setTextColor(context.getResources().getColor(R.color.primary_text)); checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> viewModel.onVoteCheckboxClicked(optionsLayout.indexOfChild(buttonView), isChecked)); optionsLayout.addView(checkBox); @@ -211,6 +213,7 @@ class TopicAdapter extends RecyclerView.Adapter { holder.voteChart.getLegend().setEnabled(false); holder.voteChart.getDescription().setEnabled(false); holder.voteChart.invalidate(); + holder.voteChart.setVisibility(View.VISIBLE); } if (poll.getRemoveVoteUrl() != null) holder.removeVotesButton.setVisibility(View.VISIBLE); if (poll.getShowVoteResultsUrl() != null) holder.showPollResultsButton.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java index ecef6034..9c987964 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java @@ -1,6 +1,7 @@ package gr.thmmy.mthmmy.activities.topic; import android.graphics.Color; +import android.util.Log; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; @@ -500,20 +501,29 @@ public class TopicParser { if (form != null) { // english poll in vote mode pollFormUrl = form.attr("action"); - - Elements formInputs = form.select("input"); - for (int j = 0; j < formInputs.size(); j++) { - if (formInputs.get(i).attr("name").equals("options[]")) { - entries.add(new Poll.Entry(formInputs.get(i).text())); - } else if (formInputs.get(i).attr("name").equals("sc")) { - sc = formInputs.get(i).attr("value"); + sc = form.select("input[name=sc]").first().attr("value"); + + int rowIndex = -1; + Elements possibleEntriesRows = form.child(0).child(0).children(); + for (int j = 0; j < possibleEntriesRows.size(); j++) { + if (possibleEntriesRows.get(j).select("input").size() > 0) { + rowIndex = j; + break; } } + String entriesRaw = form.child(0).child(0).child(rowIndex).child(0).html(); + Matcher entryMatcher = Pattern.compile(">[^<]+ 0) { diff --git a/app/src/main/res/layout/activity_topic_poll.xml b/app/src/main/res/layout/activity_topic_poll.xml index 5a63eb03..5c779274 100644 --- a/app/src/main/res/layout/activity_topic_poll.xml +++ b/app/src/main/res/layout/activity_topic_poll.xml @@ -15,7 +15,8 @@ + android:layout_height="200dp" + android:visibility="gone"/> + android:visibility="gone" + android:layout_marginEnd="16dp"/> @@ -53,6 +56,7 @@ android:id="@+id/show_poll_options_button" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginEnd="16dp" android:text="@string/show_vote_results_button" android:visibility="gone" /> @@ -60,7 +64,9 @@ android:id="@+id/submit_button" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginEnd="16dp" android:text="@string/submit" + android:textColor="@color/accent" android:visibility="gone"/> \ No newline at end of file