From 8e2e815b840ae2342f5aedb46739fd2a1d89dce5 Mon Sep 17 00:00:00 2001 From: Levi Bard Date: Fri, 2 Oct 2020 21:18:39 +0200 Subject: [PATCH] Set onClick listener for poll result view. (#1946) Fixes #1861 --- .../com/keylesspalace/tusky/adapter/PollAdapter.kt | 7 +++++-- .../tusky/adapter/StatusBaseViewHolder.java | 10 ++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/PollAdapter.kt b/app/src/main/java/com/keylesspalace/tusky/adapter/PollAdapter.kt index 8da82d22..a990d326 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/PollAdapter.kt +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/PollAdapter.kt @@ -37,18 +37,21 @@ class PollAdapter: RecyclerView.Adapter() { private var votersCount: Int? = null private var mode = RESULT private var emojis: List = emptyList() + private var resultClickListener: View.OnClickListener? = null fun setup( options: List, voteCount: Int, votersCount: Int?, emojis: List, - mode: Int) { + mode: Int, + resultClickListener: View.OnClickListener?) { this.pollOptions = options this.voteCount = voteCount this.votersCount = votersCount this.emojis = emojis this.mode = mode + this.resultClickListener = resultClickListener notifyDataSetChanged() } @@ -84,7 +87,7 @@ class PollAdapter: RecyclerView.Adapter() { val level = percent * 100 holder.resultTextView.background.level = level - + holder.resultTextView.setOnClickListener(resultClickListener) } SINGLE -> { val emojifiedPollOptionText = option.title.emojify(emojis, holder.radioButton) diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java index 4fe7b707..655f43b6 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java @@ -915,12 +915,18 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { if (expired || poll.getVoted()) { // no voting possible - pollAdapter.setup(poll.getOptions(), poll.getVotesCount(), poll.getVotersCount(), emojis, PollAdapter.RESULT); + View.OnClickListener viewThreadListener = v -> { + int position = getAdapterPosition(); + if (position != RecyclerView.NO_POSITION) { + listener.onViewThread(position); + } + }; + pollAdapter.setup(poll.getOptions(), poll.getVotesCount(), poll.getVotersCount(), emojis, PollAdapter.RESULT, viewThreadListener); pollButton.setVisibility(View.GONE); } else { // voting possible - pollAdapter.setup(poll.getOptions(), poll.getVotesCount(), poll.getVotersCount(), emojis, poll.getMultiple() ? PollAdapter.MULTIPLE : PollAdapter.SINGLE); + pollAdapter.setup(poll.getOptions(), poll.getVotesCount(), poll.getVotersCount(), emojis, poll.getMultiple() ? PollAdapter.MULTIPLE : PollAdapter.SINGLE, null); pollButton.setVisibility(View.VISIBLE);