Created
May 24, 2020 13:53
-
-
Save tobioyelekan/d4ae79eb72669f3cd157c43cb05feb54 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CourseAdapter(private val viewModel: CourseViewModel) : | |
ListAdapter<Course, ViewHolder>(CourseDiffCallback()) { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | |
val inflater = LayoutInflater.from(parent.context) | |
return ViewHolder(inflater.inflate(R.layout.course_item, parent, false)) | |
} | |
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | |
holder.bind(viewModel, getItem(position)) | |
} | |
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | |
fun bind(viewModel: CourseViewModel, course: Course) { | |
with(itemView) { | |
courseTitle.text = course.courseTitle | |
courseThumbnail.loadImage(course.thumbnail) | |
modules.text = GeneralUtil.getNumber(course.numberOfModules, "Module") | |
courseLessons.text = GeneralUtil.getNumber(course.numberOfLessons, "Lesson") | |
startCourse.setOnClickListener { | |
viewModel.openCourseModule( | |
course.id, | |
course.courseTitle, | |
course.numberOfLessons | |
) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment