Skip to content
This repository was archived by the owner on Nov 21, 2024. It is now read-only.

Commit d45df87

Browse files
committed
Design tweaks to My Courses and made implementation consistent with Featured.
Change-Id: I1979b726c6a4614437ad4dd9c6a0a75afebc8f69
1 parent 9f7fee8 commit d45df87

File tree

5 files changed

+33
-39
lines changed

5 files changed

+33
-39
lines changed

app/src/main/java/com/materialstudies/owl/ui/mycourses/MyCoursesAdapter.kt

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package com.materialstudies.owl.ui.mycourses
1616

1717
import android.view.LayoutInflater
1818
import android.view.ViewGroup
19-
import androidx.lifecycle.LifecycleOwner
2019
import androidx.recyclerview.widget.ListAdapter
2120
import androidx.recyclerview.widget.RecyclerView
2221
import com.bumptech.glide.Glide
@@ -26,40 +25,38 @@ import com.materialstudies.owl.model.Course
2625
import com.materialstudies.owl.model.CourseDiff
2726
import com.materialstudies.owl.util.ShapeAppearanceTransformation
2827

29-
class MyCourseViewHolder(
30-
private val binding: CourseItemBinding
31-
) : RecyclerView.ViewHolder(binding.root) {
32-
33-
fun bind(course: Course, imageTransform: ShapeAppearanceTransformation) {
34-
binding.course = course
35-
Glide.with(binding.courseImage)
36-
.load("https://source.unsplash.com/random/200x200")
37-
.transform(imageTransform)
38-
.into(binding.courseImage)
39-
Glide.with(binding.courseInstructor)
40-
.load("https://i.pravatar.cc/56")
41-
.circleCrop()
42-
.into(binding.courseInstructor)
43-
binding.executePendingBindings()
44-
}
45-
}
46-
47-
class MyCoursesAdapter(private val lifecycle: LifecycleOwner) :
48-
ListAdapter<Course, MyCourseViewHolder>(CourseDiff) {
28+
class MyCoursesAdapter : ListAdapter<Course, MyCourseViewHolder>(CourseDiff) {
4929

5030
private val shapeTransform =
5131
ShapeAppearanceTransformation(R.style.ShapeAppearance_Owl_SmallComponent)
5232

5333
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyCourseViewHolder {
54-
val binding =
55-
CourseItemBinding.inflate(LayoutInflater.from(parent.context), parent, false).apply {
56-
lifecycleOwner = lifecycle
57-
}
34+
val binding = CourseItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
5835
return MyCourseViewHolder(binding)
5936
}
6037

6138
override fun onBindViewHolder(holder: MyCourseViewHolder, position: Int) {
62-
holder.bind(getItem(position), shapeTransform)
39+
holder.bind(getItem(position), position, shapeTransform)
6340
}
6441

6542
}
43+
44+
class MyCourseViewHolder(
45+
private val binding: CourseItemBinding
46+
) : RecyclerView.ViewHolder(binding.root) {
47+
48+
fun bind(course: Course, position: Int, imageTransform: ShapeAppearanceTransformation) {
49+
binding.run {
50+
this.course = course
51+
Glide.with(courseImage)
52+
.load("https://source.unsplash.com/collection/369966/?$position")
53+
.transform(imageTransform)
54+
.into(courseImage)
55+
Glide.with(courseInstructor)
56+
.load("https://i.pravatar.cc/56?$position")
57+
.circleCrop()
58+
.into(courseInstructor)
59+
executePendingBindings()
60+
}
61+
}
62+
}

app/src/main/java/com/materialstudies/owl/ui/mycourses/MyCoursesFragment.kt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,15 @@ import com.materialstudies.owl.model.courses
2323

2424
class MyCoursesFragment : Fragment() {
2525

26-
private val adapter = MyCoursesAdapter(this)
27-
28-
override fun onCreate(savedInstanceState: Bundle?) {
29-
super.onCreate(savedInstanceState)
30-
adapter.submitList(courses)
31-
}
32-
3326
override fun onCreateView(
3427
inflater: LayoutInflater,
3528
container: ViewGroup?,
3629
savedInstanceState: Bundle?
3730
): View {
3831
val binding = FragmentMyCoursesBinding.inflate(inflater, container, false).apply {
39-
list.adapter = adapter
32+
list.adapter = MyCoursesAdapter().apply {
33+
submitList(courses)
34+
}
4035
}
4136
return binding.root
4237
}

app/src/main/res/layout/course_item.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
android:paddingTop="@dimen/grid_2"
7373
android:text="@{course.name}"
7474
android:textColor="?attr/colorOnSurface"
75-
android:textAppearance="?attr/textAppearanceBody1"/>
75+
android:textAppearance="?attr/textAppearanceSubtitle1"
76+
app:lineHeight="22sp"/>
7677

7778
<ImageView
7879
android:id="@+id/course_icon"
@@ -96,7 +97,7 @@
9697
app:layout_constraintBottom_toBottomOf="parent"
9798
android:paddingStart="@dimen/grid_1"
9899
android:paddingVertical="@dimen/grid_2"
99-
android:textColor="?attr/colorOnSurface"
100+
android:textColor="?attr/colorPrimary"
100101
android:textAppearance="?attr/textAppearanceCaption"
101102
android:text="@{@string/course_steps(course.step, course.steps)}"/>
102103

app/src/main/res/layout/fragment_featured.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
<com.google.android.material.appbar.AppBarLayout
3030
android:layout_width="match_parent"
3131
android:layout_height="wrap_content"
32-
app:elevation="0dp"
33-
>
32+
app:liftOnScroll="true"
33+
app:liftOnScrollTargetViewId="@id/featured_grid">
3434

3535
<androidx.appcompat.widget.Toolbar
3636
android:layout_width="match_parent"

app/src/main/res/layout/fragment_my_courses.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
<com.google.android.material.appbar.AppBarLayout
2828
android:layout_width="match_parent"
2929
android:layout_height="wrap_content"
30-
app:elevation="0dp">
30+
app:liftOnScroll="true"
31+
app:liftOnScrollTargetViewId="@id/list">
3132

3233
<androidx.appcompat.widget.Toolbar
3334
android:layout_width="match_parent"

0 commit comments

Comments
 (0)