1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-12-23 13:26:59 +00:00

Fixing codacy warnings/issues (Ongoing)

This commit is contained in:
Ammar Githam 2020-09-06 03:51:41 +09:00
parent 4efd2cb6ac
commit 4130026cad
10 changed files with 63 additions and 62 deletions

View File

@ -76,6 +76,7 @@ public final class CommentsAdapter extends RecyclerView.Adapter<CommentViewHolde
final boolean isParent, final boolean isParent,
final View.OnClickListener onClickListener, final View.OnClickListener onClickListener,
final MentionClickListener mentionClickListener) { final MentionClickListener mentionClickListener) {
super();
this.commentModels = this.filteredCommentModels = commentModels; this.commentModels = this.filteredCommentModels = commentModels;
this.isParent = isParent; this.isParent = isParent;
this.onClickListener = onClickListener; this.onClickListener = onClickListener;

View File

@ -44,8 +44,8 @@ public final class DiscoverAdapter extends MultiSelectListAdapter<DiscoverItemMo
if (itemModel != null) { if (itemModel != null) {
itemModel.setPosition(position); itemModel.setPosition(position);
holder.itemView.setTag(itemModel); holder.itemView.setTag(itemModel);
holder.itemView.setOnClickListener(v -> internalOnItemClickListener.onItemClick(itemModel, position)); holder.itemView.setOnClickListener(v -> getInternalOnItemClickListener().onItemClick(itemModel, position));
holder.itemView.setOnLongClickListener(v -> internalOnLongItemClickListener.onItemLongClick(itemModel, position)); holder.itemView.setOnLongClickListener(v -> getInternalOnLongItemClickListener().onItemLongClick(itemModel, position));
final MediaItemType mediaType = itemModel.getItemType(); final MediaItemType mediaType = itemModel.getItemType();
holder.typeIcon.setVisibility(mediaType == MediaItemType.MEDIA_TYPE_VIDEO || mediaType == MediaItemType.MEDIA_TYPE_SLIDER ? View.VISIBLE : View.GONE); 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); holder.typeIcon.setImageResource(mediaType == MediaItemType.MEDIA_TYPE_SLIDER ? R.drawable.slider : R.drawable.video);

View File

@ -1,7 +1,6 @@
package awais.instagrabber.adapters; package awais.instagrabber.adapters;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.recyclerview.widget.AsyncDifferConfig;
import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ListAdapter; import androidx.recyclerview.widget.ListAdapter;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -9,14 +8,20 @@ import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public abstract class MultiSelectListAdapter<T extends MultiSelectListAdapter.Selectable, VH extends RecyclerView.ViewHolder> extends ListAdapter<T, VH> { public abstract class MultiSelectListAdapter<T extends MultiSelectListAdapter.Selectable, VH extends RecyclerView.ViewHolder> extends
ListAdapter<T, VH> {
private boolean isSelecting = false; private boolean isSelecting;
private OnItemClickListener<T> clickListener; private final OnItemClickListener<T> internalOnItemClickListener;
private OnItemLongClickListener<T> longClickListener; private final OnItemLongClickListener<T> internalOnLongItemClickListener;
private final List<T> selectedItems = new ArrayList<>(); private final List<T> selectedItems = new ArrayList<>();
protected final OnItemClickListener<T> internalOnItemClickListener = (item, position) -> {
protected MultiSelectListAdapter(@NonNull final DiffUtil.ItemCallback<T> diffCallback,
final OnItemClickListener<T> clickListener,
final OnItemLongClickListener<T> longClickListener) {
super(diffCallback);
internalOnItemClickListener = (item, position) -> {
if (isSelecting) { if (isSelecting) {
toggleSelection(item, position); toggleSelection(item, position);
} }
@ -25,7 +30,7 @@ public abstract class MultiSelectListAdapter<T extends MultiSelectListAdapter.Se
} }
clickListener.onItemClick(item, position); clickListener.onItemClick(item, position);
}; };
protected final OnItemLongClickListener<T> internalOnLongItemClickListener = (item, position) -> { internalOnLongItemClickListener = (item, position) -> {
if (!isSelecting) { if (!isSelecting) {
isSelecting = true; isSelecting = true;
} }
@ -35,21 +40,14 @@ public abstract class MultiSelectListAdapter<T extends MultiSelectListAdapter.Se
} }
return longClickListener.onItemLongClick(item, position); return longClickListener.onItemLongClick(item, position);
}; };
protected MultiSelectListAdapter(@NonNull final DiffUtil.ItemCallback<T> diffCallback,
final OnItemClickListener<T> clickListener,
final OnItemLongClickListener<T> longClickListener) {
super(diffCallback);
this.clickListener = clickListener;
this.longClickListener = longClickListener;
} }
protected MultiSelectListAdapter(@NonNull final AsyncDifferConfig<T> config, public OnItemClickListener<T> getInternalOnItemClickListener() {
final OnItemClickListener<T> clickListener, return internalOnItemClickListener;
final OnItemLongClickListener<T> longClickListener) { }
super(config);
this.clickListener = clickListener; public OnItemLongClickListener<T> getInternalOnLongItemClickListener() {
this.longClickListener = longClickListener; return internalOnLongItemClickListener;
} }
private void toggleSelection(final T item, final int position) { private void toggleSelection(final T item, final int position) {

View File

@ -12,7 +12,7 @@ import awais.instagrabber.models.PostModel;
public final class PostsAdapter extends MultiSelectListAdapter<PostModel, PostViewHolder> { public final class PostsAdapter extends MultiSelectListAdapter<PostModel, PostViewHolder> {
private static final DiffUtil.ItemCallback<PostModel> diffCallback = new DiffUtil.ItemCallback<PostModel>() { private static final DiffUtil.ItemCallback<PostModel> DIFF_CALLBACK = new DiffUtil.ItemCallback<PostModel>() {
@Override @Override
public boolean areItemsTheSame(@NonNull final PostModel oldItem, @NonNull final PostModel newItem) { public boolean areItemsTheSame(@NonNull final PostModel oldItem, @NonNull final PostModel newItem) {
return oldItem.getPostId().equals(newItem.getPostId()); return oldItem.getPostId().equals(newItem.getPostId());
@ -26,7 +26,7 @@ public final class PostsAdapter extends MultiSelectListAdapter<PostModel, PostVi
public PostsAdapter(final OnItemClickListener<PostModel> clickListener, public PostsAdapter(final OnItemClickListener<PostModel> clickListener,
final OnItemLongClickListener<PostModel> longClickListener) { final OnItemLongClickListener<PostModel> longClickListener) {
super(diffCallback, clickListener, longClickListener); super(DIFF_CALLBACK, clickListener, longClickListener);
} }
@NonNull @NonNull
@ -40,6 +40,6 @@ public final class PostsAdapter extends MultiSelectListAdapter<PostModel, PostVi
@Override @Override
public void onBindViewHolder(@NonNull final PostViewHolder holder, final int position) { public void onBindViewHolder(@NonNull final PostViewHolder holder, final int position) {
final PostModel postModel = getItem(position); final PostModel postModel = getItem(position);
holder.bind(postModel, position, internalOnItemClickListener, internalOnLongItemClickListener); holder.bind(postModel, position, getInternalOnItemClickListener(), getInternalOnLongItemClickListener());
} }
} }

View File

@ -114,7 +114,11 @@ public abstract class FeedItemViewHolder extends RecyclerView.ViewHolder {
final TextView.BufferType bufferType = caption instanceof Spanned ? TextView.BufferType.SPANNABLE : TextView.BufferType.NORMAL; final TextView.BufferType bufferType = caption instanceof Spanned ? TextView.BufferType.SPANNABLE : TextView.BufferType.NORMAL;
if (!textView.isCaptionExpanded()) { if (textView.isCaptionExpanded()) {
textView.setText(caption, bufferType);
textView.setCaptionIsExpanded(false);
return true;
}
int i = Utils.indexOfChar(caption, '\r', 0); int i = Utils.indexOfChar(caption, '\r', 0);
if (i == -1) i = Utils.indexOfChar(caption, '\n', 0); if (i == -1) i = Utils.indexOfChar(caption, '\n', 0);
if (i == -1) i = MAX_CHARS; if (i == -1) i = MAX_CHARS;
@ -127,10 +131,6 @@ public abstract class FeedItemViewHolder extends RecyclerView.ViewHolder {
textView.setText(Utils.getMentionText(caption), TextView.BufferType.SPANNABLE); textView.setText(Utils.getMentionText(caption), TextView.BufferType.SPANNABLE);
textView.setCaptionIsExpandable(true); textView.setCaptionIsExpandable(true);
textView.setCaptionIsExpanded(true); textView.setCaptionIsExpanded(true);
} else {
textView.setText(caption, bufferType);
textView.setCaptionIsExpanded(false);
}
return true; return true;
} }

View File

@ -93,7 +93,9 @@ public class FeedSliderViewHolder extends FeedItemViewHolder {
} }
} }
final ChildMediaItemsAdapter itemsAdapter = new ChildMediaItemsAdapter(sliderItems, final ChildMediaItemsAdapter itemsAdapter = new ChildMediaItemsAdapter(sliderItems,
cacheDataSourceFactory != null ? cacheDataSourceFactory : dataSourceFactory, cacheDataSourceFactory != null
? cacheDataSourceFactory
: dataSourceFactory,
playerChangeListener); playerChangeListener);
binding.mediaList.setAdapter(itemsAdapter); binding.mediaList.setAdapter(itemsAdapter);
@ -329,7 +331,7 @@ public class FeedSliderViewHolder extends FeedItemViewHolder {
@Override @Override
public boolean isViewFromObject(@NonNull final View view, @NonNull final Object object) { public boolean isViewFromObject(@NonNull final View view, @NonNull final Object object) {
return view == object; return view.equals(object);
} }
public ViewerPostModel getItemAtPosition(final int position) { public ViewerPostModel getItemAtPosition(final int position) {

View File

@ -41,7 +41,7 @@ public class FeedVideoViewHolder extends FeedItemViewHolder {
private FeedModel feedModel; private FeedModel feedModel;
private SimpleExoPlayer player; private SimpleExoPlayer player;
final Runnable loadRunnable = new Runnable() { private final Runnable loadRunnable = new Runnable() {
@Override @Override
public void run() { public void run() {
loadPlayer(feedModel); loadPlayer(feedModel);

View File

@ -176,7 +176,7 @@ public final class DiscoverFetcher extends AsyncTask<Void, Void, DiscoverItemMod
final String customPath = settingsHelper.getString(FOLDER_PATH); final String customPath = settingsHelper.getString(FOLDER_PATH);
if (!Utils.isEmpty(customPath)) customDir = new File(customPath + if (!Utils.isEmpty(customPath)) customDir = new File(customPath +
(Utils.settingsHelper.getBoolean(DOWNLOAD_USER_FOLDER) (Utils.settingsHelper.getBoolean(DOWNLOAD_USER_FOLDER)
? ("/" + username) ? "/" + username
: "")); : ""));
} }

View File

@ -39,7 +39,7 @@ public class RespondAction extends AsyncTask<String, Void, Boolean> {
+ storyModel.getStoryMediaId().split("_")[0] + "/" + questionModel.getId() + "/story_question_response/"; + storyModel.getStoryMediaId().split("_")[0] + "/" + questionModel.getId() + "/story_question_response/";
HttpURLConnection urlConnection = null; HttpURLConnection urlConnection = null;
try { 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() + "\",\"mutation_token\":\"" + UUID.randomUUID().toString()
+ "\",\"_csrftoken\":\"" + cookie.split("csrftoken=")[1].split(";")[0] + "\",\"_csrftoken\":\"" + cookie.split("csrftoken=")[1].split(";")[0]
+ "\",\"_uid\":\"" + Utils.getUserIdFromCookie(cookie) + "\",\"_uid\":\"" + Utils.getUserIdFromCookie(cookie)

View File

@ -24,7 +24,7 @@ public class SeenAction extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
final String url = "https://www.instagram.com/stories/reel/seen"; final String url = "https://www.instagram.com/stories/reel/seen";
try { try {
String urlParameters = "reelMediaId=" + storyModel.getStoryMediaId().split("_")[0] final String urlParameters = "reelMediaId=" + storyModel.getStoryMediaId().split("_")[0]
+ "&reelMediaOwnerId=" + storyModel.getUserId() + "&reelMediaOwnerId=" + storyModel.getUserId()
+ "&reelId=" + storyModel.getUserId() + "&reelId=" + storyModel.getUserId()
+ "&reelMediaTakenAt=" + storyModel.getTimestamp() + "&reelMediaTakenAt=" + storyModel.getTimestamp()