@@ -4,6 +4,7 @@ import android.os.Bundle
4
4
import android.view.View
5
5
import androidx.appcompat.app.AppCompatActivity
6
6
import androidx.core.app.ShareCompat
7
+ import androidx.core.content.ContextCompat
7
8
import androidx.lifecycle.ViewModelProvider
8
9
import androidx.recyclerview.widget.DividerItemDecoration
9
10
import androidx.recyclerview.widget.LinearLayoutManager
@@ -22,12 +23,6 @@ import com.dicoding.moviecatalog.viewmodel.DetailMovieViewModel
22
23
23
24
class DetailShowActivity : AppCompatActivity (), ShareCallback {
24
25
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
-
31
26
private lateinit var movieDetailBinding: ContentDetailShowBinding
32
27
33
28
override fun onCreate (savedInstanceState : Bundle ? ) {
@@ -108,25 +103,27 @@ class DetailShowActivity : AppCompatActivity(), ShareCallback {
108
103
}
109
104
110
105
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
127
126
}
128
- movieDetailBinding.movieEpisodeImg.visibility = View .INVISIBLE
129
- movieDetailBinding.movieEpisodeText.visibility = View .INVISIBLE
130
127
131
128
Glide .with (this )
132
129
.load(movieEntity.imagePath)
@@ -138,33 +135,34 @@ class DetailShowActivity : AppCompatActivity(), ShareCallback {
138
135
.into(movieDetailBinding.imagePoster)
139
136
140
137
movieDetailBinding.imagePoster.contentDescription = movieEntity.imagePath
141
-
142
138
movieDetailBinding.imgShare.setOnClickListener {
143
139
onShareClickMovie(movieEntity)
144
140
}
145
141
}
146
142
147
143
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
+ }
168
166
}
169
167
170
168
Glide .with (this )
@@ -213,37 +211,186 @@ class DetailShowActivity : AppCompatActivity(), ShareCallback {
213
211
214
212
private fun genreColoringGenre1 (genre1 : String ) {
215
213
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
+ )
229
292
}
230
293
}
231
294
232
295
private fun genreColoringGenre2 (genre2 : String ) {
233
296
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
+ )
247
375
}
248
376
}
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
+ }
249
396
}
0 commit comments