Browse Source
More updated. Handle clicks. Updated comments viewer, etc
renovate/org.robolectric-robolectric-4.x
More updated. Handle clicks. Updated comments viewer, etc
renovate/org.robolectric-robolectric-4.x
Ammar Githam
4 years ago
48 changed files with 1859 additions and 1628 deletions
-
6.idea/compiler.xml
-
1.idea/gradle.xml
-
2.idea/misc.xml
-
8.idea/runConfigurations/app.xml
-
9app/build.gradle
-
260app/src/main/java/awais/instagrabber/adapters/CommentsAdapter.java
-
222app/src/main/java/awais/instagrabber/adapters/FeedAdapter.java
-
79app/src/main/java/awais/instagrabber/adapters/FeedAdapterV2.java
-
40app/src/main/java/awais/instagrabber/adapters/FeedItemCallbackAdapter.java
-
9app/src/main/java/awais/instagrabber/adapters/SliderItemsAdapter.java
-
95app/src/main/java/awais/instagrabber/adapters/viewholder/CommentViewHolder.java
-
31app/src/main/java/awais/instagrabber/adapters/viewholder/FeedGridItemViewHolder.java
-
54app/src/main/java/awais/instagrabber/adapters/viewholder/SliderVideoViewHolder.java
-
93app/src/main/java/awais/instagrabber/adapters/viewholder/comments/ChildCommentViewHolder.java
-
93app/src/main/java/awais/instagrabber/adapters/viewholder/comments/ParentCommentViewHolder.java
-
157app/src/main/java/awais/instagrabber/adapters/viewholder/feed/FeedItemViewHolder.java
-
109app/src/main/java/awais/instagrabber/adapters/viewholder/feed/FeedPhotoViewHolder.java
-
54app/src/main/java/awais/instagrabber/adapters/viewholder/feed/FeedSliderViewHolder.java
-
49app/src/main/java/awais/instagrabber/adapters/viewholder/feed/FeedVideoViewHolder.java
-
189app/src/main/java/awais/instagrabber/asyncs/CommentsFetcher.java
-
60app/src/main/java/awais/instagrabber/customviews/PostsRecyclerView.java
-
152app/src/main/java/awais/instagrabber/customviews/RamboTextViewV2.java
-
2app/src/main/java/awais/instagrabber/customviews/SharedElementTransitionDialogFragment.java
-
64app/src/main/java/awais/instagrabber/customviews/VideoPlayerViewHelper.java
-
70app/src/main/java/awais/instagrabber/dialogs/PostsLayoutPreferencesDialogFragment.java
-
466app/src/main/java/awais/instagrabber/fragments/CommentsViewerFragment.java
-
38app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java
-
101app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java
-
406app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java
-
2app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java
-
62app/src/main/java/awais/instagrabber/models/CommentModel.java
-
20app/src/main/java/awais/instagrabber/utils/Utils.java
-
19app/src/main/java/awais/instagrabber/viewmodels/CommentsViewModel.java
-
56app/src/main/java/awais/instagrabber/workers/DownloadWorker.java
-
26app/src/main/res/layout/dialog_post_view.xml
-
6app/src/main/res/layout/fragment_comments.xml
-
10app/src/main/res/layout/fragment_feed.xml
-
211app/src/main/res/layout/item_comment.xml
-
15app/src/main/res/layout/item_comment_small.xml
-
92app/src/main/res/layout/item_feed_bottom.xml
-
6app/src/main/res/layout/item_feed_photo.xml
-
6app/src/main/res/layout/item_feed_slider.xml
-
20app/src/main/res/layout/item_feed_top.xml
-
6app/src/main/res/layout/item_feed_video.xml
-
2app/src/main/res/layout/layout_video_player_with_thumbnail.xml
-
4app/src/main/res/navigation/comments_nav_graph.xml
-
2app/src/main/res/values/color.xml
-
3app/src/main/res/values/strings.xml
@ -0,0 +1,6 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="CompilerConfiguration"> |
|||
<bytecodeTargetLevel target="1.8" /> |
|||
</component> |
|||
</project> |
@ -1,111 +1,111 @@ |
|||
package awais.instagrabber.adapters; |
|||
|
|||
import android.content.Context; |
|||
import android.view.LayoutInflater; |
|||
import android.view.View; |
|||
import android.view.ViewGroup; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
import androidx.recyclerview.widget.DiffUtil; |
|||
import androidx.recyclerview.widget.ListAdapter; |
|||
|
|||
import awais.instagrabber.adapters.viewholder.feed.FeedItemViewHolder; |
|||
import awais.instagrabber.adapters.viewholder.feed.FeedPhotoViewHolder; |
|||
import awais.instagrabber.adapters.viewholder.feed.FeedSliderViewHolder; |
|||
import awais.instagrabber.adapters.viewholder.feed.FeedVideoViewHolder; |
|||
import awais.instagrabber.customviews.RamboTextView; |
|||
import awais.instagrabber.databinding.ItemFeedPhotoBinding; |
|||
import awais.instagrabber.databinding.ItemFeedSliderBinding; |
|||
import awais.instagrabber.databinding.ItemFeedVideoBinding; |
|||
import awais.instagrabber.interfaces.MentionClickListener; |
|||
import awais.instagrabber.models.FeedModel; |
|||
import awais.instagrabber.models.enums.MediaItemType; |
|||
import awais.instagrabber.utils.Utils; |
|||
|
|||
public final class FeedAdapter extends ListAdapter<FeedModel, FeedItemViewHolder> { |
|||
private static final String TAG = "FeedAdapter"; |
|||
private final View.OnClickListener clickListener; |
|||
private final MentionClickListener mentionClickListener; |
|||
private final View.OnLongClickListener longClickListener = v -> { |
|||
final Object tag; |
|||
if (v instanceof RamboTextView && (tag = v.getTag()) instanceof FeedModel) |
|||
Utils.copyText(v.getContext(), ((FeedModel) tag).getPostCaption()); |
|||
return true; |
|||
}; |
|||
|
|||
private static final DiffUtil.ItemCallback<FeedModel> diffCallback = new DiffUtil.ItemCallback<FeedModel>() { |
|||
@Override |
|||
public boolean areItemsTheSame(@NonNull final FeedModel oldItem, @NonNull final FeedModel newItem) { |
|||
return oldItem.getPostId().equals(newItem.getPostId()); |
|||
} |
|||
|
|||
@Override |
|||
public boolean areContentsTheSame(@NonNull final FeedModel oldItem, @NonNull final FeedModel newItem) { |
|||
return oldItem.getPostId().equals(newItem.getPostId()); |
|||
} |
|||
}; |
|||
|
|||
public FeedAdapter(final View.OnClickListener clickListener, |
|||
final MentionClickListener mentionClickListener) { |
|||
super(diffCallback); |
|||
// private final static String ellipsize = "… more"; |
|||
this.clickListener = clickListener; |
|||
this.mentionClickListener = mentionClickListener; |
|||
} |
|||
|
|||
@NonNull |
|||
@Override |
|||
public FeedItemViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) { |
|||
final Context context = parent.getContext(); |
|||
final LayoutInflater layoutInflater = LayoutInflater.from(context); |
|||
final MediaItemType type = MediaItemType.valueOf(viewType); |
|||
switch (type) { |
|||
case MEDIA_TYPE_VIDEO: { |
|||
final ItemFeedVideoBinding binding = ItemFeedVideoBinding.inflate(layoutInflater, parent, false); |
|||
return new FeedVideoViewHolder(binding, mentionClickListener, clickListener, longClickListener); |
|||
} |
|||
case MEDIA_TYPE_SLIDER: { |
|||
final ItemFeedSliderBinding binding = ItemFeedSliderBinding.inflate(layoutInflater, parent, false); |
|||
return new FeedSliderViewHolder(binding, mentionClickListener, clickListener, longClickListener); |
|||
} |
|||
case MEDIA_TYPE_IMAGE: |
|||
default: { |
|||
final ItemFeedPhotoBinding binding = ItemFeedPhotoBinding.inflate(layoutInflater, parent, false); |
|||
return new FeedPhotoViewHolder(binding, mentionClickListener, clickListener, longClickListener); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void onBindViewHolder(@NonNull final FeedItemViewHolder viewHolder, final int position) { |
|||
final FeedModel feedModel = getItem(position); |
|||
if (feedModel == null) { |
|||
return; |
|||
} |
|||
feedModel.setPosition(position); |
|||
viewHolder.bind(feedModel, (feedModel1, view, postImage) -> {}); |
|||
} |
|||
|
|||
@Override |
|||
public int getItemViewType(final int position) { |
|||
return getItem(position).getItemType().getId(); |
|||
} |
|||
|
|||
@Override |
|||
public void onViewAttachedToWindow(@NonNull final FeedItemViewHolder holder) { |
|||
super.onViewAttachedToWindow(holder); |
|||
// Log.d(TAG, "attached holder: " + holder); |
|||
if (!(holder instanceof FeedSliderViewHolder)) return; |
|||
final FeedSliderViewHolder feedSliderViewHolder = (FeedSliderViewHolder) holder; |
|||
feedSliderViewHolder.startPlayingVideo(); |
|||
} |
|||
|
|||
@Override |
|||
public void onViewDetachedFromWindow(@NonNull final FeedItemViewHolder holder) { |
|||
super.onViewDetachedFromWindow(holder); |
|||
// Log.d(TAG, "detached holder: " + holder); |
|||
if (!(holder instanceof FeedSliderViewHolder)) return; |
|||
final FeedSliderViewHolder feedSliderViewHolder = (FeedSliderViewHolder) holder; |
|||
feedSliderViewHolder.stopPlayingVideo(); |
|||
} |
|||
} |
|||
// package awais.instagrabber.adapters; |
|||
// |
|||
// import android.content.Context; |
|||
// import android.view.LayoutInflater; |
|||
// import android.view.View; |
|||
// import android.view.ViewGroup; |
|||
// |
|||
// import androidx.annotation.NonNull; |
|||
// import androidx.recyclerview.widget.DiffUtil; |
|||
// import androidx.recyclerview.widget.ListAdapter; |
|||
// |
|||
// import awais.instagrabber.adapters.viewholder.feed.FeedItemViewHolder; |
|||
// import awais.instagrabber.adapters.viewholder.feed.FeedPhotoViewHolder; |
|||
// import awais.instagrabber.adapters.viewholder.feed.FeedSliderViewHolder; |
|||
// import awais.instagrabber.adapters.viewholder.feed.FeedVideoViewHolder; |
|||
// import awais.instagrabber.customviews.RamboTextView; |
|||
// import awais.instagrabber.databinding.ItemFeedPhotoBinding; |
|||
// import awais.instagrabber.databinding.ItemFeedSliderBinding; |
|||
// import awais.instagrabber.databinding.ItemFeedVideoBinding; |
|||
// import awais.instagrabber.interfaces.MentionClickListener; |
|||
// import awais.instagrabber.models.FeedModel; |
|||
// import awais.instagrabber.models.enums.MediaItemType; |
|||
// import awais.instagrabber.utils.Utils; |
|||
// |
|||
// public final class FeedAdapter extends ListAdapter<FeedModel, FeedItemViewHolder> { |
|||
// private static final String TAG = "FeedAdapter"; |
|||
// private final View.OnClickListener clickListener; |
|||
// private final MentionClickListener mentionClickListener; |
|||
// private final View.OnLongClickListener longClickListener = v -> { |
|||
// final Object tag; |
|||
// if (v instanceof RamboTextView && (tag = v.getTag()) instanceof FeedModel) |
|||
// Utils.copyText(v.getContext(), ((FeedModel) tag).getPostCaption()); |
|||
// return true; |
|||
// }; |
|||
// |
|||
// private static final DiffUtil.ItemCallback<FeedModel> diffCallback = new DiffUtil.ItemCallback<FeedModel>() { |
|||
// @Override |
|||
// public boolean areItemsTheSame(@NonNull final FeedModel oldItem, @NonNull final FeedModel newItem) { |
|||
// return oldItem.getPostId().equals(newItem.getPostId()); |
|||
// } |
|||
// |
|||
// @Override |
|||
// public boolean areContentsTheSame(@NonNull final FeedModel oldItem, @NonNull final FeedModel newItem) { |
|||
// return oldItem.getPostId().equals(newItem.getPostId()); |
|||
// } |
|||
// }; |
|||
// |
|||
// public FeedAdapter(final View.OnClickListener clickListener, |
|||
// final MentionClickListener mentionClickListener) { |
|||
// super(diffCallback); |
|||
// // private final static String ellipsize = "… more"; |
|||
// this.clickListener = clickListener; |
|||
// this.mentionClickListener = mentionClickListener; |
|||
// } |
|||
// |
|||
// @NonNull |
|||
// @Override |
|||
// public FeedItemViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) { |
|||
// final Context context = parent.getContext(); |
|||
// final LayoutInflater layoutInflater = LayoutInflater.from(context); |
|||
// final MediaItemType type = MediaItemType.valueOf(viewType); |
|||
// switch (type) { |
|||
// case MEDIA_TYPE_VIDEO: { |
|||
// final ItemFeedVideoBinding binding = ItemFeedVideoBinding.inflate(layoutInflater, parent, false); |
|||
// return new FeedVideoViewHolder(binding, mentionClickListener, clickListener, longClickListener); |
|||
// } |
|||
// case MEDIA_TYPE_SLIDER: { |
|||
// final ItemFeedSliderBinding binding = ItemFeedSliderBinding.inflate(layoutInflater, parent, false); |
|||
// return new FeedSliderViewHolder(binding, mentionClickListener, clickListener, longClickListener); |
|||
// } |
|||
// case MEDIA_TYPE_IMAGE: |
|||
// default: { |
|||
// final ItemFeedPhotoBinding binding = ItemFeedPhotoBinding.inflate(layoutInflater, parent, false); |
|||
// return new FeedPhotoViewHolder(binding, mentionClickListener, clickListener, longClickListener); |
|||
// } |
|||
// } |
|||
// } |
|||
// |
|||
// @Override |
|||
// public void onBindViewHolder(@NonNull final FeedItemViewHolder viewHolder, final int position) { |
|||
// final FeedModel feedModel = getItem(position); |
|||
// if (feedModel == null) { |
|||
// return; |
|||
// } |
|||
// feedModel.setPosition(position); |
|||
// viewHolder.bind(feedModel, (feedModel1, view, postImage) -> {}); |
|||
// } |
|||
// |
|||
// @Override |
|||
// public int getItemViewType(final int position) { |
|||
// return getItem(position).getItemType().getId(); |
|||
// } |
|||
// |
|||
// @Override |
|||
// public void onViewAttachedToWindow(@NonNull final FeedItemViewHolder holder) { |
|||
// super.onViewAttachedToWindow(holder); |
|||
// // Log.d(TAG, "attached holder: " + holder); |
|||
// if (!(holder instanceof FeedSliderViewHolder)) return; |
|||
// final FeedSliderViewHolder feedSliderViewHolder = (FeedSliderViewHolder) holder; |
|||
// feedSliderViewHolder.startPlayingVideo(); |
|||
// } |
|||
// |
|||
// @Override |
|||
// public void onViewDetachedFromWindow(@NonNull final FeedItemViewHolder holder) { |
|||
// super.onViewDetachedFromWindow(holder); |
|||
// // Log.d(TAG, "detached holder: " + holder); |
|||
// if (!(holder instanceof FeedSliderViewHolder)) return; |
|||
// final FeedSliderViewHolder feedSliderViewHolder = (FeedSliderViewHolder) holder; |
|||
// feedSliderViewHolder.stopPlayingVideo(); |
|||
// } |
|||
// } |
@ -0,0 +1,40 @@ |
|||
package awais.instagrabber.adapters; |
|||
|
|||
import android.view.View; |
|||
|
|||
import awais.instagrabber.models.FeedModel; |
|||
|
|||
public class FeedItemCallbackAdapter implements FeedAdapterV2.FeedItemCallback { |
|||
@Override |
|||
public void onPostClick(final FeedModel feedModel, final View profilePicView, final View mainPostImage) {} |
|||
|
|||
@Override |
|||
public void onProfilePicClick(final FeedModel feedModel, final View profilePicView) {} |
|||
|
|||
@Override |
|||
public void onNameClick(final FeedModel feedModel, final View profilePicView) {} |
|||
|
|||
@Override |
|||
public void onLocationClick(final FeedModel feedModel) {} |
|||
|
|||
@Override |
|||
public void onMentionClick(final String mention) {} |
|||
|
|||
@Override |
|||
public void onHashtagClick(final String hashtag) {} |
|||
|
|||
@Override |
|||
public void onCommentsClick(final FeedModel feedModel) {} |
|||
|
|||
@Override |
|||
public void onDownloadClick(final FeedModel feedModel) {} |
|||
|
|||
@Override |
|||
public void onEmailClick(final String emailId) {} |
|||
|
|||
@Override |
|||
public void onURLClick(final String url) {} |
|||
|
|||
@Override |
|||
public void onSliderClick(final FeedModel feedModel, final int position) {} |
|||
} |
@ -1,95 +0,0 @@ |
|||
package awais.instagrabber.adapters.viewholder; |
|||
|
|||
import android.text.Spannable; |
|||
import android.view.View; |
|||
import android.widget.TextView; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
import androidx.recyclerview.widget.RecyclerView; |
|||
|
|||
import com.facebook.drawee.view.SimpleDraweeView; |
|||
|
|||
import awais.instagrabber.R; |
|||
import awais.instagrabber.adapters.CommentsAdapter; |
|||
import awais.instagrabber.customviews.RamboTextView; |
|||
import awais.instagrabber.interfaces.MentionClickListener; |
|||
import awais.instagrabber.models.CommentModel; |
|||
|
|||
public final class CommentViewHolder extends RecyclerView.ViewHolder { |
|||
private final MentionClickListener mentionClickListener; |
|||
private final RecyclerView rvChildComments; |
|||
private final SimpleDraweeView ivProfilePic; |
|||
private final TextView tvUsername; |
|||
private final TextView tvDate; |
|||
private final TextView tvComment; |
|||
private final TextView tvLikes; |
|||
private final View container; |
|||
|
|||
public CommentViewHolder(@NonNull final View itemView, |
|||
final View.OnClickListener onClickListener, |
|||
final MentionClickListener mentionClickListener) { |
|||
super(itemView); |
|||
|
|||
container = itemView.findViewById(R.id.container); |
|||
if (onClickListener != null) container.setOnClickListener(onClickListener); |
|||
|
|||
this.mentionClickListener = mentionClickListener; |
|||
|
|||
ivProfilePic = itemView.findViewById(R.id.ivProfilePic); |
|||
tvUsername = itemView.findViewById(R.id.tvUsername); |
|||
tvDate = itemView.findViewById(R.id.tvDate); |
|||
tvLikes = itemView.findViewById(R.id.tvLikes); |
|||
tvComment = itemView.findViewById(R.id.tvComment); |
|||
|
|||
tvUsername.setSelected(true); |
|||
tvDate.setSelected(true); |
|||
|
|||
rvChildComments = itemView.findViewById(R.id.rvChildComments); |
|||
} |
|||
|
|||
public final SimpleDraweeView getProfilePicView() { |
|||
return ivProfilePic; |
|||
} |
|||
|
|||
public final boolean isParent() { |
|||
return rvChildComments != null; |
|||
} |
|||
|
|||
public final void setCommentModel(final CommentModel commentModel) { |
|||
if (container != null) container.setTag(commentModel); |
|||
} |
|||
|
|||
public final void setUsername(final String username) { |
|||
if (tvUsername != null) tvUsername.setText(username); |
|||
} |
|||
|
|||
public final void setDate(final String date) { |
|||
if (tvDate != null) tvDate.setText(date); |
|||
} |
|||
|
|||
public final void setLikes(final String likes) { |
|||
if (tvLikes != null) tvLikes.setText(likes); |
|||
} |
|||
|
|||
public final void setLiked(final boolean liked) { |
|||
if (liked) container.setBackgroundColor(0x40FF69B4); |
|||
} |
|||
|
|||
public final void setComment(final CharSequence comment) { |
|||
if (tvComment != null) { |
|||
tvComment.setText(comment, comment instanceof Spannable ? TextView.BufferType.SPANNABLE : TextView.BufferType.NORMAL); |
|||
((RamboTextView) tvComment).setMentionClickListener(mentionClickListener); |
|||
} |
|||
} |
|||
|
|||
public final void setChildAdapter(final CommentsAdapter adapter) { |
|||
if (isParent()) { |
|||
rvChildComments.setAdapter(adapter); |
|||
rvChildComments.setVisibility(View.VISIBLE); |
|||
} |
|||
} |
|||
|
|||
public final void hideChildComments() { |
|||
if (isParent()) rvChildComments.setVisibility(View.GONE); |
|||
} |
|||
} |
@ -0,0 +1,93 @@ |
|||
package awais.instagrabber.adapters.viewholder.comments; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
import androidx.recyclerview.widget.RecyclerView; |
|||
|
|||
import awais.instagrabber.R; |
|||
import awais.instagrabber.adapters.CommentsAdapter.CommentCallback; |
|||
import awais.instagrabber.databinding.ItemCommentSmallBinding; |
|||
import awais.instagrabber.models.CommentModel; |
|||
import awais.instagrabber.models.ProfileModel; |
|||
import awais.instagrabber.utils.Utils; |
|||
|
|||
public final class ChildCommentViewHolder extends RecyclerView.ViewHolder { |
|||
|
|||
private final ItemCommentSmallBinding binding; |
|||
|
|||
public ChildCommentViewHolder(@NonNull final ItemCommentSmallBinding binding) { |
|||
super(binding.getRoot()); |
|||
this.binding = binding; |
|||
} |
|||
|
|||
public void bind(final CommentModel comment, |
|||
final boolean selected, |
|||
final CommentCallback commentCallback) { |
|||
if (comment == null) return; |
|||
if (commentCallback != null) { |
|||
itemView.setOnClickListener(v -> commentCallback.onClick(comment)); |
|||
} |
|||
if (selected) { |
|||
itemView.setBackgroundColor(itemView.getResources().getColor(R.color.comment_selected)); |
|||
} else { |
|||
itemView.setBackgroundColor(itemView.getResources().getColor(android.R.color.transparent)); |
|||
} |
|||
setupCommentText(comment, commentCallback); |
|||
binding.tvDate.setText(comment.getDateTime()); |
|||
setLiked(comment.getLiked()); |
|||
setLikes((int) comment.getLikes()); |
|||
setUser(comment); |
|||
} |
|||
|
|||
private void setupCommentText(final CommentModel comment, final CommentCallback commentCallback) { |
|||
binding.tvComment.clearOnURLClickListeners(); |
|||
binding.tvComment.clearOnHashtagClickListeners(); |
|||
binding.tvComment.clearOnMentionClickListeners(); |
|||
binding.tvComment.clearOnEmailClickListeners(); |
|||
binding.tvComment.setText(comment.getText()); |
|||
binding.tvComment.addOnHashtagListener(autoLinkItem -> { |
|||
final String originalText = autoLinkItem.getOriginalText(); |
|||
if (commentCallback == null) return; |
|||
commentCallback.onHashtagClick(originalText); |
|||
}); |
|||
binding.tvComment.addOnMentionClickListener(autoLinkItem -> { |
|||
final String originalText = autoLinkItem.getOriginalText(); |
|||
if (commentCallback == null) return; |
|||
commentCallback.onMentionClick(originalText); |
|||
|
|||
}); |
|||
binding.tvComment.addOnEmailClickListener(autoLinkItem -> { |
|||
final String originalText = autoLinkItem.getOriginalText(); |
|||
if (commentCallback == null) return; |
|||
commentCallback.onEmailClick(originalText); |
|||
}); |
|||
binding.tvComment.addOnURLClickListener(autoLinkItem -> { |
|||
final String originalText = autoLinkItem.getOriginalText(); |
|||
if (commentCallback == null) return; |
|||
commentCallback.onURLClick(originalText); |
|||
}); |
|||
binding.tvComment.setOnLongClickListener(v -> { |
|||
Utils.copyText(itemView.getContext(), comment.getText()); |
|||
return true; |
|||
}); |
|||
binding.tvComment.setOnClickListener(v -> commentCallback.onClick(comment)); |
|||
} |
|||
|
|||
private void setUser(final CommentModel comment) { |
|||
final ProfileModel profileModel = comment.getProfileModel(); |
|||
if (profileModel == null) return; |
|||
binding.tvUsername.setText(profileModel.getUsername()); |
|||
binding.ivProfilePic.setImageURI(profileModel.getSdProfilePic()); |
|||
} |
|||
|
|||
private void setLikes(final int likes) { |
|||
final String likesString = itemView.getResources().getQuantityString(R.plurals.likes_count, likes, likes); |
|||
binding.tvLikes.setText(likesString); |
|||
} |
|||
|
|||
public final void setLiked(final boolean liked) { |
|||
if (liked) { |
|||
// container.setBackgroundColor(0x40FF69B4); |
|||
return; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,93 @@ |
|||
package awais.instagrabber.adapters.viewholder.comments; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
import androidx.recyclerview.widget.RecyclerView; |
|||
|
|||
import awais.instagrabber.R; |
|||
import awais.instagrabber.adapters.CommentsAdapter.CommentCallback; |
|||
import awais.instagrabber.databinding.ItemCommentBinding; |
|||
import awais.instagrabber.models.CommentModel; |
|||
import awais.instagrabber.models.ProfileModel; |
|||
import awais.instagrabber.utils.Utils; |
|||
|
|||
public final class ParentCommentViewHolder extends RecyclerView.ViewHolder { |
|||
|
|||
private final ItemCommentBinding binding; |
|||
|
|||
public ParentCommentViewHolder(@NonNull final ItemCommentBinding binding) { |
|||
super(binding.getRoot()); |
|||
this.binding = binding; |
|||
} |
|||
|
|||
public void bind(final CommentModel comment, |
|||
final boolean selected, |
|||
final CommentCallback commentCallback) { |
|||
if (comment == null) return; |
|||
if (commentCallback != null) { |
|||
itemView.setOnClickListener(v -> commentCallback.onClick(comment)); |
|||
} |
|||
if (selected) { |
|||
itemView.setBackgroundColor(itemView.getResources().getColor(R.color.comment_selected)); |
|||
} else { |
|||
itemView.setBackgroundColor(itemView.getResources().getColor(android.R.color.transparent)); |
|||
} |
|||
setupCommentText(comment, commentCallback); |
|||
binding.tvDate.setText(comment.getDateTime()); |
|||
setLiked(comment.getLiked()); |
|||
setLikes((int) comment.getLikes()); |
|||
setUser(comment); |
|||
} |
|||
|
|||
private void setupCommentText(final CommentModel comment, final CommentCallback commentCallback) { |
|||
binding.tvComment.clearOnURLClickListeners(); |
|||
binding.tvComment.clearOnHashtagClickListeners(); |
|||
binding.tvComment.clearOnMentionClickListeners(); |
|||
binding.tvComment.clearOnEmailClickListeners(); |
|||
binding.tvComment.setText(comment.getText()); |
|||
binding.tvComment.addOnHashtagListener(autoLinkItem -> { |
|||
final String originalText = autoLinkItem.getOriginalText(); |
|||
if (commentCallback == null) return; |
|||
commentCallback.onHashtagClick(originalText); |
|||
}); |
|||
binding.tvComment.addOnMentionClickListener(autoLinkItem -> { |
|||
final String originalText = autoLinkItem.getOriginalText(); |
|||
if (commentCallback == null) return; |
|||
commentCallback.onMentionClick(originalText); |
|||
|
|||
}); |
|||
binding.tvComment.addOnEmailClickListener(autoLinkItem -> { |
|||
final String originalText = autoLinkItem.getOriginalText(); |
|||
if (commentCallback == null) return; |
|||
commentCallback.onEmailClick(originalText); |
|||
}); |
|||
binding.tvComment.addOnURLClickListener(autoLinkItem -> { |
|||
final String originalText = autoLinkItem.getOriginalText(); |
|||
if (commentCallback == null) return; |
|||
commentCallback.onURLClick(originalText); |
|||
}); |
|||
binding.tvComment.setOnLongClickListener(v -> { |
|||
Utils.copyText(itemView.getContext(), comment.getText()); |
|||
return true; |
|||
}); |
|||
binding.tvComment.setOnClickListener(v -> commentCallback.onClick(comment)); |
|||
} |
|||
|
|||
private void setUser(final CommentModel comment) { |
|||
final ProfileModel profileModel = comment.getProfileModel(); |
|||
if (profileModel == null) return; |
|||
binding.tvUsername.setText(profileModel.getUsername()); |
|||
binding.ivProfilePic.setImageURI(profileModel.getSdProfilePic()); |
|||
} |
|||
|
|||
private void setLikes(final int likes) { |
|||
final String likesString = itemView.getResources().getQuantityString(R.plurals.likes_count, likes, likes); |
|||
binding.tvLikes.setText(likesString); |
|||
} |
|||
|
|||
public final void setLiked(final boolean liked) { |
|||
if (liked) { |
|||
// container.setBackgroundColor(0x40FF69B4); |
|||
return; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,152 @@ |
|||
package awais.instagrabber.customviews; |
|||
|
|||
import android.content.Context; |
|||
import android.util.AttributeSet; |
|||
|
|||
import org.jetbrains.annotations.NotNull; |
|||
import org.jetbrains.annotations.Nullable; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
import io.github.armcha.autolink.AutoLinkItem; |
|||
import io.github.armcha.autolink.AutoLinkTextView; |
|||
import io.github.armcha.autolink.MODE_EMAIL; |
|||
import io.github.armcha.autolink.MODE_HASHTAG; |
|||
import io.github.armcha.autolink.MODE_MENTION; |
|||
import io.github.armcha.autolink.MODE_URL; |
|||
import io.github.armcha.autolink.Mode; |
|||
import kotlin.Unit; |
|||
|
|||
public class RamboTextViewV2 extends AutoLinkTextView { |
|||
private final List<OnMentionClickListener> onMentionClickListeners = new ArrayList<>(); |
|||
private final List<OnHashtagClickListener> onHashtagClickListeners = new ArrayList<>(); |
|||
private final List<OnURLClickListener> onURLClickListeners = new ArrayList<>(); |
|||
private final List<OnEmailClickListener> onEmailClickListeners = new ArrayList<>(); |
|||
|
|||
public RamboTextViewV2(@NotNull final Context context, |
|||
@Nullable final AttributeSet attrs) { |
|||
super(context, attrs); |
|||
init(); |
|||
} |
|||
|
|||
private void init() { |
|||
addAutoLinkMode(MODE_HASHTAG.INSTANCE, MODE_MENTION.INSTANCE, MODE_EMAIL.INSTANCE, MODE_URL.INSTANCE); |
|||
onAutoLinkClick(autoLinkItem -> { |
|||
final Mode mode = autoLinkItem.getMode(); |
|||
if (mode.equals(MODE_MENTION.INSTANCE)) { |
|||
for (final OnMentionClickListener onMentionClickListener : onMentionClickListeners) { |
|||
onMentionClickListener.onMentionClick(autoLinkItem); |
|||
} |
|||
return Unit.INSTANCE; |
|||
} |
|||
if (mode.equals(MODE_HASHTAG.INSTANCE)) { |
|||
for (final OnHashtagClickListener onHashtagClickListener : onHashtagClickListeners) { |
|||
onHashtagClickListener.onHashtagClick(autoLinkItem); |
|||
} |
|||
return Unit.INSTANCE; |
|||
} |
|||
if (mode.equals(MODE_URL.INSTANCE)) { |
|||
for (final OnURLClickListener onURLClickListener : onURLClickListeners) { |
|||
onURLClickListener.onURLClick(autoLinkItem); |
|||
} |
|||
return Unit.INSTANCE; |
|||
} |
|||
if (mode.equals(MODE_EMAIL.INSTANCE)) { |
|||
for (final OnEmailClickListener onEmailClickListener : onEmailClickListeners) { |
|||
onEmailClickListener.onEmailClick(autoLinkItem); |
|||
} |
|||
return Unit.INSTANCE; |
|||
} |
|||
return Unit.INSTANCE; |
|||
}); |
|||
} |
|||
|
|||
public void addOnMentionClickListener(final OnMentionClickListener onMentionClickListener) { |
|||
if (onMentionClickListener == null) { |
|||
return; |
|||
} |
|||
onMentionClickListeners.add(onMentionClickListener); |
|||
} |
|||
|
|||
public void removeOnMentionClickListener(final OnMentionClickListener onMentionClickListener) { |
|||
if (onMentionClickListener == null) { |
|||
return; |
|||
} |
|||
onMentionClickListeners.remove(onMentionClickListener); |
|||
} |
|||
|
|||
public void clearOnMentionClickListeners() { |
|||
onMentionClickListeners.clear(); |
|||
} |
|||
|
|||
public void addOnHashtagListener(final OnHashtagClickListener onHashtagClickListener) { |
|||
if (onHashtagClickListener == null) { |
|||
return; |
|||
} |
|||
onHashtagClickListeners.add(onHashtagClickListener); |
|||
} |
|||
|
|||
public void removeOnHashtagListener(final OnHashtagClickListener onHashtagClickListener) { |
|||
if (onHashtagClickListener == null) { |
|||
return; |
|||
} |
|||
onHashtagClickListeners.remove(onHashtagClickListener); |
|||
} |
|||
|
|||
public void clearOnHashtagClickListeners() { |
|||
onHashtagClickListeners.clear(); |
|||
} |
|||
|
|||
public void addOnURLClickListener(final OnURLClickListener onURLClickListener) { |
|||
if (onURLClickListener == null) { |
|||
return; |
|||
} |
|||
onURLClickListeners.add(onURLClickListener); |
|||
} |
|||
|
|||
public void removeOnURLClickListener(final OnURLClickListener onURLClickListener) { |
|||
if (onURLClickListener == null) { |
|||
return; |
|||
} |
|||
onURLClickListeners.remove(onURLClickListener); |
|||
} |
|||
|
|||
public void clearOnURLClickListeners() { |
|||
onURLClickListeners.clear(); |
|||
} |
|||
|
|||
public void addOnEmailClickListener(final OnEmailClickListener onEmailClickListener) { |
|||
if (onEmailClickListener == null) { |
|||
return; |
|||
} |
|||
onEmailClickListeners.add(onEmailClickListener); |
|||
} |
|||
|
|||
public void removeOnEmailClickListener(final OnEmailClickListener onEmailClickListener) { |
|||
if (onEmailClickListener == null) { |
|||
return; |
|||
} |
|||
onEmailClickListeners.remove(onEmailClickListener); |
|||
} |
|||
|
|||
public void clearOnEmailClickListeners() { |
|||
onEmailClickListeners.clear(); |
|||
} |
|||
|
|||
public interface OnMentionClickListener { |
|||
void onMentionClick(final AutoLinkItem autoLinkItem); |
|||
} |
|||
|
|||
public interface OnHashtagClickListener { |
|||
void onHashtagClick(final AutoLinkItem autoLinkItem); |
|||
} |
|||
|
|||
public interface OnURLClickListener { |
|||
void onURLClick(final AutoLinkItem autoLinkItem); |
|||
} |
|||
|
|||
public interface OnEmailClickListener { |
|||
void onEmailClick(final AutoLinkItem autoLinkItem); |
|||
} |
|||
} |
@ -0,0 +1,19 @@ |
|||
package awais.instagrabber.viewmodels; |
|||
|
|||
import androidx.lifecycle.MutableLiveData; |
|||
import androidx.lifecycle.ViewModel; |
|||
|
|||
import java.util.List; |
|||
|
|||
import awais.instagrabber.models.CommentModel; |
|||
|
|||
public class CommentsViewModel extends ViewModel { |
|||
private MutableLiveData<List<CommentModel>> list; |
|||
|
|||
public MutableLiveData<List<CommentModel>> getList() { |
|||
if (list == null) { |
|||
list = new MutableLiveData<>(); |
|||
} |
|||
return list; |
|||
} |
|||
} |
@ -1,118 +1,117 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|||
xmlns:app="http://schemas.android.com/apk/res-auto" |
|||
xmlns:tools="http://schemas.android.com/tools" |
|||
android:id="@+id/container" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="wrap_content" |
|||
android:orientation="vertical" |
|||
tools:viewBindingIgnore="true"> |
|||
android:background="?android:selectableItemBackground" |
|||
android:clickable="true" |
|||
android:focusable="true" |
|||
android:orientation="horizontal" |
|||
android:padding="8dp"> |
|||
|
|||
<androidx.constraintlayout.widget.ConstraintLayout |
|||
android:id="@+id/container" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="wrap_content" |
|||
android:background="?android:selectableItemBackground" |
|||
android:orientation="horizontal"> |
|||
|
|||
<com.facebook.drawee.view.SimpleDraweeView |
|||
android:id="@+id/ivProfilePic" |
|||
android:layout_width="@dimen/simple_item_picture_size" |
|||
android:layout_height="@dimen/simple_item_picture_size" |
|||
android:padding="4dp" |
|||
app:actualImageScaleType="centerCrop" |
|||
app:layout_constraintStart_toStartOf="parent" |
|||
app:layout_constraintTop_toTopOf="parent" |
|||
app:roundAsCircle="true" /> |
|||
<com.facebook.drawee.view.SimpleDraweeView |
|||
android:id="@+id/ivProfilePic" |
|||
android:layout_width="@dimen/simple_item_picture_size" |
|||
android:layout_height="@dimen/simple_item_picture_size" |
|||
android:padding="4dp" |
|||
app:actualImageScaleType="centerCrop" |
|||
app:layout_constraintStart_toStartOf="parent" |
|||
app:layout_constraintTop_toTopOf="parent" |
|||
app:roundAsCircle="true" |
|||
tools:background="@mipmap/ic_launcher" /> |
|||
|
|||
<androidx.appcompat.widget.AppCompatTextView |
|||
android:id="@+id/tvUsername" |
|||
android:layout_width="0dp" |
|||
android:layout_height="wrap_content" |
|||
android:ellipsize="marquee" |
|||
android:paddingStart="4dp" |
|||
android:paddingTop="2dp" |
|||
android:paddingEnd="4dp" |
|||
android:paddingBottom="2dp" |
|||
android:singleLine="true" |
|||
android:textAppearance="@style/TextAppearance.AppCompat.Medium" |
|||
android:textColor="?android:textColorPrimary" |
|||
android:textStyle="bold" |
|||
app:layout_constraintBottom_toTopOf="@id/tvComment" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintStart_toEndOf="@id/ivProfilePic" |
|||
app:layout_constraintTop_toTopOf="parent" |
|||
tools:text="username" /> |
|||
|
|||
<awais.instagrabber.customviews.RamboTextView |
|||
android:id="@+id/tvComment" |
|||
android:layout_width="0dp" |
|||
android:layout_height="wrap_content" |
|||
android:autoLink="web|email" |
|||
android:ellipsize="end" |
|||
android:linksClickable="true" |
|||
android:paddingStart="4dp" |
|||
android:paddingTop="2dp" |
|||
android:paddingEnd="4dp" |
|||
android:paddingBottom="2dp" |
|||
android:textAppearance="@style/TextAppearance.AppCompat" |
|||
app:layout_constraintBottom_toTopOf="@id/tvLikes" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintHorizontal_bias="0.0" |
|||
app:layout_constraintStart_toEndOf="@id/ivProfilePic" |
|||
app:layout_constraintTop_toBottomOf="@id/tvUsername" |
|||
tools:text="comment comment comment comment comment comment comment comment comment comment comment comment comment comment comment comment comment comment comment comment comment comment comment comment comment comment comment comment " /> |
|||
<androidx.appcompat.widget.AppCompatTextView |
|||
android:id="@+id/tvUsername" |
|||
android:layout_width="0dp" |
|||
android:layout_height="wrap_content" |
|||
android:ellipsize="marquee" |
|||
android:paddingStart="4dp" |
|||
android:paddingTop="2dp" |
|||
android:paddingEnd="4dp" |
|||
android:paddingBottom="2dp" |
|||
android:singleLine="true" |
|||
android:textAppearance="@style/TextAppearance.AppCompat.Medium" |
|||
android:textColor="?android:textColorPrimary" |
|||
android:textStyle="bold" |
|||
app:layout_constraintBottom_toTopOf="@id/tvComment" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintStart_toEndOf="@id/ivProfilePic" |
|||
app:layout_constraintTop_toTopOf="parent" |
|||
tools:text="username" /> |
|||
|
|||
<androidx.appcompat.widget.AppCompatTextView |
|||
android:id="@+id/tvLikes" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:layout_weight="1" |
|||
android:gravity="center_vertical" |
|||
android:paddingStart="4dp" |
|||
android:paddingTop="2dp" |
|||
android:paddingEnd="4dp" |
|||
android:paddingBottom="2dp" |
|||
android:singleLine="true" |
|||
android:textAppearance="@style/TextAppearance.AppCompat.Caption" |
|||
app:layout_constraintBottom_toBottomOf="parent" |
|||
app:layout_constraintEnd_toStartOf="@id/tvDate" |
|||
app:layout_constraintStart_toEndOf="@id/ivProfilePic" |
|||
app:layout_constraintTop_toBottomOf="@id/tvComment" |
|||
tools:text="likes" /> |
|||
<awais.instagrabber.customviews.RamboTextViewV2 |
|||
android:id="@+id/tvComment" |
|||
android:layout_width="0dp" |
|||
android:layout_height="wrap_content" |
|||
android:autoLink="web|email" |
|||
android:ellipsize="end" |
|||
android:linksClickable="true" |
|||
android:paddingStart="4dp" |
|||
android:paddingTop="2dp" |
|||
android:paddingEnd="4dp" |
|||
android:paddingBottom="2dp" |
|||
android:textAppearance="@style/TextAppearance.AppCompat" |
|||
app:layout_constraintBottom_toTopOf="@id/tvLikes" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintHorizontal_bias="0.0" |
|||
app:layout_constraintStart_toEndOf="@id/ivProfilePic" |
|||
app:layout_constraintTop_toBottomOf="@id/tvUsername" |
|||
tools:text="comment comment comment comment comment comment comment comment comment comment comment comment |
|||
comment comment comment comment comment comment comment comment comment comment comment comment comment comment comment comment" /> |
|||
|
|||
<androidx.appcompat.widget.AppCompatTextView |
|||
android:id="@+id/tvDate" |
|||
android:layout_width="0dp" |
|||
android:layout_height="wrap_content" |
|||
android:ellipsize="marquee" |
|||
android:gravity="end" |
|||
android:singleLine="true" |
|||
android:textAppearance="@style/TextAppearance.AppCompat.Caption" |
|||
android:textStyle="italic" |
|||
app:layout_constraintBaseline_toBaselineOf="@id/tvLikes" |
|||
app:layout_constraintBottom_toBottomOf="parent" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintStart_toEndOf="@id/tvLikes" |
|||
app:layout_constraintTop_toBottomOf="@id/tvComment" |
|||
tools:text="long date................................" /> |
|||
</androidx.constraintlayout.widget.ConstraintLayout> |
|||
<androidx.appcompat.widget.AppCompatTextView |
|||
android:id="@+id/tvLikes" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:layout_weight="1" |
|||
android:gravity="center_vertical" |
|||
android:paddingStart="4dp" |
|||
android:paddingTop="2dp" |
|||
android:paddingEnd="4dp" |
|||
android:paddingBottom="2dp" |
|||
android:scrollbars="none" |
|||
android:singleLine="true" |
|||
android:textAppearance="@style/TextAppearance.AppCompat.Caption" |
|||
app:layout_constraintBottom_toBottomOf="parent" |
|||
app:layout_constraintEnd_toStartOf="@id/tvDate" |
|||
app:layout_constraintStart_toEndOf="@id/ivProfilePic" |
|||
app:layout_constraintTop_toBottomOf="@id/tvComment" |
|||
tools:text="likes" /> |
|||
|
|||
<androidx.recyclerview.widget.RecyclerView |
|||
android:id="@+id/rvChildComments" |
|||
android:layout_width="match_parent" |
|||
<androidx.appcompat.widget.AppCompatTextView |
|||
android:id="@+id/tvDate" |
|||
android:layout_width="0dp" |
|||
android:layout_height="wrap_content" |
|||
android:layout_marginStart="40dp" |
|||
android:layout_marginLeft="40dp" |
|||
app:layoutManager="LinearLayoutManager" |
|||
tools:itemCount="5" |
|||
tools:listitem="@layout/item_comment_small" /> |
|||
android:ellipsize="marquee" |
|||
android:gravity="end" |
|||
android:singleLine="true" |
|||
android:textAppearance="@style/TextAppearance.AppCompat.Caption" |
|||
android:textStyle="italic" |
|||
app:layout_constraintBaseline_toBaselineOf="@id/tvLikes" |
|||
app:layout_constraintBottom_toBottomOf="parent" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintStart_toEndOf="@id/tvLikes" |
|||
app:layout_constraintTop_toBottomOf="@id/tvComment" |
|||
tools:text="long date................................" /> |
|||
</androidx.constraintlayout.widget.ConstraintLayout> |
|||
|
|||
<!--<androidx.recyclerview.widget.RecyclerView--> |
|||
<!-- android:id="@+id/rvChildComments"--> |
|||
<!-- android:layout_width="match_parent"--> |
|||
<!-- android:layout_height="wrap_content"--> |
|||
<!-- android:layout_marginStart="40dp"--> |
|||
<!-- android:layout_marginLeft="40dp"--> |
|||
<!-- app:layoutManager="LinearLayoutManager"--> |
|||
<!-- tools:itemCount="5"--> |
|||
<!-- tools:listitem="@layout/item_comment_small" />--> |
|||
|
|||
<View |
|||
android:layout_width="match_parent" |
|||
android:layout_height="1dp" |
|||
android:layout_gravity="bottom" |
|||
android:layout_marginStart="4dp" |
|||
android:layout_marginEnd="4dp" |
|||
android:layout_marginBottom="4dp" |
|||
android:background="#32888888" /> |
|||
</LinearLayout> |
|||
<!--<View--> |
|||
<!-- android:layout_width="match_parent"--> |
|||
<!-- android:layout_height="1dp"--> |
|||
<!-- android:layout_gravity="bottom"--> |
|||
<!-- android:layout_marginStart="4dp"--> |
|||
<!-- android:layout_marginEnd="4dp"--> |
|||
<!-- android:layout_marginBottom="4dp"--> |
|||
<!-- android:background="#32888888" />--> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue