Skip to content

Instantly share code, notes, and snippets.

@AdamMc331
Created October 9, 2021 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamMc331/955989a52429ab1f812a9ecf94d5b1d3 to your computer and use it in GitHub Desktop.
Save AdamMc331/955989a52429ab1f812a9ecf94d5b1d3 to your computer and use it in GitHub Desktop.
class DramaCategoryFragment : Fragment(R.layout.fragment_drama_category),
MovieListAdapter.FavouriteMovieListener {
// ...
private fun getDramaMovies() {
val movieAPI = MoviesData.defaultInstance()
// ...
val retrofitData =
movieAPI.getMoviesByCategory("39fd0a08c0cc7fd3041fc14605c22358", 18)
// ...
}
// ...
}
interface MoviesData {
@GET("movie/now_playing")
fun getData(@Query("api_key") apiKey: String): Call<MovieResponse>
@GET("search/movie")
fun searchMovies(@Query("api_key") apiKey: String, @Query("query") movieName : String): Call<MovieResponse>
@GET("movie/{movie_id}")
fun getMovieDetails(@Path("movie_id") movieId : Int, @Query("api_key") apiKey: String) : Call<MovieDetails>
@GET("discover/movie")
fun getMoviesByCategory(@Query("api_key") apiKey : String, @Query("with_genres") genreId : Int) : Call<MovieResponse>
companion object {
private const val BASE_URL = "https://api.themoviedb.org/3/"
// Create a default instance here, make sure it's public.
fun defaultInstance(): MovieData {
return = Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(BASE_URL)
.build()
.create(MoviesData::class.java)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment