Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/tmdb api implementation #60

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Yasir896
Copy link
Collaborator

TMDB database API implementation to get Now Playing Movies.

@Yasir896 Yasir896 requested a review from UmairKhalid786 June 12, 2023 17:42
Copy link
Owner

@UmairKhalid786 UmairKhalid786 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good effort @Yasir896 but please make sure the data flow and right layer should do correct job ✨

@@ -82,4 +88,18 @@ dependencies {
kapt(libs.hilt.compiler)
// Hilt navigation
implementation(libs.androidx.hilt.navigation.compose)

//Retrofit
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will use ktor for network

import java.io.IOException
import javax.inject.Inject

class NowPlayingMovieSource @Inject constructor(private val repository: MoviesRepository):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Datasource should not consume the Repository, it's the other way around. Movies repository will consume data source and then usecase will consume the repository

viewmodel -> usecase -> repository -> data source


override suspend fun load(params: LoadParams<Int>): LoadResult<Int, Movie> {
return try {
val nextPage = params.key ?: 1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

val nextPage = params.key ?: 1 val nowPlayingMovies = repository.getNowPlayingMovies(nextPage) LoadResult.Page( data = nowPlayingMovies.searches, prevKey = if (nextPage == 1) null else nextPage - 1, nextKey = if (nowPlayingMovies.searches.isEmpty()) null else nowPlayingMovies.page + 1 )

        This part is business logic and should be moved to usecase

import javax.inject.Inject

@HiltViewModel
class MoviesViewModel @Inject constructor(private val useCase: MoviesUseCase): ViewModel() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please correct formating and spacing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants