From 4738c1869488092978e405e2b30a92975996d2c5 Mon Sep 17 00:00:00 2001 From: amirisback Date: Sun, 29 Mar 2020 21:07:59 +0700 Subject: [PATCH] add: Networks method function --- README.md | 22 ++++++ .../frogothemoviedbapi/ConsumeMovieApi.kt | 72 ++++++++++++++++++ .../frogothemoviedbapi/ConsumeMovieApiView.kt | 21 ++++++ .../data/model/NetworkLogo.kt | 31 ++++++++ .../data/model/NetworkName.kt | 13 ++++ .../data/response/NetworkAlternativeName.kt | 31 ++++++++ .../data/response/NetworkDetail.kt | 39 ++++++++++ .../data/response/NetworkImage.kt | 31 ++++++++ .../data/source/MovieApiService.kt | 24 ++++++ .../data/source/MovieDataSource.kt | 24 ++++++ .../data/source/MovieRemoteDataSource.kt | 75 +++++++++++++++++++ .../data/source/MovieRepository.kt | 23 ++++++ 12 files changed, 406 insertions(+) create mode 100644 frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/model/NetworkLogo.kt create mode 100644 frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/model/NetworkName.kt create mode 100644 frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/response/NetworkAlternativeName.kt create mode 100644 frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/response/NetworkDetail.kt create mode 100644 frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/response/NetworkImage.kt diff --git a/README.md b/README.md index f789655..0cb8cd6 100644 --- a/README.md +++ b/README.md @@ -340,6 +340,28 @@ https://developers.themoviedb.org/3/getting-started/introduction ## LIST ## NETWORKS + + // NETWORKS + // Get Details + fun getNetworkDetail( + network_id: Int, + callback: MovieResultCallback + ) + + // NETWORKS + // Get Alternative Names + fun getNetworkAlternativeName( + network_id: Int, + callback: MovieResultCallback + ) + + // NETWORKS + // Get Images + fun getNetworkImage( + network_id: Int, + callback: MovieResultCallback + ) + ## PEOPLE ## SEARCH ## TV diff --git a/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/ConsumeMovieApi.kt b/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/ConsumeMovieApi.kt index 972b7d2..5a87d95 100644 --- a/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/ConsumeMovieApi.kt +++ b/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/ConsumeMovieApi.kt @@ -1042,4 +1042,76 @@ class ConsumeMovieApi(private val apiKey: String) : ConsumeMovieApiView { } }) } + + override fun getNetworkDetail(network_id: Int, callback: MovieResultCallback) { + movieRepository.getNetworkDetail( + network_id, + apiKey, + object : MovieDataSource.GetRemoteCallback { + override fun onSuccess(data: NetworkDetail) { + callback.getResultData(data) + } + + override fun onFailed(statusCode: Int, errorMessage: String?) { + callback.failedResult(statusCode, errorMessage) + } + + override fun onShowProgress() { + callback.onShowProgress() + } + + override fun onHideProgress() { + callback.onHideProgress() + } + }) + } + + override fun getNetworkAlternativeName( + network_id: Int, + callback: MovieResultCallback + ) { + movieRepository.getNetworkAlternativeName( + network_id, + apiKey, + object : MovieDataSource.GetRemoteCallback { + override fun onSuccess(data: NetworkAlternativeName) { + callback.getResultData(data) + } + + override fun onFailed(statusCode: Int, errorMessage: String?) { + callback.failedResult(statusCode, errorMessage) + } + + override fun onShowProgress() { + callback.onShowProgress() + } + + override fun onHideProgress() { + callback.onHideProgress() + } + }) + } + + override fun getNetworkImage(network_id: Int, callback: MovieResultCallback) { + movieRepository.getNetworkImage( + network_id, + apiKey, + object : MovieDataSource.GetRemoteCallback { + override fun onSuccess(data: NetworkImage) { + callback.getResultData(data) + } + + override fun onFailed(statusCode: Int, errorMessage: String?) { + callback.failedResult(statusCode, errorMessage) + } + + override fun onShowProgress() { + callback.onShowProgress() + } + + override fun onHideProgress() { + callback.onHideProgress() + } + }) + } } \ No newline at end of file diff --git a/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/ConsumeMovieApiView.kt b/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/ConsumeMovieApiView.kt index 3a45833..6f82e98 100644 --- a/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/ConsumeMovieApiView.kt +++ b/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/ConsumeMovieApiView.kt @@ -314,4 +314,25 @@ interface ConsumeMovieApiView { callback: MovieResultCallback ) + // NETWORKS + // Get Details + fun getNetworkDetail( + network_id: Int, + callback: MovieResultCallback + ) + + // NETWORKS + // Get Alternative Names + fun getNetworkAlternativeName( + network_id: Int, + callback: MovieResultCallback + ) + + // NETWORKS + // Get Images + fun getNetworkImage( + network_id: Int, + callback: MovieResultCallback + ) + } \ No newline at end of file diff --git a/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/model/NetworkLogo.kt b/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/model/NetworkLogo.kt new file mode 100644 index 0000000..0d7eaab --- /dev/null +++ b/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/model/NetworkLogo.kt @@ -0,0 +1,31 @@ +package com.frogobox.frogothemoviedbapi.data.model + +import com.google.gson.annotations.SerializedName + +data class NetworkLogo( + + @SerializedName("aspect_ratio") + var aspect_ratio: Int? = null, + + @SerializedName("file_path") + var file_path: String? = null, + + @SerializedName("height") + var height: Int? = null, + + @SerializedName("id") + var id: String? = null, + + @SerializedName("file_type") + var file_type: String? = null, + + @SerializedName("vote_average") + var vote_average: Int? = null, + + @SerializedName("vote_count") + var vote_count: Int? = null, + + @SerializedName("width") + var width: Int? = null + +) diff --git a/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/model/NetworkName.kt b/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/model/NetworkName.kt new file mode 100644 index 0000000..ce9a55a --- /dev/null +++ b/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/model/NetworkName.kt @@ -0,0 +1,13 @@ +package com.frogobox.frogothemoviedbapi.data.model + +import com.google.gson.annotations.SerializedName + +data class NetworkName( + + @SerializedName("name") + var name: String? = null, + + @SerializedName("type") + var type: String? = null + +) diff --git a/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/response/NetworkAlternativeName.kt b/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/response/NetworkAlternativeName.kt new file mode 100644 index 0000000..e14fd07 --- /dev/null +++ b/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/response/NetworkAlternativeName.kt @@ -0,0 +1,31 @@ +package com.frogobox.frogothemoviedbapi.data.response + +import com.frogobox.frogothemoviedbapi.data.model.NetworkName +import com.google.gson.annotations.SerializedName + +/** + * Created by Faisal Amir + * FrogoBox Inc License + * ========================================= + * consumable-code-movie-tmdb-api + * Copyright (C) 29/03/2020. + * All rights reserved + * ----------------------------------------- + * Name : Muhammad Faisal Amir + * E-mail : faisalamircs@gmail.com + * Github : github.com/amirisback + * LinkedIn : linkedin.com/in/faisalamircs + * ----------------------------------------- + * FrogoBox Software Industries + * com.frogobox.frogothemoviedbapi.data.response + * + */ +data class NetworkAlternativeName( + + @SerializedName("id") + var id: Int? = null, + + @SerializedName("results") + var results: List? = null + +) \ No newline at end of file diff --git a/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/response/NetworkDetail.kt b/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/response/NetworkDetail.kt new file mode 100644 index 0000000..79631c7 --- /dev/null +++ b/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/response/NetworkDetail.kt @@ -0,0 +1,39 @@ +package com.frogobox.frogothemoviedbapi.data.response + +import com.google.gson.annotations.SerializedName + +/** + * Created by Faisal Amir + * FrogoBox Inc License + * ========================================= + * consumable-code-movie-tmdb-api + * Copyright (C) 29/03/2020. + * All rights reserved + * ----------------------------------------- + * Name : Muhammad Faisal Amir + * E-mail : faisalamircs@gmail.com + * Github : github.com/amirisback + * LinkedIn : linkedin.com/in/faisalamircs + * ----------------------------------------- + * FrogoBox Software Industries + * com.frogobox.frogothemoviedbapi.data.response + * + */ +data class NetworkDetail( + + @SerializedName("headquarters") + var headquarters: String? = null, + + @SerializedName("homepage") + var homepage: String? = null, + + @SerializedName("id") + var id: Int? = null, + + @SerializedName("name") + var name: String? = null, + + @SerializedName("origin_country") + var origin_country: String? = null + +) \ No newline at end of file diff --git a/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/response/NetworkImage.kt b/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/response/NetworkImage.kt new file mode 100644 index 0000000..d14e6b6 --- /dev/null +++ b/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/response/NetworkImage.kt @@ -0,0 +1,31 @@ +package com.frogobox.frogothemoviedbapi.data.response + +import com.frogobox.frogothemoviedbapi.data.model.NetworkLogo +import com.frogobox.frogothemoviedbapi.data.model.NetworkName +import com.google.gson.annotations.SerializedName + +/** + * Created by Faisal Amir + * FrogoBox Inc License + * ========================================= + * consumable-code-movie-tmdb-api + * Copyright (C) 29/03/2020. + * All rights reserved + * ----------------------------------------- + * Name : Muhammad Faisal Amir + * E-mail : faisalamircs@gmail.com + * Github : github.com/amirisback + * LinkedIn : linkedin.com/in/faisalamircs + * ----------------------------------------- + * FrogoBox Software Industries + * com.frogobox.frogothemoviedbapi.data.response + * + */ +data class NetworkImage( + + @SerializedName("id") + var id: Int? = null, + + @SerializedName("results") + var results: List? = null +) \ No newline at end of file diff --git a/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/source/MovieApiService.kt b/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/source/MovieApiService.kt index 5ef1938..870bb93 100644 --- a/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/source/MovieApiService.kt +++ b/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/source/MovieApiService.kt @@ -357,6 +357,30 @@ interface MovieApiService { @Query(MovieConstant.QUERY_API_KEY) apiKey: String ): Observable + // NETWORKS + // Get Details + @GET(MovieUrl.NETWORKS_GET_DETAILS) + fun getNetworkDetail( + @Path(MovieConstant.PATH_NETWORK_ID) network_id: Int, + @Query(MovieConstant.QUERY_API_KEY) apiKey: String + ): Observable + + // NETWORKS + // Get Alternative Names + @GET(MovieUrl.NETWORKS_GET_ALTERNATIVE_NAMES) + fun getNetworkAlternativeName( + @Path(MovieConstant.PATH_NETWORK_ID) network_id: Int, + @Query(MovieConstant.QUERY_API_KEY) apiKey: String + ): Observable + + // NETWORKS + // Get Images + @GET(MovieUrl.NETWORKS_GET_IMAGES) + fun getNetworkImage( + @Path(MovieConstant.PATH_NETWORK_ID) network_id: Int, + @Query(MovieConstant.QUERY_API_KEY) apiKey: String + ): Observable + companion object Factory { private var isUsingChuckInterceptor = false diff --git a/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/source/MovieDataSource.kt b/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/source/MovieDataSource.kt index 9461e99..66738da 100644 --- a/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/source/MovieDataSource.kt +++ b/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/source/MovieDataSource.kt @@ -336,6 +336,30 @@ interface MovieDataSource { callback: GetRemoteCallback ) + // NETWORKS + // Get Details + fun getNetworkDetail( + network_id: Int, + apiKey: String, + callback: GetRemoteCallback + ) + + // NETWORKS + // Get Alternative Names + fun getNetworkAlternativeName( + network_id: Int, + apiKey: String, + callback: GetRemoteCallback + ) + + // NETWORKS + // Get Images + fun getNetworkImage( + network_id: Int, + apiKey: String, + callback: GetRemoteCallback + ) + // Response Callback interface GetRemoteCallback : BaseMovieDataSource.ResponseCallback diff --git a/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/source/MovieRemoteDataSource.kt b/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/source/MovieRemoteDataSource.kt index 004c51f..626554f 100644 --- a/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/source/MovieRemoteDataSource.kt +++ b/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/source/MovieRemoteDataSource.kt @@ -953,4 +953,79 @@ object MovieRemoteDataSource : MovieDataSource { } }) } + + override fun getNetworkDetail( + network_id: Int, + apiKey: String, + callback: MovieDataSource.GetRemoteCallback + ) { + movieApiService.getApiService + .getNetworkDetail(network_id, apiKey) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .doOnSubscribe { callback.onShowProgress() } + .doOnTerminate { callback.onHideProgress() } + .subscribe(object : MovieApiCallback() { + override fun onSuccess(data: NetworkDetail) { + callback.onSuccess(data) + } + + override fun onFailure(statusCode: Int, errorMessage: String) { + callback.onFailed(statusCode, errorMessage) + } + + override fun onFinish() { + } + }) + } + + override fun getNetworkAlternativeName( + network_id: Int, + apiKey: String, + callback: MovieDataSource.GetRemoteCallback + ) { + movieApiService.getApiService + .getNetworkAlternativeName(network_id, apiKey) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .doOnSubscribe { callback.onShowProgress() } + .doOnTerminate { callback.onHideProgress() } + .subscribe(object : MovieApiCallback() { + override fun onSuccess(data: NetworkAlternativeName) { + callback.onSuccess(data) + } + + override fun onFailure(statusCode: Int, errorMessage: String) { + callback.onFailed(statusCode, errorMessage) + } + + override fun onFinish() { + } + }) + } + + override fun getNetworkImage( + network_id: Int, + apiKey: String, + callback: MovieDataSource.GetRemoteCallback + ) { + movieApiService.getApiService + .getNetworkImage(network_id, apiKey) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .doOnSubscribe { callback.onShowProgress() } + .doOnTerminate { callback.onHideProgress() } + .subscribe(object : MovieApiCallback() { + override fun onSuccess(data: NetworkImage) { + callback.onSuccess(data) + } + + override fun onFailure(statusCode: Int, errorMessage: String) { + callback.onFailed(statusCode, errorMessage) + } + + override fun onFinish() { + } + }) + } } \ No newline at end of file diff --git a/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/source/MovieRepository.kt b/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/source/MovieRepository.kt index 96e0f72..56a9a4e 100644 --- a/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/source/MovieRepository.kt +++ b/frogothemoviedbapi/src/main/java/com/frogobox/frogothemoviedbapi/data/source/MovieRepository.kt @@ -414,4 +414,27 @@ class MovieRepository(private val remoteDataSource: MovieRemoteDataSource) : Mov remoteDataSource.getReviews(review_id, apiKey, callback) } + override fun getNetworkDetail( + network_id: Int, + apiKey: String, + callback: MovieDataSource.GetRemoteCallback + ) { + remoteDataSource.getNetworkDetail(network_id, apiKey, callback) + } + + override fun getNetworkAlternativeName( + network_id: Int, + apiKey: String, + callback: MovieDataSource.GetRemoteCallback + ) { + remoteDataSource.getNetworkAlternativeName(network_id, apiKey, callback) + } + + override fun getNetworkImage( + network_id: Int, + apiKey: String, + callback: MovieDataSource.GetRemoteCallback + ) { + remoteDataSource.getNetworkImage(network_id, apiKey, callback) + } } \ No newline at end of file