Skip to content

Instantly share code, notes, and snippets.

@PollyGlot
Created January 3, 2020 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PollyGlot/e5f96880b225c7457fe825a73b263265 to your computer and use it in GitHub Desktop.
Save PollyGlot/e5f96880b225c7457fe825a73b263265 to your computer and use it in GitHub Desktop.
A method to navigate to comments fragment from different types of posts in the feed adapter
private fun navigateToCommentsFragment(holder: ViewHolder) {
val timeLineObject = timelineList[holder.adapterPosition]
holder.itemView.findNavController().navigate(R.id.action_home_dest_to_comments_fragment, Bundle().apply {
putInt(CommentsFragment.EXTRA_COMMENTS, timeLineObject.comments)
putInt(CommentsFragment.EXTRA_LIKES_COUNT, timeLineObject.likes)
putBoolean(CommentsFragment.EXTRA_LIKED, timeLineObject.hasLiked)
putInt(CommentsFragment.EXTRA_POSITION, holder.adapterPosition)
putString(CommentsFragment.EXTRA_PROFILE_IMAGE, timeLineObject.user.avatarUrl)
putString(CommentsFragment.EXTRA_PROFILE_NAME, timeLineObject.user.username)
when (holder.itemViewType) {
ACTIVITY_COMPLETED -> {
putString(CommentsFragment.EXTRA_TYPE, TimelineType.ACTIVITY_COMPLETED.postType)
putInt(CommentsFragment.EXTRA_ACTIVITY_ID, timeLineObject.activityCompleted.activityId)
putInt(CommentsFragment.EXTRA_SESSION_ID, timeLineObject.activityCompleted.id)
putString(CommentsFragment.EXTRA_ACTIVITY_MODE, timeLineObject.activityCompleted.mode)
putString(CommentsFragment.EXTRA_CONTENT_TITLE, timeLineObject.activityCompleted.name)
putLong(CommentsFragment.EXTRA_PUBLICATION_TIME, timeLineObject.createdAt)
}
VIDEO_ADDED -> {
putString(CommentsFragment.EXTRA_TYPE, TimelineType.VIDEO_ADDED.postType)
putInt(CommentsFragment.EXTRA_VIDEO_ID, timeLineObject.videoObject.id)
putString(CommentsFragment.EXTRA_VIDEO_TITLE, timeLineObject.videoObject.name)
putLong(CommentsFragment.EXTRA_PUBLICATION_TIME, timeLineObject.createdAt)
}
PLAYLIST_UNLOCKED -> {
putString(CommentsFragment.EXTRA_TYPE, TimelineType.PLAYLIST_UNLOCKED.postType)
putInt(CommentsFragment.EXTRA_PLAYLIST_ID, timeLineObject.playlistObject.id)
putString(CommentsFragment.EXTRA_PLAYLIST_TITLE, timeLineObject.playlistObject.name)
putLong(CommentsFragment.EXTRA_PUBLICATION_TIME, timeLineObject.createdAt)
}
VIDEO_COACHING_ADDED -> {
putString(CommentsFragment.EXTRA_TYPE, TimelineType.VIDEO_COACHING_ADDED.postType)
putInt(CommentsFragment.EXTRA_VIDEO_ID, timeLineObject.videoObject.id)
putString(CommentsFragment.EXTRA_VIDEO_TITLE, timeLineObject.videoObject.name)
putLong(CommentsFragment.EXTRA_PUBLICATION_TIME, timeLineObject.createdAt)
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment