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 f3557d8e..345fa9e2 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 @@ -185,6 +185,7 @@ class TopicAdapter extends RecyclerView.Adapter { if (!pollSupported) { holder.optionsLayout.setVisibility(View.GONE); holder.voteChart.setVisibility(View.GONE); + holder.selectedEntry.setVisibility(View.GONE); holder.removeVotesButton.setVisibility(View.GONE); holder.showPollResultsButton.setVisibility(View.GONE); holder.hidePollResultsButton.setVisibility(View.GONE); @@ -222,6 +223,7 @@ class TopicAdapter extends RecyclerView.Adapter { holder.optionsLayout.addView(checkBox); } holder.voteChart.setVisibility(View.GONE); + holder.selectedEntry.setVisibility(View.GONE); holder.optionsLayout.setVisibility(View.VISIBLE); } else if (poll.getAvailableVoteCount() == 1) { // vote single option @@ -242,8 +244,9 @@ class TopicAdapter extends RecyclerView.Adapter { } holder.optionsLayout.addView(radioGroup); holder.voteChart.setVisibility(View.GONE); + holder.selectedEntry.setVisibility(View.GONE); holder.optionsLayout.setVisibility(View.VISIBLE); - } else if (poll.getSelectedEntryIndex() != -1) { + } else if (poll.isPollResultsHidden()) { // vote already submitted but results are hidden Poll.Entry[] entries1 = poll.getEntries(); for (int i = 0; i < entries1.length; i++) { @@ -267,6 +270,7 @@ class TopicAdapter extends RecyclerView.Adapter { holder.optionsLayout.addView(textView); } holder.voteChart.setVisibility(View.GONE); + holder.selectedEntry.setVisibility(View.GONE); holder.optionsLayout.setVisibility(View.VISIBLE); } else { // Showing results @@ -316,6 +320,12 @@ class TopicAdapter extends RecyclerView.Adapter { holder.voteChart.setMinimumHeight((int) (chartHeightDp * (metrics.densityDpi / 160f))); holder.voteChart.invalidate(); holder.voteChart.setVisibility(View.VISIBLE); + + if (poll.getSelectedEntryIndex() != -1) { + holder.selectedEntry.setText("You voted \"" + + poll.getEntries()[poll.getSelectedEntryIndex()].getEntryName() + "\""); + holder.selectedEntry.setVisibility(View.VISIBLE); + } } if (poll.getRemoveVoteUrl() != null) { holder.removeVotesButton.setOnClickListener(v -> viewModel.removeVote()); @@ -899,7 +909,7 @@ class TopicAdapter extends RecyclerView.Adapter { } static class PollViewHolder extends RecyclerView.ViewHolder { - final TextView question, errorTextview; + final TextView question, errorTextview, selectedEntry; final LinearLayout optionsLayout; final AppCompatButton submitButton; final AppCompatButton removeVotesButton, showPollResultsButton, hidePollResultsButton; @@ -916,6 +926,7 @@ class TopicAdapter extends RecyclerView.Adapter { hidePollResultsButton = itemView.findViewById(R.id.show_poll_options_button); errorTextview = itemView.findViewById(R.id.error_too_many_checked); voteChart = itemView.findViewById(R.id.vote_chart); + selectedEntry = itemView.findViewById(R.id.selected_entry_textview); voteChart.setScaleYEnabled(false); voteChart.setDoubleTapToZoomEnabled(false); } 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 ca67957b..1a7922ff 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 @@ -487,6 +487,7 @@ public class TopicParser { int availableVoteCount = 0, selectedEntryIndex = -1; String pollFormUrl = null, sc = null, removeVoteUrl = null, showVoteResultsUrl = null, showOptionsUrl = null; + boolean pollResultsHidden = false; Element pollColumn = table.select("tr[class=windowbg]").first().child(1); question = pollColumn.ownText().trim(); @@ -525,21 +526,19 @@ public class TopicParser { } } else { // poll in results mode - boolean pollResultsHidden = false; Elements entryRows = pollColumn.select("table[cellspacing] tr"); for (int i = 0; i < entryRows.size(); i++) { Element entryRow = entryRows.get(i); Elements entryColumns = entryRow.select("td"); - if (entryColumns.size() < 2) pollResultsHidden = true; + if (entryColumns.first().attr("style").contains("font-weight: bold;")) + selectedEntryIndex = i; String optionName = entryColumns.first().html(); int voteCount = 0; - if (pollResultsHidden) { - if (entryColumns.first().attr("style").contains("font-weight: bold;")) - selectedEntryIndex = i; - } else { + if (entryColumns.size() < 2) pollResultsHidden = true; + if (!pollResultsHidden) { String voteCountDescription = entryColumns.last().text(); Matcher integerMatcher = integerPattern.matcher(voteCountDescription); if (integerMatcher.find()) { @@ -560,7 +559,7 @@ public class TopicParser { } } return new Poll(question, entries.toArray(new Poll.Entry[0]), availableVoteCount, - pollFormUrl, sc, removeVoteUrl, showVoteResultsUrl, showOptionsUrl, selectedEntryIndex); + pollFormUrl, sc, removeVoteUrl, showVoteResultsUrl, showOptionsUrl, selectedEntryIndex, pollResultsHidden); } catch (Exception e) { Timber.v(e, "Could not parse a poll"); } diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/Poll.java b/app/src/main/java/gr/thmmy/mthmmy/model/Poll.java index ffd98e4d..407a357e 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/Poll.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Poll.java @@ -9,9 +9,10 @@ public class Poll extends TopicItem { private Entry[] entries; private int availableVoteCount, selectedEntryIndex = -1; private String pollFormUrl, sc, removeVoteUrl, showVoteResultsUrl, showOptionsUrl; + private boolean pollResultsHidden; public Poll(String question, Entry[] entries, int availableVoteCount, String pollFormUrl, String sc, - String removeVoteUrl, String showVoteResultsUrl, String showOptionsUrl, int selectedEntryIndex) { + String removeVoteUrl, String showVoteResultsUrl, String showOptionsUrl, int selectedEntryIndex, boolean pollResultsHidden) { this.question = question; this.entries = entries; this.availableVoteCount = availableVoteCount; @@ -21,6 +22,7 @@ public class Poll extends TopicItem { this.showVoteResultsUrl = showVoteResultsUrl; this.showOptionsUrl = showOptionsUrl; this.selectedEntryIndex = selectedEntryIndex; + this.pollResultsHidden = pollResultsHidden; } private int totalVotes() { @@ -73,6 +75,10 @@ public class Poll extends TopicItem { return selectedEntryIndex; } + public boolean isPollResultsHidden() { + return pollResultsHidden; + } + public static class Entry { private final String entryName; private int votes; diff --git a/app/src/main/res/layout/activity_topic_poll.xml b/app/src/main/res/layout/activity_topic_poll.xml index 285c740b..7b77f29a 100644 --- a/app/src/main/res/layout/activity_topic_poll.xml +++ b/app/src/main/res/layout/activity_topic_poll.xml @@ -25,6 +25,14 @@ android:layout_height="wrap_content" android:visibility="gone"/> + +