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

Commit c8ab6ec

Browse files
nickbutcherGerrit Code Review
authored andcommitted
Merge "Implement Featured screen."
2 parents 49410c7 + c6bc834 commit c8ab6ec

25 files changed

+577
-92
lines changed
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/*
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.materialstudies.owl.model
18+
19+
import androidx.recyclerview.widget.DiffUtil
20+
21+
data class Course(
22+
val id: Long,
23+
val name: String,
24+
val subject: String,
25+
val thumb: String,
26+
val thumbContentDesc: String,
27+
val steps: Int,
28+
val step: Int,
29+
val instructor: String
30+
)
31+
32+
object CourseDiff : DiffUtil.ItemCallback<Course>() {
33+
override fun areItemsTheSame(oldItem: Course, newItem: Course) = oldItem.id == newItem.id
34+
override fun areContentsTheSame(oldItem: Course, newItem: Course) = oldItem == newItem
35+
}
36+
37+
val courses = listOf(
38+
Course(
39+
id = 0,
40+
name = "Basic Blocks and Woodturning",
41+
subject = "Arts & Crafts",
42+
thumb = "",
43+
thumbContentDesc = "",
44+
steps = 7,
45+
step = 1,
46+
instructor = ""
47+
),
48+
Course(
49+
id = 1,
50+
name = "An Introduction To Oil Painting On Canvas",
51+
subject = "Painting",
52+
thumb = "",
53+
thumbContentDesc = "",
54+
steps = 12,
55+
step = 1,
56+
instructor = ""
57+
),
58+
Course(
59+
id = 2,
60+
name = "Understanding the Composition of Modern Cities",
61+
subject = "Architecture",
62+
thumb = "",
63+
thumbContentDesc = "",
64+
steps = 18,
65+
step = 1,
66+
instructor = ""
67+
),
68+
Course(
69+
id = 2,
70+
name = "Learning The Basics of Brand Identity",
71+
subject = "Design",
72+
thumb = "",
73+
thumbContentDesc = "",
74+
steps = 22,
75+
step = 1,
76+
instructor = ""
77+
),
78+
Course(
79+
id = 2,
80+
name = "Wooden Materials and Sculpting Machinery",
81+
subject = "Arts & Crafts",
82+
thumb = "",
83+
thumbContentDesc = "",
84+
steps = 19,
85+
step = 1,
86+
instructor = ""
87+
),
88+
Course(
89+
id = 2,
90+
name = "Advanced Potter's Wheel",
91+
subject = "Arts & Crafts",
92+
thumb = "",
93+
thumbContentDesc = "",
94+
steps = 14,
95+
step = 1,
96+
instructor = ""
97+
),
98+
Course(
99+
id = 2,
100+
name = "Advanced Abstract Shapes & 3D",
101+
subject = "Arts & Crafts",
102+
thumb = "",
103+
thumbContentDesc = "",
104+
steps = 17,
105+
step = 1,
106+
instructor = ""
107+
),
108+
Course(
109+
id = 2,
110+
name = "Beginning Portraiture",
111+
subject = "Photography",
112+
thumb = "",
113+
thumbContentDesc = "",
114+
steps = 22,
115+
step = 1,
116+
instructor = ""
117+
),
118+
Course(
119+
id = 2,
120+
name = "Intermediate Knife Skills",
121+
subject = "Culinary",
122+
thumb = "",
123+
thumbContentDesc = "",
124+
steps = 14,
125+
step = 1,
126+
instructor = ""
127+
),
128+
Course(
129+
id = 2,
130+
name = "Pattern Making for Begginers",
131+
subject = "Fashion",
132+
thumb = "",
133+
thumbContentDesc = "",
134+
steps = 7,
135+
step = 1,
136+
instructor = ""
137+
),
138+
Course(
139+
id = 2,
140+
name = "Location Lighting for Beginners",
141+
subject = "Photography",
142+
thumb = "",
143+
thumbContentDesc = "",
144+
steps = 6,
145+
step = 1,
146+
instructor = ""
147+
),
148+
Course(
149+
id = 2,
150+
name = "Cinematography & Lighting",
151+
subject = "Film",
152+
thumb = "",
153+
thumbContentDesc = "",
154+
steps = 4,
155+
step = 1,
156+
instructor = ""
157+
)
158+
)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.materialstudies.owl.ui.featured
18+
19+
import android.view.LayoutInflater
20+
import android.view.ViewGroup
21+
import androidx.recyclerview.widget.ListAdapter
22+
import androidx.recyclerview.widget.RecyclerView
23+
import com.bumptech.glide.Glide
24+
import com.materialstudies.owl.R
25+
import com.materialstudies.owl.databinding.FeaturedItemBinding
26+
import com.materialstudies.owl.model.Course
27+
import com.materialstudies.owl.model.CourseDiff
28+
29+
class FeaturedAdapter : ListAdapter<Course, FeaturedViewHolder>(CourseDiff) {
30+
31+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FeaturedViewHolder {
32+
val binding = FeaturedItemBinding.inflate(
33+
LayoutInflater.from(parent.context),
34+
parent,
35+
false
36+
)
37+
return FeaturedViewHolder(binding)
38+
}
39+
40+
override fun onBindViewHolder(holder: FeaturedViewHolder, position: Int) {
41+
holder.bind(getItem(position), position)
42+
}
43+
44+
}
45+
46+
class FeaturedViewHolder(
47+
private val binding: FeaturedItemBinding
48+
) : RecyclerView.ViewHolder(binding.root) {
49+
50+
fun bind(course: Course, position: Int) {
51+
binding.run {
52+
this.course = course
53+
Glide.with(courseImage)
54+
.load("https://source.unsplash.com/collection/369966/?$position")
55+
.placeholder(R.drawable.course_image_placeholder)
56+
.into(courseImage)
57+
Glide.with(courseInstructor)
58+
.load("https://i.pravatar.cc/56?$position")
59+
.circleCrop()
60+
.into(courseInstructor)
61+
executePendingBindings()
62+
}
63+
}
64+
65+
}

app/src/main/java/com/materialstudies/owl/ui/featured/FeaturedFragment.kt

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,46 @@
1616

1717
package com.materialstudies.owl.ui.featured
1818

19+
import android.graphics.Rect
1920
import android.os.Bundle
2021
import android.view.LayoutInflater
2122
import android.view.View
2223
import android.view.ViewGroup
24+
import androidx.annotation.Px
2325
import androidx.fragment.app.Fragment
26+
import androidx.recyclerview.widget.RecyclerView
2427
import com.materialstudies.owl.R
28+
import com.materialstudies.owl.databinding.FragmentFeaturedBinding
29+
import com.materialstudies.owl.model.courses
2530

2631
class FeaturedFragment : Fragment() {
27-
override fun onCreate(savedInstanceState: Bundle?) {
28-
super.onCreate(savedInstanceState)
29-
}
3032

3133
override fun onCreateView(
3234
inflater: LayoutInflater,
3335
container: ViewGroup?,
3436
savedInstanceState: Bundle?
3537
): View? {
36-
// Inflate the layout for this fragment
37-
return inflater.inflate(R.layout.fragment_featured, container, false)
38+
val binding = FragmentFeaturedBinding.inflate(inflater, container, false).apply {
39+
featuredGrid.apply {
40+
adapter = FeaturedAdapter().apply {
41+
submitList(courses)
42+
}
43+
addItemDecoration(
44+
OffsetDecoration(resources.getDimensionPixelSize(R.dimen.grid_0_5))
45+
)
46+
}
47+
}
48+
return binding.root
49+
}
50+
}
51+
52+
class OffsetDecoration(@Px private val offset: Int) : RecyclerView.ItemDecoration() {
53+
override fun getItemOffsets(
54+
outRect: Rect,
55+
view: View,
56+
parent: RecyclerView,
57+
state: RecyclerView.State
58+
) {
59+
outRect.set(offset, offset, offset, offset)
3860
}
3961
}

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

Lines changed: 0 additions & 51 deletions
This file was deleted.

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ package com.materialstudies.owl.ui.mycourses
1717
import android.view.LayoutInflater
1818
import android.view.ViewGroup
1919
import androidx.lifecycle.LifecycleOwner
20-
import androidx.recyclerview.widget.DiffUtil
2120
import androidx.recyclerview.widget.ListAdapter
2221
import androidx.recyclerview.widget.RecyclerView
2322
import com.bumptech.glide.Glide
2423
import com.materialstudies.owl.R
2524
import com.materialstudies.owl.databinding.CourseItemBinding
25+
import com.materialstudies.owl.model.Course
26+
import com.materialstudies.owl.model.CourseDiff
2627
import com.materialstudies.owl.util.ShapeAppearanceTransformation
2728

2829
class MyCourseViewHolder(
@@ -61,8 +62,4 @@ class MyCoursesAdapter(private val lifecycle: LifecycleOwner) :
6162
holder.bind(getItem(position), shapeTransform)
6263
}
6364

64-
object CourseDiff : DiffUtil.ItemCallback<Course>() {
65-
override fun areItemsTheSame(oldItem: Course, newItem: Course) = oldItem.id == newItem.id
66-
override fun areContentsTheSame(oldItem: Course, newItem: Course) = oldItem == newItem
67-
}
6865
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import android.view.View
1919
import android.view.ViewGroup
2020
import androidx.fragment.app.Fragment
2121
import com.materialstudies.owl.databinding.FragmentMyCoursesBinding
22+
import com.materialstudies.owl.model.courses
2223

2324
class MyCoursesFragment : Fragment() {
2425

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright (c) 2019 Google Inc.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6+
in compliance with the License. You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software distributed under the License
11+
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12+
or implied. See the License for the specific language governing permissions and limitations under
13+
the License.
14+
-->
15+
<shape
16+
xmlns:android="http://schemas.android.com/apk/res/android"
17+
android:shape="oval">
18+
19+
<stroke
20+
android:color="?attr/colorSurface"
21+
android:width="3dp"/>
22+
23+
</shape>

app/src/main/res/drawable/course_image_placeholder.xml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
xmlns:android="http://schemas.android.com/apk/res/android"
1717
android:shape="rectangle">
1818

19-
<corners android:topLeftRadius="28dp"/>
20-
<stroke
21-
android:color="#66ffffff"
22-
android:width="1dp"/>
19+
<solid android:color="#e9e9e9"/>
20+
<size android:height="120dp"/>
2321

24-
</shape>
22+
</shape>

0 commit comments

Comments
 (0)