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

Commit 8815c43

Browse files
committed
Adds Lesson screen.
Change-Id: I6bc62a8e0c797b4d6c610d8838b02b681310dbbe
1 parent 25f8ac4 commit 8815c43

File tree

17 files changed

+475
-44
lines changed

17 files changed

+475
-44
lines changed

app/src/main/java/com/materialstudies/owl/model/Lesson.kt

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import androidx.recyclerview.widget.DiffUtil
2020

2121
data class Lesson(
2222
val title: String,
23-
val formattedSteps: String,
23+
val formattedStepNumber: String,
2424
val length: String,
25-
val thumbUrl: String,
26-
val thumbContentDescription: String = ""
25+
val imageUrl: String,
26+
val imageContentDescription: String = ""
2727
)
2828

2929
object LessonDiff : DiffUtil.ItemCallback<Lesson>() {
@@ -34,56 +34,56 @@ object LessonDiff : DiffUtil.ItemCallback<Lesson>() {
3434
val lessons = listOf(
3535
Lesson(
3636
title = "An introduction to the Landscape",
37-
formattedSteps = "01",
37+
formattedStepNumber = "01",
3838
length = "4:14",
39-
thumbUrl = "https://source.unsplash.com/NRQV-hBF10M"
39+
imageUrl = "https://source.unsplash.com/NRQV-hBF10M"
4040
),
4141
Lesson(
4242
title = "Movement and Expression",
43-
formattedSteps = "02",
43+
formattedStepNumber = "02",
4444
length = "7:28",
45-
thumbUrl = "https://source.unsplash.com/JhqhGfX_Wd8"
45+
imageUrl = "https://source.unsplash.com/JhqhGfX_Wd8"
4646
),
4747
Lesson(
4848
title = "Composition and the Urban Canvas",
49-
formattedSteps = "03",
49+
formattedStepNumber = "03",
5050
length = "3:43",
51-
thumbUrl = "https://source.unsplash.com/0OjzOqlJyoU"
51+
imageUrl = "https://source.unsplash.com/0OjzOqlJyoU"
5252
),
5353
Lesson(
5454
title = "Lighting Techniques and Aesthetics",
55-
formattedSteps = "04",
55+
formattedStepNumber = "04",
5656
length = "4:45",
57-
thumbUrl = "https://source.unsplash.com/J5-Kqu_fxyo"
57+
imageUrl = "https://source.unsplash.com/J5-Kqu_fxyo"
5858
),
5959
Lesson(
6060
title = "Special Effects",
61-
formattedSteps = "05",
61+
formattedStepNumber = "05",
6262
length = "6:19",
63-
thumbUrl = "https://source.unsplash.com/9ZCZoH69dZQ"
63+
imageUrl = "https://source.unsplash.com/9ZCZoH69dZQ"
6464
),
6565
Lesson(
6666
title = "Techniques with Structures",
67-
formattedSteps = "06",
67+
formattedStepNumber = "06",
6868
length = "9:41",
69-
thumbUrl = "https://source.unsplash.com/RFDP7_80v5A"
69+
imageUrl = "https://source.unsplash.com/RFDP7_80v5A"
7070
),
7171
Lesson(
7272
title = "Deep Focus Using a Camera Dolly",
73-
formattedSteps = "07",
73+
formattedStepNumber = "07",
7474
length = "4:43",
75-
thumbUrl = "https://source.unsplash.com/0rZ2-QWtkwY"
75+
imageUrl = "https://source.unsplash.com/0rZ2-QWtkwY"
7676
),
7777
Lesson(
7878
title = "Point of View Shots with Structures",
79-
formattedSteps = "08",
79+
formattedStepNumber = "08",
8080
length = "9:41",
81-
thumbUrl = "https://source.unsplash.com/iQnR_xEsBj0"
81+
imageUrl = "https://source.unsplash.com/iQnR_xEsBj0"
8282
),
8383
Lesson(
8484
title = "Photojournalism: Street Art",
85-
formattedSteps = "09",
85+
formattedStepNumber = "09",
8686
length = "9:41",
87-
thumbUrl = "https://source.unsplash.com/qX9Ie7ieb1E"
87+
imageUrl = "https://source.unsplash.com/qX9Ie7ieb1E"
8888
)
8989
)

app/src/main/java/com/materialstudies/owl/ui/learn/LessonAdapter.kt renamed to app/src/main/java/com/materialstudies/owl/ui/lessons/LessonAdapter.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,31 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.materialstudies.owl.ui.learn
17+
package com.materialstudies.owl.ui.lessons
1818

1919
import android.view.LayoutInflater
20+
import android.view.View
2021
import android.view.ViewGroup
22+
import androidx.navigation.Navigation
23+
import androidx.navigation.findNavController
2124
import androidx.recyclerview.widget.ListAdapter
2225
import androidx.recyclerview.widget.RecyclerView
26+
import com.materialstudies.owl.R
2327
import com.materialstudies.owl.databinding.LessonItemBinding
2428
import com.materialstudies.owl.model.Lesson
2529
import com.materialstudies.owl.model.LessonDiff
2630

2731
class LessonAdapter : ListAdapter<Lesson, LessonViewHolder>(LessonDiff) {
2832

2933
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LessonViewHolder {
30-
val binding = LessonItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
34+
val binding = LessonItemBinding.inflate(
35+
LayoutInflater.from(parent.context), parent,
36+
false
37+
).apply {
38+
root.setOnClickListener {
39+
it.findNavController().navigate(R.id.lesson)
40+
}
41+
}
3142
return LessonViewHolder(binding)
3243
}
3344

@@ -47,5 +58,4 @@ class LessonViewHolder(
4758
executePendingBindings()
4859
}
4960
}
50-
51-
}
61+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.lessons
18+
19+
import android.os.Bundle
20+
import androidx.fragment.app.Fragment
21+
import android.view.LayoutInflater
22+
import android.view.View
23+
import android.view.ViewGroup
24+
import androidx.navigation.findNavController
25+
26+
import com.materialstudies.owl.R
27+
import com.materialstudies.owl.databinding.FragmentLessonBinding
28+
import com.materialstudies.owl.model.lessons
29+
30+
/**
31+
* A [Fragment] displaying a lesson.
32+
*/
33+
class LessonFragment : Fragment() {
34+
35+
override fun onCreateView(
36+
inflater: LayoutInflater,
37+
container: ViewGroup?,
38+
savedInstanceState: Bundle?
39+
): View? {
40+
val binding = FragmentLessonBinding.inflate(inflater, container, false).apply {
41+
lesson = lessons.first()
42+
steps.apply {
43+
adapter = StepsAdapter(lessons, context)
44+
}
45+
collapse.setOnClickListener {
46+
it.findNavController().popBackStack()
47+
}
48+
}
49+
return binding.root
50+
}
51+
}

app/src/main/java/com/materialstudies/owl/ui/lessons/LessonsSheetFragment.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,16 @@ import androidx.annotation.Px
3030
import androidx.core.view.doOnLayout
3131
import androidx.core.view.forEach
3232
import androidx.fragment.app.Fragment
33-
import androidx.navigation.fragment.findNavController
3433
import androidx.recyclerview.widget.RecyclerView
3534
import com.google.android.material.bottomsheet.BottomSheetBehavior
35+
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_COLLAPSED
3636
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED
3737
import com.google.android.material.shape.MaterialShapeDrawable
3838
import com.google.android.material.shape.ShapeAppearanceModel
3939
import com.materialstudies.owl.R
4040
import com.materialstudies.owl.databinding.FragmentLessonsSheetBinding
4141
import com.materialstudies.owl.model.courses
4242
import com.materialstudies.owl.model.lessons
43-
import com.materialstudies.owl.ui.learn.LessonAdapter
4443
import com.materialstudies.owl.util.doOnApplyWindowInsets
4544
import com.materialstudies.owl.util.lerp
4645
import com.materialstudies.owl.util.lerpArgb
@@ -59,8 +58,8 @@ class LessonsSheetFragment : Fragment() {
5958
course = courses.last()
6059
val behavior = BottomSheetBehavior.from(lessonsSheet)
6160
val backCallback =
62-
requireActivity().onBackPressedDispatcher.addCallback(lifecycleOwner, false) {
63-
behavior.state = BottomSheetBehavior.STATE_COLLAPSED
61+
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, false) {
62+
behavior.state = STATE_COLLAPSED
6463
}
6564
val sheetStartColor = lessonsSheet.context.getColor(R.color.owl_pink_500)
6665
val sheetEndColor =
@@ -112,10 +111,10 @@ class LessonsSheetFragment : Fragment() {
112111
}
113112
}
114113
collapsePlaylist.setOnClickListener {
115-
behavior.state = BottomSheetBehavior.STATE_COLLAPSED
114+
behavior.state = STATE_COLLAPSED
116115
}
117116
sheetExpand.setOnClickListener {
118-
behavior.state = BottomSheetBehavior.STATE_EXPANDED
117+
behavior.state = STATE_EXPANDED
119118
}
120119
playlist.adapter = LessonAdapter().apply {
121120
submitList(lessons)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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.lessons
18+
19+
import android.content.Context
20+
import android.view.LayoutInflater
21+
import android.view.ViewGroup
22+
import androidx.recyclerview.widget.DiffUtil
23+
import androidx.recyclerview.widget.ListAdapter
24+
import androidx.recyclerview.widget.RecyclerView
25+
import com.materialstudies.owl.R
26+
import com.materialstudies.owl.databinding.StepItemBinding
27+
import com.materialstudies.owl.model.Lesson
28+
29+
class StepsAdapter(
30+
lessons: List<Lesson>,
31+
context: Context
32+
) : ListAdapter<Step, StepViewHolder>(StepDiff) {
33+
34+
init {
35+
val steps = lessons.mapIndexed { step, _ ->
36+
Step(
37+
context.getString(R.string.step_num, step + 1),
38+
when (step % 3) {
39+
0 -> context.getString(R.string.step_0)
40+
1 -> context.getString(R.string.step_1)
41+
else -> context.getString(R.string.step_2)
42+
}
43+
)
44+
}
45+
submitList(steps)
46+
}
47+
48+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): StepViewHolder {
49+
val binding = StepItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
50+
return StepViewHolder(binding)
51+
}
52+
53+
override fun onBindViewHolder(holder: StepViewHolder, position: Int) {
54+
holder.bind(getItem(position))
55+
}
56+
}
57+
58+
class StepViewHolder(private val binding: StepItemBinding) : RecyclerView.ViewHolder(binding.root) {
59+
60+
fun bind(step: Step) {
61+
binding.run {
62+
this.step = step
63+
executePendingBindings()
64+
}
65+
}
66+
}
67+
68+
data class Step(
69+
val title: String,
70+
val body: String
71+
)
72+
73+
object StepDiff : DiffUtil.ItemCallback<Step>() {
74+
override fun areItemsTheSame(oldItem: Step, newItem: Step) = oldItem.title == newItem.title
75+
override fun areContentsTheSame(oldItem: Step, newItem: Step) = oldItem == newItem
76+
}

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

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

1717
import android.view.LayoutInflater
1818
import android.view.ViewGroup
19-
import androidx.navigation.Navigation
19+
import androidx.navigation.findNavController
2020
import androidx.recyclerview.widget.ListAdapter
2121
import androidx.recyclerview.widget.RecyclerView
2222
import com.bumptech.glide.Glide
@@ -38,7 +38,7 @@ class MyCoursesAdapter : ListAdapter<Course, MyCourseViewHolder>(CourseDiff) {
3838
false
3939
).apply {
4040
click.setOnClickListener {
41-
Navigation.findNavController(it).navigate(R.id.learn)
41+
it.findNavController().navigate(R.id.learn)
4242
}
4343
}
4444
return MyCourseViewHolder(binding)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
<vector
16+
xmlns:android="http://schemas.android.com/apk/res/android"
17+
android:width="24dp"
18+
android:height="24dp"
19+
android:viewportWidth="24"
20+
android:viewportHeight="24">
21+
<path
22+
android:fillColor="#fff"
23+
android:pathData="M14.5,5h3c0.3,0 0.5,0.2 0.5,0.5v13c0,0.3 -0.2,0.5 -0.5,0.5h-3c-0.3,0 -0.5,-0.2 -0.5,-0.5v-13c0,-0.3 0.2,-0.5 0.5,-0.5zM6,18.5v-13c0,-0.3 0.2,-0.5 0.5,-0.5h3c0.3,0 0.5,0.2 0.5,0.5v13c0,0.3 -0.2,0.5 -0.5,0.5h-3c-0.3,0 -0.5,-0.2 -0.5,-0.5z"/>
24+
</vector>
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="rectangle">
18+
<gradient
19+
android:type="linear"
20+
android:angle="270"
21+
android:startColor="#00000000"
22+
android:endColor="#b3000000"/>
23+
</shape>

0 commit comments

Comments
 (0)