-
Notifications
You must be signed in to change notification settings - Fork 0
/
movieFilter.kt
66 lines (57 loc) · 2.11 KB
/
movieFilter.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main.whattowatch
enum class Genre {
SCIENCEFICTION, COMEDY, DOCUMENTARY,
DRAMA, FAMILY, ACTION, WESTERN, WAR,
CRIME, FANTASY, ADVENTURE, HORROR,
THRILLER, ROMANCE, ANIMATION
}
class MovieFilter {
fun filterByYear(movies: ArrayList<Movie>, year: String): ArrayList<Movie> {
val filtered = ArrayList<Movie>()
for(m in 0 until movies.size) {
var releaseYear = movies[m].releaseDate.split("-").toTypedArray()[0]
if (releaseYear == year) {
filtered.add(movies[m])
}
}
return filtered
}
fun filterForeign(movies: ArrayList<Movie>): ArrayList<Movie> {
val filtered = ArrayList<Movie>()
for (i in 0 until movies.size) {
if (movies[i].language == "en") {
filtered.add(movies[i])
}
}
return filtered
}
fun filterByGenre(movies: ArrayList<Movie>, genre: Genre): ArrayList<Movie> {
var genreString = ""
val filtered = ArrayList<Movie>()
when(genre) {
Genre.SCIENCEFICTION -> genreString = "ScienceFiction"
Genre.COMEDY -> genreString = "Comedy"
Genre.DOCUMENTARY -> genreString = "Documentary"
Genre.DRAMA -> genreString = "Drama"
Genre.FAMILY -> genreString = "Family"
Genre.ACTION -> genreString = "Action"
Genre.WESTERN -> genreString = "Western"
Genre.WAR -> genreString = "War"
Genre.CRIME -> genreString = "Crime"
Genre.FANTASY -> genreString = "Fantasy"
Genre.ADVENTURE -> genreString = "Adventure"
Genre.HORROR -> genreString = "Horror"
Genre.THRILLER -> genreString = "Thriller"
Genre.ROMANCE -> genreString = "Romance"
Genre.ANIMATION -> genreString = "Animation"
}
for (i in 0 until movies.size) {
for (g in 0 until movies[i].genres.size) {
if (movies[i].genres[g] == genreString) {
filtered.add(movies[i])
}
}
}
return filtered
}
}