-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Urdzik/the-movie-db-branch
The movie db branch
- Loading branch information
Showing
20 changed files
with
299 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
|
||
# Built application files | ||
*.apk | ||
*.aar | ||
*.ap_ | ||
*.aab | ||
|
||
# Files for the ART/Dalvik VM | ||
*.dex | ||
|
||
# Java class files | ||
*.class | ||
|
||
# Generated files | ||
bin/ | ||
gen/ | ||
out/ | ||
# Uncomment the following line in case you need and you don't have the release build type files in your app | ||
# release/ | ||
|
||
# Gradle files | ||
.gradle/ | ||
build/ | ||
|
||
# Local configuration file (sdk path, etc) | ||
local.properties | ||
|
||
# Proguard folder generated by Eclipse | ||
proguard/ | ||
|
||
# Log Files | ||
*.log | ||
|
||
# Android Studio Navigation editor temp files | ||
.navigation/ | ||
|
||
# Android Studio captures folder | ||
captures/ | ||
|
||
# IntelliJ | ||
*.iml | ||
.idea | ||
.idea/workspace.xml | ||
.idea/tasks.xml | ||
.idea/gradle.xml | ||
.idea/assetWizardSettings.xml | ||
.idea/dictionaries | ||
.idea/libraries | ||
# Android Studio 3 in .gitignore file. | ||
.idea/caches | ||
.idea/modules.xml | ||
# Comment next line if keeping position of elements in Navigation Editor is relevant for you | ||
.idea/navEditor.xml | ||
|
||
# Keystore files | ||
# Uncomment the following lines if you do not want to check your keystore files in. | ||
#*.jks | ||
#*.keystore | ||
|
||
# External native build folder generated in Android Studio 2.2 and later | ||
.externalNativeBuild | ||
.cxx/ | ||
|
||
# Google Services (e.g. APIs or Firebase) | ||
# google-services.json | ||
|
||
# Freeline | ||
freeline.py | ||
freeline/ | ||
freeline_project_description.json | ||
|
||
# fastlane | ||
fastlane/report.xml | ||
fastlane/Preview.html | ||
fastlane/screenshots | ||
fastlane/test_output | ||
fastlane/readme.md | ||
|
||
# Version control | ||
vcs.xml | ||
|
||
# lint | ||
lint/intermediates/ | ||
lint/generated/ | ||
lint/outputs/ | ||
lint/tmp/ | ||
# lint/reports/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 8 additions & 2 deletions
10
app/src/main/java/com/example/movieapp/model/network/MovieApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
package com.example.movieapp.model.network | ||
|
||
import com.example.movieapp.model.network.data.MovieInfo | ||
import com.example.movieapp.model.network.data.Results | ||
import retrofit2.http.GET | ||
import retrofit2.http.Path | ||
|
||
|
||
//A retrofit service to fetch movie playlist. | ||
interface MovieApi { | ||
@GET("movie.json") | ||
suspend fun getPropertyAsync(): List<NetworkMovie> | ||
@GET("top_rated?api_key=26f381d6ab8dd659b22d983cab9aa255&language=ru&page=1") | ||
suspend fun getPropertyAsync(): Results | ||
|
||
@GET("{id}?api_key=26f381d6ab8dd659b22d983cab9aa255&language=ru") | ||
suspend fun getMovieByID(@Path("id") id: Int): MovieInfo | ||
} |
29 changes: 0 additions & 29 deletions
29
app/src/main/java/com/example/movieapp/model/network/NetworkMovie.kt
This file was deleted.
Oops, something went wrong.
15 changes: 11 additions & 4 deletions
15
app/src/main/java/com/example/movieapp/model/network/NetworkSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
package com.example.movieapp.model.network | ||
|
||
import com.example.movieapp.model.network.data.MovieInfo | ||
import com.example.movieapp.model.network.data.NetworkMovie | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import javax.inject.Inject | ||
|
||
class NetworkSource @Inject constructor( | ||
private val api: MovieApi | ||
) { | ||
class NetworkSource @Inject constructor(private val api: MovieApi) { | ||
suspend fun retrieveData(): List<NetworkMovie> = withContext(Dispatchers.IO) { | ||
val playList = api.getPropertyAsync() | ||
playList | ||
playList.networkMovie | ||
} | ||
} | ||
|
||
class MovieInfoSource @Inject constructor(private val api: MovieApi){ | ||
suspend fun retrieveInfoData(id: Int): MovieInfo = withContext(Dispatchers.IO){ | ||
val infoOfMovie = api.getMovieByID(id) | ||
infoOfMovie | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
app/src/main/java/com/example/movieapp/model/network/data/MovieInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.example.movieapp.model.network.data | ||
|
||
|
||
data class MovieInfo ( | ||
val adult: Boolean, | ||
val backdrop_path: String, | ||
val belongs_to_collection: String, | ||
val budget: Int, | ||
val genres: List<Genres>, | ||
val homepage: String, | ||
val id: Int, | ||
val imdb_id: String, | ||
val original_language: String, | ||
val original_title: String, | ||
val overview: String, | ||
val popularity: Double, | ||
val poster_path: String, | ||
val production_companies: List<ProductionCompanies>, | ||
val production_countries: List<ProductionCountries>, | ||
val release_date: String, | ||
val revenue: Int, | ||
val runtime: Int, | ||
val spoken_languages: List<SpokenLanguages>, | ||
val status: String, | ||
val tagline: String, | ||
val title: String, | ||
val video: Boolean, | ||
val vote_average: Double, | ||
val vote_count: Int | ||
) | ||
|
||
data class SpokenLanguages ( | ||
val iso_639_1: String, | ||
val name: String | ||
) | ||
data class ProductionCountries ( | ||
val iso_3166_1: String, | ||
val name: String | ||
) | ||
data class ProductionCompanies ( | ||
val id: Int, | ||
val logo_path: String, | ||
val name: String, | ||
val origin_country: String | ||
) | ||
|
||
data class Genres ( | ||
val id: Int, | ||
val name: String | ||
) |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/example/movieapp/model/network/data/NetworkMovie.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.example.movieapp.model.network.data | ||
|
||
import android.view.View | ||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
|
||
//Network object of movie for REST | ||
@JsonClass(generateAdapter = true) | ||
data class Results( | ||
@Json(name = "results") val networkMovie: List<NetworkMovie>, | ||
@Json(name = "page") val page: Int, | ||
@Json(name = "total_results") val totalResults: Int, | ||
@Json(name = "total_pages") val totalPages: Int | ||
) | ||
|
||
data class NetworkMovie( | ||
val id: Int, | ||
val adult: Boolean, | ||
val popularity: Double, | ||
val voteCount: Int, | ||
val video: Boolean, | ||
val poster_path: String, | ||
val backdrop_path: String, | ||
val original_language: String, | ||
val original_title: String, | ||
val genre_ids: List<Int>, | ||
val title: String, | ||
val vote_average: Double, | ||
val overview: String, | ||
val release_date: String | ||
){ | ||
val plus18 | ||
get() = if (adult) View.VISIBLE else View.GONE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 13 additions & 7 deletions
20
app/src/main/java/com/example/movieapp/ui/detail/DetailViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
package com.example.movieapp.ui.detail | ||
|
||
import android.util.Log | ||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import com.example.movieapp.model.network.NetworkMovie | ||
import androidx.lifecycle.viewModelScope | ||
import com.example.movieapp.model.network.MovieInfoSource | ||
import com.example.movieapp.model.network.data.MovieInfo | ||
import com.example.movieapp.model.network.data.NetworkMovie | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
class DetailViewModel @Inject constructor() : ViewModel() { | ||
class DetailViewModel @Inject constructor(private val movieInfoSource: MovieInfoSource) : ViewModel() { | ||
|
||
//LiveData object of movie | ||
private val _selectProperty = MutableLiveData<NetworkMovie>() | ||
val selectProperty: LiveData<NetworkMovie> | ||
private val _selectProperty = MutableLiveData<MovieInfo>() | ||
val selectProperty: LiveData<MovieInfo> | ||
get() = _selectProperty | ||
|
||
|
||
fun getSelectMovie(networkMovie: NetworkMovie) { | ||
_selectProperty.value = networkMovie | ||
fun getSelectMovie(id: Int) { | ||
viewModelScope.launch { | ||
_selectProperty.value = movieInfoSource.retrieveInfoData(id) | ||
} | ||
} | ||
} |
Oops, something went wrong.