|
@ -42,6 +42,7 @@ import com.github.mikephil.charting.data.BarDataSet; |
|
|
import com.github.mikephil.charting.data.BarEntry; |
|
|
import com.github.mikephil.charting.data.BarEntry; |
|
|
import com.squareup.picasso.Picasso; |
|
|
import com.squareup.picasso.Picasso; |
|
|
|
|
|
|
|
|
|
|
|
import java.text.DecimalFormat; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Objects; |
|
|
import java.util.Objects; |
|
@ -166,10 +167,13 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
|
|
|
|
|
|
boolean pollSupported = true; |
|
|
boolean pollSupported = true; |
|
|
for (Poll.Entry entry : entries) { |
|
|
for (Poll.Entry entry : entries) { |
|
|
if (ThmmyParser.containsHtml(entry.getEntryName())) pollSupported = false; |
|
|
if (ThmmyParser.containsHtml(entry.getEntryName())){ |
|
|
break; |
|
|
pollSupported = false; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
if (ThmmyParser.containsHtml(poll.getQuestion())) pollSupported = false; |
|
|
if (ThmmyParser.containsHtml(poll.getQuestion())) |
|
|
|
|
|
pollSupported = false; |
|
|
if (!pollSupported) { |
|
|
if (!pollSupported) { |
|
|
holder.optionsLayout.setVisibility(View.GONE); |
|
|
holder.optionsLayout.setVisibility(View.GONE); |
|
|
holder.voteChart.setVisibility(View.GONE); |
|
|
holder.voteChart.setVisibility(View.GONE); |
|
@ -193,6 +197,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
holder.errorTextview.setVisibility(View.GONE); |
|
|
holder.errorTextview.setVisibility(View.GONE); |
|
|
|
|
|
|
|
|
final int primaryTextColor = context.getResources().getColor(R.color.primary_text); |
|
|
final int primaryTextColor = context.getResources().getColor(R.color.primary_text); |
|
|
|
|
|
final int accentColor = context.getResources().getColor(R.color.accent); |
|
|
|
|
|
|
|
|
if (poll.getAvailableVoteCount() > 1) { |
|
|
if (poll.getAvailableVoteCount() > 1) { |
|
|
for (Poll.Entry entry : entries) { |
|
|
for (Poll.Entry entry : entries) { |
|
@ -239,19 +244,21 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
//Showing results
|
|
|
//Showing results
|
|
|
holder.optionsLayout.setVisibility(View.GONE); |
|
|
holder.optionsLayout.setVisibility(View.GONE); |
|
|
List<BarEntry> valuesToCompare = new ArrayList<>(); |
|
|
List<BarEntry> valuesToCompare = new ArrayList<>(); |
|
|
|
|
|
int totalVotes = 0; |
|
|
for (int i = 0; i < entries.length; i++) { |
|
|
for (int i = 0; i < entries.length; i++) { |
|
|
valuesToCompare.add(new BarEntry(i, entries[i].getVotes())); |
|
|
valuesToCompare.add(new BarEntry(i, entries[i].getVotes())); |
|
|
|
|
|
totalVotes += entries[i].getVotes(); |
|
|
} |
|
|
} |
|
|
BarDataSet dataSet = new BarDataSet(valuesToCompare, "Vote Results"); |
|
|
BarDataSet dataSet = new BarDataSet(valuesToCompare, "Vote Results"); |
|
|
dataSet.setDrawValues(true); |
|
|
dataSet.setDrawValues(true); |
|
|
dataSet.setColor(context.getResources().getColor(R.color.accent)); |
|
|
dataSet.setColor(accentColor); |
|
|
dataSet.setValueTextColor(primaryTextColor); |
|
|
dataSet.setValueTextColor(accentColor); |
|
|
|
|
|
|
|
|
YAxis yAxisLeft = holder.voteChart.getAxisLeft(); |
|
|
YAxis yAxisLeft = holder.voteChart.getAxisLeft(); |
|
|
yAxisLeft.setGranularity(1); |
|
|
yAxisLeft.setGranularity(1); |
|
|
yAxisLeft.setTextColor(primaryTextColor); |
|
|
yAxisLeft.setTextColor(primaryTextColor); |
|
|
yAxisLeft.setAxisMinimum(0); |
|
|
yAxisLeft.setAxisMinimum(0); |
|
|
yAxisLeft.setSpaceTop(30f); |
|
|
yAxisLeft.setSpaceTop(40f); |
|
|
YAxis yAxisRight = holder.voteChart.getAxisRight(); |
|
|
YAxis yAxisRight = holder.voteChart.getAxisRight(); |
|
|
yAxisRight.setEnabled(false); |
|
|
yAxisRight.setEnabled(false); |
|
|
|
|
|
|
|
@ -265,6 +272,12 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
xAxis.setPosition(XAxis.XAxisPosition.TOP_INSIDE); |
|
|
xAxis.setPosition(XAxis.XAxisPosition.TOP_INSIDE); |
|
|
|
|
|
|
|
|
BarData barData = new BarData(dataSet); |
|
|
BarData barData = new BarData(dataSet); |
|
|
|
|
|
int finalSum = totalVotes; |
|
|
|
|
|
barData.setValueFormatter((value, entry, dataSetIndex, viewPortHandler) -> { |
|
|
|
|
|
DecimalFormat format = new DecimalFormat("###.#%"); |
|
|
|
|
|
double percentage = ((double) value / (double) finalSum); |
|
|
|
|
|
return "" + (int) value + " (" + format.format(percentage) + ")"; |
|
|
|
|
|
}); |
|
|
holder.voteChart.setData(barData); |
|
|
holder.voteChart.setData(barData); |
|
|
holder.voteChart.getLegend().setEnabled(false); |
|
|
holder.voteChart.getLegend().setEnabled(false); |
|
|
holder.voteChart.getDescription().setEnabled(false); |
|
|
holder.voteChart.getDescription().setEnabled(false); |
|
@ -509,9 +522,9 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
holder.overflowButton.setOnClickListener(view -> { |
|
|
holder.overflowButton.setOnClickListener(view -> { |
|
|
//Inflates the popup menu content
|
|
|
//Inflates the popup menu content
|
|
|
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
|
|
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
|
|
if (layoutInflater == null) { |
|
|
if (layoutInflater == null) |
|
|
return; |
|
|
return; |
|
|
} |
|
|
|
|
|
View popUpContent = layoutInflater.inflate(R.layout.activity_topic_overflow_menu, null); |
|
|
View popUpContent = layoutInflater.inflate(R.layout.activity_topic_overflow_menu, null); |
|
|
|
|
|
|
|
|
//Creates the PopupWindow
|
|
|
//Creates the PopupWindow
|
|
@ -795,7 +808,6 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
voteChart = itemView.findViewById(R.id.vote_chart); |
|
|
voteChart = itemView.findViewById(R.id.vote_chart); |
|
|
voteChart.setScaleEnabled(false); |
|
|
voteChart.setScaleEnabled(false); |
|
|
voteChart.setTouchEnabled(false); |
|
|
voteChart.setTouchEnabled(false); |
|
|
voteChart.setDrawValueAboveBar(false); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|