Skip to content

Commit 11a8357

Browse files
author
Dicky Herlambang
committed
Treewide: Apply dicoding advice on submission 1
* DetailShowActivity.kt - Re-order "companion object" code position below other code (as kotlin class layout suggestion) - Use "apply" for binding to avoid re-write binding every want to connect some textview or etc - Use constant value for genre and include into companion object * MovieEntity.kt & All Entity - Use val instead of var when variable aren't supposed to change in other time * MovieFragment.kt & TvShowFragment.kt - Avoid use lateinit for binding While i'm applying several advice from reviewer, there's still some of it that i can't apply it now. Maybe later, and also this is closing for submission 1
1 parent e3ba37b commit 11a8357

File tree

9 files changed

+274
-117
lines changed

9 files changed

+274
-117
lines changed

.idea/gradle.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ android {
1111
minSdk 21
1212
targetSdk 31
1313
versionCode 1
14-
versionName "1.1"
14+
versionName "1.2"
1515

1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1717
vectorDrawables.useSupportLibrary = true

app/src/main/java/com/dicoding/moviecatalog/activity/DetailShowActivity.kt

+218-71
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.os.Bundle
44
import android.view.View
55
import androidx.appcompat.app.AppCompatActivity
66
import androidx.core.app.ShareCompat
7+
import androidx.core.content.ContextCompat
78
import androidx.lifecycle.ViewModelProvider
89
import androidx.recyclerview.widget.DividerItemDecoration
910
import androidx.recyclerview.widget.LinearLayoutManager
@@ -22,12 +23,6 @@ import com.dicoding.moviecatalog.viewmodel.DetailMovieViewModel
2223

2324
class DetailShowActivity : AppCompatActivity(), ShareCallback {
2425

25-
companion object {
26-
const val SHOW_ID = "show_id"
27-
const val EXTRA_MOVIE = "extra_movie"
28-
const val EXTRA_TV_SHOW = "extra_tvshow"
29-
}
30-
3126
private lateinit var movieDetailBinding: ContentDetailShowBinding
3227

3328
override fun onCreate(savedInstanceState: Bundle?) {
@@ -108,25 +103,27 @@ class DetailShowActivity : AppCompatActivity(), ShareCallback {
108103
}
109104

110105
private fun populateMovie(movieEntity: MovieEntity) {
111-
movieDetailBinding.movieTitleText.text = movieEntity.title
112-
movieDetailBinding.movieReleaseDate.text = movieEntity.releaseDate
113-
movieDetailBinding.movieDurationText.text = movieEntity.duration
114-
movieDetailBinding.movieRatingText.text = movieEntity.rating
115-
movieDetailBinding.descText.text = movieEntity.description
116-
if (movieEntity.genre1 == "Null") {
117-
movieDetailBinding.cvGenre1.visibility = View.INVISIBLE
118-
} else {
119-
movieDetailBinding.movieGenre1Text.text = movieEntity.genre1
120-
genreColoringGenre1(movieEntity.genre1)
121-
}
122-
if (movieEntity.genre2 == "Null") {
123-
movieDetailBinding.cvGenre2.visibility = View.INVISIBLE
124-
} else {
125-
movieDetailBinding.movieGenre2Text.text = movieEntity.genre2
126-
genreColoringGenre2(movieEntity.genre2)
106+
movieDetailBinding.apply {
107+
movieTitleText.text = movieEntity.title
108+
movieReleaseDate.text = movieEntity.releaseDate
109+
movieDurationText.text = movieEntity.duration
110+
movieRatingText.text = movieEntity.rating
111+
descText.text = movieEntity.description
112+
if (movieEntity.genre1 == "Null") {
113+
cvGenre1.visibility = View.INVISIBLE
114+
} else {
115+
movieGenre1Text.text = movieEntity.genre1
116+
genreColoringGenre1(movieEntity.genre1)
117+
}
118+
if (movieEntity.genre2 == "Null") {
119+
cvGenre2.visibility = View.INVISIBLE
120+
} else {
121+
movieGenre2Text.text = movieEntity.genre2
122+
genreColoringGenre2(movieEntity.genre2)
123+
}
124+
movieEpisodeImg.visibility = View.INVISIBLE
125+
movieEpisodeText.visibility = View.INVISIBLE
127126
}
128-
movieDetailBinding.movieEpisodeImg.visibility = View.INVISIBLE
129-
movieDetailBinding.movieEpisodeText.visibility = View.INVISIBLE
130127

131128
Glide.with(this)
132129
.load(movieEntity.imagePath)
@@ -138,33 +135,34 @@ class DetailShowActivity : AppCompatActivity(), ShareCallback {
138135
.into(movieDetailBinding.imagePoster)
139136

140137
movieDetailBinding.imagePoster.contentDescription = movieEntity.imagePath
141-
142138
movieDetailBinding.imgShare.setOnClickListener {
143139
onShareClickMovie(movieEntity)
144140
}
145141
}
146142

147143
private fun populateTvShow(tvShowEntity: TvShowEntity) {
148-
movieDetailBinding.movieTitleText.text = tvShowEntity.title
149-
movieDetailBinding.movieReleaseDate.text = tvShowEntity.releaseDate
150-
movieDetailBinding.movieDurationText.text = tvShowEntity.duration
151-
movieDetailBinding.movieRatingText.text = tvShowEntity.rating
152-
movieDetailBinding.descText.text = tvShowEntity.description
153-
val season: String =
154-
tvShowEntity.episode + " | " + tvShowEntity.season
155-
movieDetailBinding.movieEpisodeText.text = season
156-
157-
if (tvShowEntity.genre1 == "Null") {
158-
movieDetailBinding.cvGenre1.visibility = View.INVISIBLE
159-
} else {
160-
movieDetailBinding.movieGenre1Text.text = tvShowEntity.genre1
161-
genreColoringGenre1(tvShowEntity.genre1)
162-
}
163-
if (tvShowEntity.genre2 == "Null") {
164-
movieDetailBinding.cvGenre2.visibility = View.INVISIBLE
165-
} else {
166-
movieDetailBinding.movieGenre2Text.text = tvShowEntity.genre2
167-
genreColoringGenre2(tvShowEntity.genre2)
144+
movieDetailBinding.apply {
145+
movieTitleText.text = tvShowEntity.title
146+
movieReleaseDate.text = tvShowEntity.releaseDate
147+
movieDurationText.text = tvShowEntity.duration
148+
movieRatingText.text = tvShowEntity.rating
149+
descText.text = tvShowEntity.description
150+
val season: String =
151+
tvShowEntity.episode + " | " + tvShowEntity.season
152+
movieEpisodeText.text = season
153+
154+
if (tvShowEntity.genre1 == "Null") {
155+
cvGenre1.visibility = View.INVISIBLE
156+
} else {
157+
movieGenre1Text.text = tvShowEntity.genre1
158+
genreColoringGenre1(tvShowEntity.genre1)
159+
}
160+
if (tvShowEntity.genre2 == "Null") {
161+
cvGenre2.visibility = View.INVISIBLE
162+
} else {
163+
movieGenre2Text.text = tvShowEntity.genre2
164+
genreColoringGenre2(tvShowEntity.genre2)
165+
}
168166
}
169167

170168
Glide.with(this)
@@ -213,37 +211,186 @@ class DetailShowActivity : AppCompatActivity(), ShareCallback {
213211

214212
private fun genreColoringGenre1(genre1: String) {
215213
when (genre1) {
216-
"Drama" -> movieDetailBinding.cvGenre1.setCardBackgroundColor(resources.getColor(R.color.red))
217-
"Romance" -> movieDetailBinding.cvGenre1.setCardBackgroundColor(resources.getColor(R.color.red))
218-
"Action" -> movieDetailBinding.cvGenre1.setCardBackgroundColor(resources.getColor(R.color.blue))
219-
"Adventure" -> movieDetailBinding.cvGenre1.setCardBackgroundColor(resources.getColor(R.color.green))
220-
"Music" -> movieDetailBinding.cvGenre1.setCardBackgroundColor(resources.getColor(R.color.orange))
221-
"Crime" -> movieDetailBinding.cvGenre1.setCardBackgroundColor(resources.getColor(R.color.purple))
222-
"Fantasy" -> movieDetailBinding.cvGenre1.setCardBackgroundColor(resources.getColor(R.color.red))
223-
"Thriller" -> movieDetailBinding.cvGenre1.setCardBackgroundColor(resources.getColor(R.color.dark_green))
224-
"Family" -> movieDetailBinding.cvGenre1.setCardBackgroundColor(resources.getColor(R.color.blue))
225-
"Animation" -> movieDetailBinding.cvGenre1.setCardBackgroundColor(resources.getColor(R.color.red))
226-
"Sci-Fi" -> movieDetailBinding.cvGenre1.setCardBackgroundColor(resources.getColor(R.color.silver))
227-
"Comedy" -> movieDetailBinding.cvGenre1.setCardBackgroundColor(resources.getColor(R.color.yellow))
228-
"Mystery" -> movieDetailBinding.cvGenre1.setCardBackgroundColor(resources.getColor(R.color.green))
214+
drama -> movieDetailBinding.cvGenre1.setCardBackgroundColor(
215+
ContextCompat.getColor(
216+
this,
217+
R.color.red
218+
)
219+
)
220+
romance -> movieDetailBinding.cvGenre1.setCardBackgroundColor(
221+
ContextCompat.getColor(
222+
this,
223+
R.color.red
224+
)
225+
)
226+
action -> movieDetailBinding.cvGenre1.setCardBackgroundColor(
227+
ContextCompat.getColor(
228+
this,
229+
R.color.blue
230+
)
231+
)
232+
adventure -> movieDetailBinding.cvGenre1.setCardBackgroundColor(
233+
ContextCompat.getColor(
234+
this,
235+
R.color.green
236+
)
237+
)
238+
music -> movieDetailBinding.cvGenre1.setCardBackgroundColor(
239+
ContextCompat.getColor(
240+
this,
241+
R.color.orange
242+
)
243+
)
244+
crime -> movieDetailBinding.cvGenre1.setCardBackgroundColor(
245+
ContextCompat.getColor(
246+
this,
247+
R.color.purple
248+
)
249+
)
250+
fantasy -> movieDetailBinding.cvGenre1.setCardBackgroundColor(
251+
ContextCompat.getColor(
252+
this,
253+
R.color.red
254+
)
255+
)
256+
thriller -> movieDetailBinding.cvGenre1.setCardBackgroundColor(
257+
ContextCompat.getColor(
258+
this,
259+
R.color.dark_green
260+
)
261+
)
262+
family -> movieDetailBinding.cvGenre1.setCardBackgroundColor(
263+
ContextCompat.getColor(
264+
this,
265+
R.color.blue
266+
)
267+
)
268+
animation -> movieDetailBinding.cvGenre1.setCardBackgroundColor(
269+
ContextCompat.getColor(
270+
this,
271+
R.color.red
272+
)
273+
)
274+
sciFi -> movieDetailBinding.cvGenre1.setCardBackgroundColor(
275+
ContextCompat.getColor(
276+
this,
277+
R.color.silver
278+
)
279+
)
280+
comedy -> movieDetailBinding.cvGenre1.setCardBackgroundColor(
281+
ContextCompat.getColor(
282+
this,
283+
R.color.yellow
284+
)
285+
)
286+
mystery -> movieDetailBinding.cvGenre1.setCardBackgroundColor(
287+
ContextCompat.getColor(
288+
this,
289+
R.color.green
290+
)
291+
)
229292
}
230293
}
231294

232295
private fun genreColoringGenre2(genre2: String) {
233296
when (genre2) {
234-
"Drama" -> movieDetailBinding.cvGenre2.setCardBackgroundColor(resources.getColor(R.color.red))
235-
"Romance" -> movieDetailBinding.cvGenre2.setCardBackgroundColor(resources.getColor(R.color.red))
236-
"Action" -> movieDetailBinding.cvGenre2.setCardBackgroundColor(resources.getColor(R.color.blue))
237-
"Adventure" -> movieDetailBinding.cvGenre2.setCardBackgroundColor(resources.getColor(R.color.green))
238-
"Music" -> movieDetailBinding.cvGenre2.setCardBackgroundColor(resources.getColor(R.color.orange))
239-
"Crime" -> movieDetailBinding.cvGenre2.setCardBackgroundColor(resources.getColor(R.color.purple))
240-
"Fantasy" -> movieDetailBinding.cvGenre2.setCardBackgroundColor(resources.getColor(R.color.red))
241-
"Thriller" -> movieDetailBinding.cvGenre2.setCardBackgroundColor(resources.getColor(R.color.dark_green))
242-
"Family" -> movieDetailBinding.cvGenre2.setCardBackgroundColor(resources.getColor(R.color.blue))
243-
"Animation" -> movieDetailBinding.cvGenre2.setCardBackgroundColor(resources.getColor(R.color.red))
244-
"Sci-Fi" -> movieDetailBinding.cvGenre2.setCardBackgroundColor(resources.getColor(R.color.silver))
245-
"Comedy" -> movieDetailBinding.cvGenre2.setCardBackgroundColor(resources.getColor(R.color.yellow))
246-
"Mystery" -> movieDetailBinding.cvGenre2.setCardBackgroundColor(resources.getColor(R.color.green))
297+
drama -> movieDetailBinding.cvGenre2.setCardBackgroundColor(
298+
ContextCompat.getColor(
299+
this,
300+
R.color.red
301+
)
302+
)
303+
romance -> movieDetailBinding.cvGenre2.setCardBackgroundColor(
304+
ContextCompat.getColor(
305+
this,
306+
R.color.red
307+
)
308+
)
309+
action -> movieDetailBinding.cvGenre2.setCardBackgroundColor(
310+
ContextCompat.getColor(
311+
this,
312+
R.color.blue
313+
)
314+
)
315+
adventure -> movieDetailBinding.cvGenre2.setCardBackgroundColor(
316+
ContextCompat.getColor(
317+
this,
318+
R.color.green
319+
)
320+
)
321+
music -> movieDetailBinding.cvGenre2.setCardBackgroundColor(
322+
ContextCompat.getColor(
323+
this,
324+
R.color.orange
325+
)
326+
)
327+
crime -> movieDetailBinding.cvGenre2.setCardBackgroundColor(
328+
ContextCompat.getColor(
329+
this,
330+
R.color.purple
331+
)
332+
)
333+
fantasy -> movieDetailBinding.cvGenre2.setCardBackgroundColor(
334+
ContextCompat.getColor(
335+
this,
336+
R.color.red
337+
)
338+
)
339+
thriller -> movieDetailBinding.cvGenre2.setCardBackgroundColor(
340+
ContextCompat.getColor(
341+
this,
342+
R.color.dark_green
343+
)
344+
)
345+
family -> movieDetailBinding.cvGenre2.setCardBackgroundColor(
346+
ContextCompat.getColor(
347+
this,
348+
R.color.blue
349+
)
350+
)
351+
animation -> movieDetailBinding.cvGenre2.setCardBackgroundColor(
352+
ContextCompat.getColor(
353+
this,
354+
R.color.red
355+
)
356+
)
357+
sciFi -> movieDetailBinding.cvGenre2.setCardBackgroundColor(
358+
ContextCompat.getColor(
359+
this,
360+
R.color.silver
361+
)
362+
)
363+
comedy -> movieDetailBinding.cvGenre2.setCardBackgroundColor(
364+
ContextCompat.getColor(
365+
this,
366+
R.color.yellow
367+
)
368+
)
369+
mystery -> movieDetailBinding.cvGenre2.setCardBackgroundColor(
370+
ContextCompat.getColor(
371+
this,
372+
R.color.green
373+
)
374+
)
247375
}
248376
}
377+
378+
companion object {
379+
const val SHOW_ID = "show_id"
380+
const val EXTRA_MOVIE = "extra_movie"
381+
const val EXTRA_TV_SHOW = "extra_tvshow"
382+
const val drama = "Drama"
383+
const val romance = "Romance"
384+
const val action = "Action"
385+
const val adventure = "Adventure"
386+
const val music = "Music"
387+
const val crime = "Crime"
388+
const val fantasy = "Fantasy"
389+
const val thriller = "Thriller"
390+
const val family = "Family"
391+
const val animation = "Animation"
392+
const val sciFi = "Sci-Fi"
393+
const val comedy = "Comedy"
394+
const val mystery = "Mystery"
395+
}
249396
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.dicoding.moviecatalog.data.movie
22

33
data class MovieCastEntity(
4-
var castId: String,
5-
var castMovieName: String,
6-
var castRealName: String,
7-
var castImage: String
4+
val castId: String,
5+
val castMovieName: String,
6+
val castRealName: String,
7+
val castImage: String
88
)
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.dicoding.moviecatalog.data.movie
22

33
data class MovieEntity(
4-
var movieId: String,
5-
var title: String,
6-
var genre1: String,
7-
var genre2: String,
8-
var description: String,
9-
var duration: String,
10-
var releaseDate: String,
11-
var imagePath: String,
12-
var rating: String
4+
val movieId: String,
5+
val title: String,
6+
val genre1: String,
7+
val genre2: String,
8+
val description: String,
9+
val duration: String,
10+
val releaseDate: String,
11+
val imagePath: String,
12+
val rating: String
1313
)

0 commit comments

Comments
 (0)