From 4130026caddd5f0243adcc067f7e0eaf930df3fe Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sun, 6 Sep 2020 03:51:41 +0900 Subject: [PATCH] Fixing codacy warnings/issues (Ongoing) --- .../adapters/CommentsAdapter.java | 1 + .../adapters/DiscoverAdapter.java | 4 +- .../adapters/MultiSelectListAdapter.java | 62 +++++++++---------- .../instagrabber/adapters/PostsAdapter.java | 6 +- .../viewholder/feed/FeedItemViewHolder.java | 28 ++++----- .../viewholder/feed/FeedSliderViewHolder.java | 16 ++--- .../viewholder/feed/FeedVideoViewHolder.java | 2 +- .../instagrabber/asyncs/DiscoverFetcher.java | 2 +- .../instagrabber/asyncs/RespondAction.java | 2 +- .../awais/instagrabber/asyncs/SeenAction.java | 2 +- 10 files changed, 63 insertions(+), 62 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/adapters/CommentsAdapter.java b/app/src/main/java/awais/instagrabber/adapters/CommentsAdapter.java index 77e308cd..66d5af6f 100755 --- a/app/src/main/java/awais/instagrabber/adapters/CommentsAdapter.java +++ b/app/src/main/java/awais/instagrabber/adapters/CommentsAdapter.java @@ -76,6 +76,7 @@ public final class CommentsAdapter extends RecyclerView.Adapter internalOnItemClickListener.onItemClick(itemModel, position)); - holder.itemView.setOnLongClickListener(v -> internalOnLongItemClickListener.onItemLongClick(itemModel, position)); + holder.itemView.setOnClickListener(v -> getInternalOnItemClickListener().onItemClick(itemModel, position)); + holder.itemView.setOnLongClickListener(v -> getInternalOnLongItemClickListener().onItemLongClick(itemModel, position)); final MediaItemType mediaType = itemModel.getItemType(); holder.typeIcon.setVisibility(mediaType == MediaItemType.MEDIA_TYPE_VIDEO || mediaType == MediaItemType.MEDIA_TYPE_SLIDER ? View.VISIBLE : View.GONE); holder.typeIcon.setImageResource(mediaType == MediaItemType.MEDIA_TYPE_SLIDER ? R.drawable.slider : R.drawable.video); diff --git a/app/src/main/java/awais/instagrabber/adapters/MultiSelectListAdapter.java b/app/src/main/java/awais/instagrabber/adapters/MultiSelectListAdapter.java index 392be0c1..d196b2c9 100644 --- a/app/src/main/java/awais/instagrabber/adapters/MultiSelectListAdapter.java +++ b/app/src/main/java/awais/instagrabber/adapters/MultiSelectListAdapter.java @@ -1,7 +1,6 @@ package awais.instagrabber.adapters; import androidx.annotation.NonNull; -import androidx.recyclerview.widget.AsyncDifferConfig; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.ListAdapter; import androidx.recyclerview.widget.RecyclerView; @@ -9,47 +8,46 @@ import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; import java.util.List; -public abstract class MultiSelectListAdapter extends ListAdapter { +public abstract class MultiSelectListAdapter extends + ListAdapter { - private boolean isSelecting = false; - private OnItemClickListener clickListener; - private OnItemLongClickListener longClickListener; + private boolean isSelecting; + private final OnItemClickListener internalOnItemClickListener; + private final OnItemLongClickListener internalOnLongItemClickListener; private final List selectedItems = new ArrayList<>(); - protected final OnItemClickListener internalOnItemClickListener = (item, position) -> { - if (isSelecting) { - toggleSelection(item, position); - } - if (clickListener == null) { - return; - } - clickListener.onItemClick(item, position); - }; - protected final OnItemLongClickListener internalOnLongItemClickListener = (item, position) -> { - if (!isSelecting) { - isSelecting = true; - } - toggleSelection(item, position); - if (longClickListener == null) { - return true; - } - return longClickListener.onItemLongClick(item, position); - }; protected MultiSelectListAdapter(@NonNull final DiffUtil.ItemCallback diffCallback, final OnItemClickListener clickListener, final OnItemLongClickListener longClickListener) { super(diffCallback); - this.clickListener = clickListener; - this.longClickListener = longClickListener; + internalOnItemClickListener = (item, position) -> { + if (isSelecting) { + toggleSelection(item, position); + } + if (clickListener == null) { + return; + } + clickListener.onItemClick(item, position); + }; + internalOnLongItemClickListener = (item, position) -> { + if (!isSelecting) { + isSelecting = true; + } + toggleSelection(item, position); + if (longClickListener == null) { + return true; + } + return longClickListener.onItemLongClick(item, position); + }; } - protected MultiSelectListAdapter(@NonNull final AsyncDifferConfig config, - final OnItemClickListener clickListener, - final OnItemLongClickListener longClickListener) { - super(config); - this.clickListener = clickListener; - this.longClickListener = longClickListener; + public OnItemClickListener getInternalOnItemClickListener() { + return internalOnItemClickListener; + } + + public OnItemLongClickListener getInternalOnLongItemClickListener() { + return internalOnLongItemClickListener; } private void toggleSelection(final T item, final int position) { diff --git a/app/src/main/java/awais/instagrabber/adapters/PostsAdapter.java b/app/src/main/java/awais/instagrabber/adapters/PostsAdapter.java index 9365357e..521f261a 100755 --- a/app/src/main/java/awais/instagrabber/adapters/PostsAdapter.java +++ b/app/src/main/java/awais/instagrabber/adapters/PostsAdapter.java @@ -12,7 +12,7 @@ import awais.instagrabber.models.PostModel; public final class PostsAdapter extends MultiSelectListAdapter { - private static final DiffUtil.ItemCallback diffCallback = new DiffUtil.ItemCallback() { + private static final DiffUtil.ItemCallback DIFF_CALLBACK = new DiffUtil.ItemCallback() { @Override public boolean areItemsTheSame(@NonNull final PostModel oldItem, @NonNull final PostModel newItem) { return oldItem.getPostId().equals(newItem.getPostId()); @@ -26,7 +26,7 @@ public final class PostsAdapter extends MultiSelectListAdapter clickListener, final OnItemLongClickListener longClickListener) { - super(diffCallback, clickListener, longClickListener); + super(DIFF_CALLBACK, clickListener, longClickListener); } @NonNull @@ -40,6 +40,6 @@ public final class PostsAdapter extends MultiSelectListAdapter { + storyModel.getStoryMediaId().split("_")[0] + "/" + questionModel.getId() + "/story_question_response/"; HttpURLConnection urlConnection = null; try { - JSONObject ogbody = new JSONObject("{\"client_context\":\"" + UUID.randomUUID().toString() + final JSONObject ogbody = new JSONObject("{\"client_context\":\"" + UUID.randomUUID().toString() + "\",\"mutation_token\":\"" + UUID.randomUUID().toString() + "\",\"_csrftoken\":\"" + cookie.split("csrftoken=")[1].split(";")[0] + "\",\"_uid\":\"" + Utils.getUserIdFromCookie(cookie) diff --git a/app/src/main/java/awais/instagrabber/asyncs/SeenAction.java b/app/src/main/java/awais/instagrabber/asyncs/SeenAction.java index 805942e9..39a798ae 100644 --- a/app/src/main/java/awais/instagrabber/asyncs/SeenAction.java +++ b/app/src/main/java/awais/instagrabber/asyncs/SeenAction.java @@ -24,7 +24,7 @@ public class SeenAction extends AsyncTask { protected Void doInBackground(Void... voids) { final String url = "https://www.instagram.com/stories/reel/seen"; try { - String urlParameters = "reelMediaId=" + storyModel.getStoryMediaId().split("_")[0] + final String urlParameters = "reelMediaId=" + storyModel.getStoryMediaId().split("_")[0] + "&reelMediaOwnerId=" + storyModel.getUserId() + "&reelId=" + storyModel.getUserId() + "&reelMediaTakenAt=" + storyModel.getTimestamp()