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 ad8ecb28..ff766e62 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 @@ -40,13 +40,11 @@ import android.widget.RelativeLayout; import android.widget.TextView; import com.github.mikephil.charting.charts.HorizontalBarChart; -import com.github.mikephil.charting.components.AxisBase; +import com.github.mikephil.charting.components.XAxis; import com.github.mikephil.charting.components.YAxis; import com.github.mikephil.charting.data.BarData; import com.github.mikephil.charting.data.BarDataSet; import com.github.mikephil.charting.data.BarEntry; -import com.github.mikephil.charting.formatter.IAxisValueFormatter; -import com.github.mikephil.charting.interfaces.datasets.IBarDataSet; import com.squareup.picasso.Picasso; import java.util.ArrayList; @@ -188,18 +186,36 @@ class TopicAdapter extends RecyclerView.Adapter { holder.rootLayout.addView(radioGroup, 1); } else { //Showing results - ArrayList valuesToCompare = new ArrayList<>(); + List valuesToCompare = new ArrayList<>(); for (int i = 0; i < entries.length; i++) { - valuesToCompare.add(new BarEntry(entries[i].getVotes(), i)); + valuesToCompare.add(new BarEntry(i, entries[i].getVotes())); } BarDataSet data = new BarDataSet(valuesToCompare, "Vote Results"); YAxis yAxisLeft = holder.voteChart.getAxisLeft(); - yAxisLeft.setValueFormatter((value, axis) -> entries[(int) value].getEntryName()); + yAxisLeft.setGranularity(1f); + YAxis yAxisRight = holder.voteChart.getAxisRight(); + yAxisRight.setEnabled(false); + + XAxis xAxis = holder.voteChart.getXAxis(); + xAxis.setValueFormatter((value, axis) -> entries[(int) value].getEntryName()); + xAxis.setTextColor(context.getResources().getColor(R.color.primary_text)); + xAxis.setGranularity(1f); + xAxis.setDrawGridLines(false); + xAxis.setDrawAxisLine(false); + xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); BarData barData = new BarData(data); + barData.setValueTextColor(context.getResources().getColor(R.color.accent)); holder.voteChart.setData(barData); + holder.voteChart.getLegend().setEnabled(false); + holder.voteChart.getDescription().setEnabled(false); + holder.voteChart.invalidate(); } + if (poll.getRemoveVoteUrl() != null) holder.removeVotesButton.setVisibility(View.VISIBLE); + if (poll.getShowVoteResultsUrl() != null) holder.showPollResultsButton.setVisibility(View.VISIBLE); + if (poll.getShowOptionsUrl() != null) holder.showPollOptionsButton.setVisibility(View.VISIBLE); + if (poll.getPollFormUrl() != null) holder.submitButton.setVisibility(View.VISIBLE); } else { Post currentPost = (Post) topicItems.get(position); if (currentHolder instanceof PostViewHolder) { @@ -702,7 +718,7 @@ class TopicAdapter extends RecyclerView.Adapter { final TextView question, errorTooManySelected; final LinearLayout rootLayout; final AppCompatButton submitButton; - final AppCompatButton removeVotesButton; + final AppCompatButton removeVotesButton, showPollResultsButton, showPollOptionsButton; final HorizontalBarChart voteChart; public PollViewHolder(View itemView) { @@ -712,6 +728,8 @@ class TopicAdapter extends RecyclerView.Adapter { rootLayout = (LinearLayout) itemView; submitButton = itemView.findViewById(R.id.submit_button); removeVotesButton = itemView.findViewById(R.id.remove_vote_button); + showPollResultsButton = itemView.findViewById(R.id.show_poll_results_button); + showPollOptionsButton = itemView.findViewById(R.id.show_poll_options_button); errorTooManySelected = itemView.findViewById(R.id.error_too_many_checked); voteChart = itemView.findViewById(R.id.vote_chart); } 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 66c28a57..071557e9 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/Poll.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Poll.java @@ -99,5 +99,10 @@ public class Poll extends TopicItem { public void setVotes(int votes) { this.votes = votes; } + + @Override + public String toString() { + return "Vote label:" + entryName + ", num votes:" + votes; + } } } diff --git a/app/src/main/res/layout/activity_topic_poll.xml b/app/src/main/res/layout/activity_topic_poll.xml index 9953846f..5a63eb03 100644 --- a/app/src/main/res/layout/activity_topic_poll.xml +++ b/app/src/main/res/layout/activity_topic_poll.xml @@ -1,20 +1,21 @@ - + android:layout_height="wrap_content" + android:layout_margin="16dp" + android:orientation="vertical"> + android:layout_height="wrap_content" + android:textColor="@color/primary_text" /> + android:layout_height="200dp" /> + android:visibility="gone" /> - + + - - - + + + + + + + + + + \ No newline at end of file