This repository has been archived by the owner on May 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[PR] [feature #5] Screen listing most popular shows
- Loading branch information
Showing
28 changed files
with
497 additions
and
49 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
app/src/main/java/com/example/isabelcosta/moviesapp/adapters/MostPopularShowsAdapter.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,42 @@ | ||
package com.example.isabelcosta.moviesapp.adapters | ||
|
||
import android.support.v7.widget.RecyclerView | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import com.example.isabelcosta.moviesapp.R | ||
import com.example.isabelcosta.moviesapp.data.models.MostPopularShowsListItemResponseData | ||
import com.example.isabelcosta.moviesapp.ui.activities.BaseActivity | ||
import com.example.isabelcosta.moviesapp.utils.getFullImageUrl | ||
import com.squareup.picasso.Picasso | ||
import kotlinx.android.synthetic.main.item_most_popular_shows.view.* | ||
|
||
class MostPopularShowsAdapter( | ||
private val context: BaseActivity, | ||
private val showsList: List<MostPopularShowsListItemResponseData> | ||
) : RecyclerView.Adapter<MostPopularShowsAdapter.MostPopularShowsViewHolder>() { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): MostPopularShowsViewHolder { | ||
val v = LayoutInflater.from(context).inflate(R.layout.item_most_popular_shows, parent, false) | ||
return MostPopularShowsViewHolder(v) | ||
} | ||
|
||
override fun onBindViewHolder(holder: MostPopularShowsViewHolder?, position: Int) { | ||
val item = showsList[position] | ||
val itemView = holder?.itemView ?: return | ||
|
||
itemView.mostPopularShowsItemTitle.text = item.originalName | ||
itemView.mostPopularShowsItemRating.text = item.voteAverage.toString() | ||
val imageFullPath = getFullImageUrl(item.posterPath) | ||
Picasso.with(context).load(imageFullPath).into(itemView.mostPopularShowsItemPosterImage) | ||
|
||
// itemView.setOnClickListener() | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return showsList.size | ||
} | ||
|
||
class MostPopularShowsViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) | ||
|
||
} |
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
26 changes: 26 additions & 0 deletions
26
...c/main/java/com/example/isabelcosta/moviesapp/data/models/MostPopularShowsResponseData.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,26 @@ | ||
package com.example.isabelcosta.moviesapp.data.models | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class MostPopularShowsListResponseData( | ||
@SerializedName("page") val page: Int, //1 | ||
@SerializedName("total_results") val totalResults: Int, //20022 | ||
@SerializedName("total_pages") val totalPages: Int, //1002 | ||
@SerializedName("results") val results: List<MostPopularShowsListItemResponseData> | ||
) | ||
|
||
data class MostPopularShowsListItemResponseData( | ||
@SerializedName("original_name") val originalName: String, //The Walking Dead | ||
@SerializedName("genre_ids") val genreIds: List<Int>, | ||
@SerializedName("name") val name: String, //The Walking Dead | ||
@SerializedName("popularity") val popularity: Double, //232.631301 | ||
@SerializedName("origin_country") val originCountry: List<String>, | ||
@SerializedName("vote_count") val voteCount: Int, //2608 | ||
@SerializedName("first_air_date") val firstAirDate: String, //2010-10-31 | ||
@SerializedName("backdrop_path") val backdropPath: String, ///xVzvD5BPAU4HpleFSo8QOdHkndo.jpg | ||
@SerializedName("original_language") val originalLanguage: String, //en | ||
@SerializedName("movieId") val showId: Int, //1402 | ||
@SerializedName("vote_average") val voteAverage: Double, //7.4 | ||
@SerializedName("overview") val overview: String, //Sheriff's deputy Rick Grimes awakens from a coma to find a post-apocalyptic world dominated by flesh-eating zombies. He sets out to find his family and encounters many other survivors along the way. | ||
@SerializedName("poster_path") val posterPath: String ///vxuoMW6YBt6UsxvMfRNwRl9LtWS.jpg | ||
) |
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
19 changes: 19 additions & 0 deletions
19
app/src/main/java/com/example/isabelcosta/moviesapp/data/source/ITvDataSource.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,19 @@ | ||
package com.example.isabelcosta.moviesapp.data.source | ||
|
||
import com.example.isabelcosta.moviesapp.data.models.MostPopularShowsListResponseData | ||
|
||
interface ITvDataSource { | ||
|
||
interface GetMostPopularShows { | ||
fun onSuccessGetMostPopularShows(tvShows: MostPopularShowsListResponseData) | ||
fun onFailGetMostPopularShows() | ||
} | ||
|
||
interface GetTvShowDetail { | ||
fun onSuccessGetTvShowDetail() | ||
fun onFailGetTvShowDetail() | ||
} | ||
|
||
fun getMostPopularShows(presenter: ITvDataSource.GetMostPopularShows) | ||
fun getTvShowDetail(presenter: ITvDataSource.GetTvShowDetail, tvShowId: Int) | ||
} |
40 changes: 40 additions & 0 deletions
40
app/src/main/java/com/example/isabelcosta/moviesapp/data/source/remote/TvRemoteDataSource.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,40 @@ | ||
package com.example.isabelcosta.moviesapp.data.source.remote | ||
|
||
import com.example.isabelcosta.moviesapp.data.models.MostPopularShowsListResponseData | ||
import com.example.isabelcosta.moviesapp.data.remote.RemoteDataSource | ||
import com.example.isabelcosta.moviesapp.data.source.ITvDataSource | ||
import com.example.isabelcosta.moviesapp.data.source.remote.service.TvAPIService | ||
import retrofit2.Call | ||
import retrofit2.Callback | ||
import retrofit2.Response | ||
|
||
class TvRemoteDataSource : RemoteDataSource(), ITvDataSource { | ||
|
||
private val service: TvAPIService = retrofit.create(TvAPIService::class.java) | ||
|
||
override fun getMostPopularShows(presenter: ITvDataSource.GetMostPopularShows) { | ||
|
||
val call = service.getPopularTvShows(apiKey) | ||
|
||
call.enqueue(object : Callback<MostPopularShowsListResponseData> { | ||
override fun onResponse(call: Call<MostPopularShowsListResponseData>?, response: Response<MostPopularShowsListResponseData>?) { | ||
|
||
val responseBody = response?.body() | ||
if (responseBody != null) { | ||
presenter.onSuccessGetMostPopularShows(responseBody) | ||
} else { | ||
presenter.onFailGetMostPopularShows() | ||
} | ||
} | ||
|
||
override fun onFailure(call: Call<MostPopularShowsListResponseData>?, t: Throwable?) { | ||
presenter.onFailGetMostPopularShows() | ||
} | ||
}) | ||
} | ||
|
||
override fun getTvShowDetail(presenter: ITvDataSource.GetTvShowDetail, tvShowId: Int) { | ||
presenter.onSuccessGetTvShowDetail() | ||
} | ||
|
||
} |
13 changes: 12 additions & 1 deletion
13
...rc/main/java/com/example/isabelcosta/moviesapp/data/source/remote/service/TvAPIService.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,15 +1,26 @@ | ||
package com.example.isabelcosta.moviesapp.data.source.remote.service | ||
|
||
import com.example.isabelcosta.moviesapp.data.models.MostPopularShowsListResponseData | ||
import retrofit2.Call | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
interface TvAPIService { | ||
|
||
companion object { | ||
|
||
// Endpoint parts | ||
const val TV = "tv" | ||
const val POPULAR = "popular" | ||
|
||
// Path parameters | ||
const val TV_ID = "{tv_id}" | ||
const val TV_ID = "tv_id" | ||
|
||
// Query string | ||
const val API_KEY = "api_key" | ||
} | ||
|
||
@GET("$TV/$POPULAR") | ||
fun getPopularTvShows(@Query(API_KEY) apiKey: String): Call<MostPopularShowsListResponseData> | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/example/isabelcosta/moviesapp/presenters/MostPopularShowsPresenter.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,24 @@ | ||
package com.example.isabelcosta.moviesapp.presenters | ||
|
||
import com.example.isabelcosta.moviesapp.data.models.MostPopularShowsListResponseData | ||
import com.example.isabelcosta.moviesapp.data.source.ITvDataSource | ||
import com.example.isabelcosta.moviesapp.data.source.remote.TvRemoteDataSource | ||
import com.example.isabelcosta.moviesapp.ui.callbacks.IMostPopularShowsUiCallback | ||
|
||
class MostPopularShowsPresenter(private val uiCallback: IMostPopularShowsUiCallback) | ||
: ITvDataSource.GetMostPopularShows { | ||
|
||
private val remoteDataSource = TvRemoteDataSource() | ||
|
||
fun getMostPopularShows() { | ||
remoteDataSource.getMostPopularShows(this) | ||
} | ||
|
||
override fun onSuccessGetMostPopularShows(tvShows: MostPopularShowsListResponseData) { | ||
uiCallback.onShowMostPopularShows(tvShows) | ||
} | ||
|
||
override fun onFailGetMostPopularShows() { | ||
uiCallback.onFetchFailMostPopularShows() | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
...c/main/java/com/example/isabelcosta/moviesapp/ui/callbacks/IMostPopularShowsUiCallback.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,9 @@ | ||
package com.example.isabelcosta.moviesapp.ui.callbacks | ||
|
||
import com.example.isabelcosta.moviesapp.data.models.MostPopularShowsListResponseData | ||
|
||
interface IMostPopularShowsUiCallback { | ||
|
||
fun onShowMostPopularShows(tvShows: MostPopularShowsListResponseData) | ||
fun onFetchFailMostPopularShows() | ||
} |
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
Oops, something went wrong.