aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-01-12 03:31:34 +0000
committerDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-01-12 03:31:34 +0000
commitd98c02d0adc026dfca3bcc9a294ee3e9fddb80f3 (patch)
tree57f95aa9821033e9553866f3900d1cfc737896fd /app/src/main/java
parent0e4027fbbea76ee30ded1e5c9c09f1d592619250 (diff)
downloadinfinity-for-reddit-d98c02d0adc026dfca3bcc9a294ee3e9fddb80f3.tar
infinity-for-reddit-d98c02d0adc026dfca3bcc9a294ee3e9fddb80f3.tar.gz
infinity-for-reddit-d98c02d0adc026dfca3bcc9a294ee3e9fddb80f3.tar.bz2
infinity-for-reddit-d98c02d0adc026dfca3bcc9a294ee3e9fddb80f3.tar.lz
infinity-for-reddit-d98c02d0adc026dfca3bcc9a294ee3e9fddb80f3.tar.xz
infinity-for-reddit-d98c02d0adc026dfca3bcc9a294ee3e9fddb80f3.tar.zst
infinity-for-reddit-d98c02d0adc026dfca3bcc9a294ee3e9fddb80f3.zip
Fix NullPointerException when invoking onClick.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/markdown/CustomMarkwonAdapter.java39
1 files changed, 23 insertions, 16 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/CustomMarkwonAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/CustomMarkwonAdapter.java
index 1f2ce94c..e83d5597 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/CustomMarkwonAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/CustomMarkwonAdapter.java
@@ -12,6 +12,7 @@ import android.widget.TextView;
import androidx.annotation.IdRes;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import org.commonmark.node.Node;
@@ -35,7 +36,9 @@ public class CustomMarkwonAdapter extends MarkwonAdapter {
private Markwon markwon;
private List<Node> nodes;
+ @Nullable
private View.OnClickListener onClickListener;
+ @Nullable
private View.OnLongClickListener onLongClickListener;
@SuppressWarnings("WeakerAccess")
@@ -50,11 +53,11 @@ public class CustomMarkwonAdapter extends MarkwonAdapter {
setHasStableIds(true);
}
- public void setOnClickListener(View.OnClickListener onClickListener) {
+ public void setOnClickListener(@Nullable View.OnClickListener onClickListener) {
this.onClickListener = onClickListener;
}
- public void setOnLongClickListener(View.OnLongClickListener onLongClickListener) {
+ public void setOnLongClickListener(@Nullable View.OnLongClickListener onLongClickListener) {
this.onLongClickListener = onLongClickListener;
}
@@ -161,25 +164,29 @@ public class CustomMarkwonAdapter extends MarkwonAdapter {
}
if (node instanceof ImageAndGifBlock) {
- if (!holder.itemView.hasOnClickListeners()) {
+ if (onClickListener != null) {
holder.itemView.setOnClickListener(onClickListener);
+ }
+ if (onLongClickListener != null) {
holder.itemView.setOnLongClickListener(onLongClickListener);
}
if (holder instanceof ImageAndGifEntry.Holder) {
- if (!((ImageAndGifEntry.Holder) holder).binding.captionTextViewMarkdownImageAndGifBlock.hasOnClickListeners()) {
- ((ImageAndGifEntry.Holder) holder).binding.captionTextViewMarkdownImageAndGifBlock.setOnClickListener(view -> {
- if (onClickListener != null && ((ImageAndGifEntry.Holder) holder).binding.captionTextViewMarkdownImageAndGifBlock.getSelectionStart() == -1 && ((ImageAndGifEntry.Holder) holder).binding.captionTextViewMarkdownImageAndGifBlock.getSelectionEnd() == -1) {
- onClickListener.onClick(view);
- }
- });
- ((ImageAndGifEntry.Holder) holder).binding.captionTextViewMarkdownImageAndGifBlock.setOnLongClickListener(view -> {
- if (onLongClickListener != null && ((ImageAndGifEntry.Holder) holder).binding.captionTextViewMarkdownImageAndGifBlock.getSelectionStart() == -1 && ((ImageAndGifEntry.Holder) holder).binding.captionTextViewMarkdownImageAndGifBlock.getSelectionEnd() == -1) {
- return onLongClickListener.onLongClick(view);
- }
- return false;
- });
- }
+ ((ImageAndGifEntry.Holder) holder).binding.captionTextViewMarkdownImageAndGifBlock.setOnClickListener(view -> {
+ if (onClickListener != null
+ && ((ImageAndGifEntry.Holder) holder).binding.captionTextViewMarkdownImageAndGifBlock.getSelectionStart() == -1
+ && ((ImageAndGifEntry.Holder) holder).binding.captionTextViewMarkdownImageAndGifBlock.getSelectionEnd() == -1) {
+ onClickListener.onClick(view);
+ }
+ });
+ ((ImageAndGifEntry.Holder) holder).binding.captionTextViewMarkdownImageAndGifBlock.setOnLongClickListener(view -> {
+ if (onLongClickListener != null
+ && ((ImageAndGifEntry.Holder) holder).binding.captionTextViewMarkdownImageAndGifBlock.getSelectionStart() == -1
+ && ((ImageAndGifEntry.Holder) holder).binding.captionTextViewMarkdownImageAndGifBlock.getSelectionEnd() == -1) {
+ return onLongClickListener.onLongClick(view);
+ }
+ return false;
+ });
}
}
}