1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-18 04:37:30 +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 View.OnClickListener onClickListener,
final MentionClickListener mentionClickListener) {
super();
this.commentModels = this.filteredCommentModels = commentModels;
this.isParent = isParent;
this.onClickListener = onClickListener;

View File

@ -44,8 +44,8 @@ public final class DiscoverAdapter extends MultiSelectListAdapter<DiscoverItemMo
if (itemModel != null) {
itemModel.setPosition(position);
holder.itemView.setTag(itemModel);
holder.itemView.setOnClickListener(v -> 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);

View File

@ -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<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 OnItemClickListener<T> clickListener;
private OnItemLongClickListener<T> longClickListener;
private boolean isSelecting;
private final OnItemClickListener<T> internalOnItemClickListener;
private final OnItemLongClickListener<T> internalOnLongItemClickListener;
private final List<T> selectedItems = new ArrayList<>();
protected final OnItemClickListener<T> internalOnItemClickListener = (item, position) -> {
if (isSelecting) {
toggleSelection(item, position);
}
if (clickListener == null) {
return;
}
clickListener.onItemClick(item, position);
};
protected final OnItemLongClickListener<T> 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<T> diffCallback,
final OnItemClickListener<T> clickListener,
final OnItemLongClickListener<T> 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<T> config,
final OnItemClickListener<T> clickListener,
final OnItemLongClickListener<T> longClickListener) {
super(config);
this.clickListener = clickListener;
this.longClickListener = longClickListener;
public OnItemClickListener<T> getInternalOnItemClickListener() {
return internalOnItemClickListener;
}
public OnItemLongClickListener<T> getInternalOnLongItemClickListener() {
return internalOnLongItemClickListener;
}
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> {
private static final DiffUtil.ItemCallback<PostModel> diffCallback = new DiffUtil.ItemCallback<PostModel>() {
private static final DiffUtil.ItemCallback<PostModel> DIFF_CALLBACK = new DiffUtil.ItemCallback<PostModel>() {
@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<PostModel, PostVi
public PostsAdapter(final OnItemClickListener<PostModel> clickListener,
final OnItemLongClickListener<PostModel> longClickListener) {
super(diffCallback, clickListener, longClickListener);
super(DIFF_CALLBACK, clickListener, longClickListener);
}
@NonNull
@ -40,6 +40,6 @@ public final class PostsAdapter extends MultiSelectListAdapter<PostModel, PostVi
@Override
public void onBindViewHolder(@NonNull final PostViewHolder holder, final int position) {
final PostModel postModel = getItem(position);
holder.bind(postModel, position, internalOnItemClickListener, internalOnLongItemClickListener);
holder.bind(postModel, position, getInternalOnItemClickListener(), getInternalOnLongItemClickListener());
}
}

View File

@ -114,23 +114,23 @@ public abstract class FeedItemViewHolder extends RecyclerView.ViewHolder {
final TextView.BufferType bufferType = caption instanceof Spanned ? TextView.BufferType.SPANNABLE : TextView.BufferType.NORMAL;
if (!textView.isCaptionExpanded()) {
int i = Utils.indexOfChar(caption, '\r', 0);
if (i == -1) i = Utils.indexOfChar(caption, '\n', 0);
if (i == -1) i = MAX_CHARS;
final int captionLen = caption.length();
final int minTrim = Math.min(MAX_CHARS, i);
if (captionLen <= minTrim) return false;
if (Utils.hasMentions(caption))
textView.setText(Utils.getMentionText(caption), TextView.BufferType.SPANNABLE);
textView.setCaptionIsExpandable(true);
textView.setCaptionIsExpanded(true);
} else {
if (textView.isCaptionExpanded()) {
textView.setText(caption, bufferType);
textView.setCaptionIsExpanded(false);
return true;
}
int i = Utils.indexOfChar(caption, '\r', 0);
if (i == -1) i = Utils.indexOfChar(caption, '\n', 0);
if (i == -1) i = MAX_CHARS;
final int captionLen = caption.length();
final int minTrim = Math.min(MAX_CHARS, i);
if (captionLen <= minTrim) return false;
if (Utils.hasMentions(caption))
textView.setText(Utils.getMentionText(caption), TextView.BufferType.SPANNABLE);
textView.setCaptionIsExpandable(true);
textView.setCaptionIsExpanded(true);
return true;
}

View File

@ -93,8 +93,10 @@ public class FeedSliderViewHolder extends FeedItemViewHolder {
}
}
final ChildMediaItemsAdapter itemsAdapter = new ChildMediaItemsAdapter(sliderItems,
cacheDataSourceFactory != null ? cacheDataSourceFactory : dataSourceFactory,
playerChangeListener);
cacheDataSourceFactory != null
? cacheDataSourceFactory
: dataSourceFactory,
playerChangeListener);
binding.mediaList.setAdapter(itemsAdapter);
//noinspection deprecation
@ -176,10 +178,10 @@ public class FeedSliderViewHolder extends FeedItemViewHolder {
}
final ViewSwitcher viewSwitcher = (ViewSwitcher) binding.mediaList.getChildAt(position);
loadPlayer(binding.getRoot().getContext(),
position, sliderItem.getDisplayUrl(),
viewSwitcher,
cacheDataSourceFactory != null ? cacheDataSourceFactory : dataSourceFactory,
playerChangeListener);
position, sliderItem.getDisplayUrl(),
viewSwitcher,
cacheDataSourceFactory != null ? cacheDataSourceFactory : dataSourceFactory,
playerChangeListener);
}
public void startPlayingVideo() {
@ -329,7 +331,7 @@ public class FeedSliderViewHolder extends FeedItemViewHolder {
@Override
public boolean isViewFromObject(@NonNull final View view, @NonNull final Object object) {
return view == object;
return view.equals(object);
}
public ViewerPostModel getItemAtPosition(final int position) {

View File

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

View File

@ -176,7 +176,7 @@ public final class DiscoverFetcher extends AsyncTask<Void, Void, DiscoverItemMod
final String customPath = settingsHelper.getString(FOLDER_PATH);
if (!Utils.isEmpty(customPath)) customDir = new File(customPath +
(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/";
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)

View File

@ -24,7 +24,7 @@ public class SeenAction extends AsyncTask<Void, Void, Void> {
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()