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

Search screen #196

Merged
merged 2 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ dependencies {
implementation(project(":feature:details"))
implementation(project(":feature:feed"))
implementation(project(":feature:gallery"))
implementation(project(":feature:search"))
implementation(project(":feature:settings"))

testImplementation(libs.junit)
Expand Down
14 changes: 13 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,19 @@

<data
android:host="settings"
android:scheme="shortcut" />
android:scheme="movies_shortcut" />

</intent-filter>

<intent-filter
android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="search"
android:scheme="movies_shortcut" />

</intent-filter>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import org.michaelbel.movies.feed.feedGraph
import org.michaelbel.movies.gallery.galleryGraph
import org.michaelbel.movies.gallery.navigateToGallery
import org.michaelbel.movies.navigation.ktx.addOnDestinationChangedListener
import org.michaelbel.movies.search.navigateToSearch
import org.michaelbel.movies.search.searchGraph
import org.michaelbel.movies.settings.navigateToSettings
import org.michaelbel.movies.settings.settingsGraph
import org.michaelbel.movies.ui.theme.MoviesTheme
Expand Down Expand Up @@ -49,6 +51,7 @@ internal fun MainActivityContent(
navigateBack = navHostController::popBackStack
)
feedGraph(
navigateToSearch = navHostController::navigateToSearch,
navigateToAuth = navHostController::navigateToAuth,
navigateToAccount = navHostController::navigateToAccount,
navigateToSettings = navHostController::navigateToSettings,
Expand All @@ -62,6 +65,10 @@ internal fun MainActivityContent(
galleryGraph(
navigateBack = navHostController::popBackStack
)
searchGraph(
navigateBack = navHostController::popBackStack,
navigateToDetails = navHostController::navigateToDetails,
)
settingsGraph(
navigateBack = navHostController::popBackStack
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package org.michaelbel.movies.common.exceptions

data object FeedEmptyException: Exception()
data object PageEmptyException: Exception()
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ class Interactor @Inject constructor(
movieInteractor: MovieInteractor,
notificationInteractor: NotificationInteractor,
pagingKeyInteractor: PagingKeyInteractor,
searchInteractor: SearchInteractor,
settingsInteractor: SettingsInteractor
): AccountInteractor by accountInteractor,
AuthenticationInteractor by authenticationInteractor,
ImageInteractor by imageInteractor,
MovieInteractor by movieInteractor,
NotificationInteractor by notificationInteractor,
PagingKeyInteractor by pagingKeyInteractor,
SearchInteractor by searchInteractor,
SettingsInteractor by settingsInteractor
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import org.michaelbel.movies.persistence.database.entity.MovieDb

interface MovieInteractor {

fun moviesPagingSource(movieList: String): PagingSource<Int, MovieDb>
fun moviesPagingSource(pagingKey: String): PagingSource<Int, MovieDb>

suspend fun moviesResult(movieList: String, page: Int): Result<MovieResponse>

suspend fun movieDetails(movieId: Int): Either<MovieDb>

suspend fun removeAllMovies(movieList: String)
suspend fun removeAllMovies(pagingKey: String)

suspend fun insertAllMovies(movieList: String, movies: List<MovieResponse>)
suspend fun insertAllMovies(pagingKey: String, movies: List<MovieResponse>)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.michaelbel.movies.interactor

import org.michaelbel.movies.network.model.MovieResponse
import org.michaelbel.movies.network.model.Result

interface SearchInteractor {

suspend fun searchMoviesResult(query: String, page: Int): Result<MovieResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import org.michaelbel.movies.interactor.ImageInteractor
import org.michaelbel.movies.interactor.MovieInteractor
import org.michaelbel.movies.interactor.NotificationInteractor
import org.michaelbel.movies.interactor.PagingKeyInteractor
import org.michaelbel.movies.interactor.SearchInteractor
import org.michaelbel.movies.interactor.SettingsInteractor
import org.michaelbel.movies.interactor.impl.AccountInteractorImpl
import org.michaelbel.movies.interactor.impl.AuthenticationInteractorImpl
import org.michaelbel.movies.interactor.impl.ImageInteractorImpl
import org.michaelbel.movies.interactor.impl.MovieInteractorImpl
import org.michaelbel.movies.interactor.impl.NotificationInteractorImpl
import org.michaelbel.movies.interactor.impl.PagingKeyInteractorImpl
import org.michaelbel.movies.interactor.impl.SearchInteractorImpl
import org.michaelbel.movies.interactor.impl.SettingsInteractorImpl

@Module
Expand Down Expand Up @@ -60,6 +62,12 @@ internal interface InteractorModule {
interactor: PagingKeyInteractorImpl
): PagingKeyInteractor

@Binds
@Singleton
fun provideSearchInteractor(
interactor: SearchInteractorImpl
): SearchInteractor

@Binds
@Singleton
fun provideSettingsInteractor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ internal class MovieInteractorImpl @Inject constructor(
private val movieRepository: MovieRepository
): MovieInteractor {

override fun moviesPagingSource(movieList: String): PagingSource<Int, MovieDb> {
return movieRepository.moviesPagingSource(movieList)
override fun moviesPagingSource(pagingKey: String): PagingSource<Int, MovieDb> {
return movieRepository.moviesPagingSource(pagingKey)
}

override suspend fun moviesResult(movieList: String, page: Int): Result<MovieResponse> {
Expand All @@ -34,15 +34,15 @@ internal class MovieInteractorImpl @Inject constructor(
}
}

override suspend fun removeAllMovies(movieList: String) {
override suspend fun removeAllMovies(pagingKey: String) {
return withContext(dispatchers.io) {
movieRepository.removeAllMovies(movieList)
movieRepository.removeAllMovies(pagingKey)
}
}

override suspend fun insertAllMovies(movieList: String, movies: List<MovieResponse>) {
override suspend fun insertAllMovies(pagingKey: String, movies: List<MovieResponse>) {
return withContext(dispatchers.io) {
movieRepository.insertAllMovies(movieList, movies)
movieRepository.insertAllMovies(pagingKey, movies)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.michaelbel.movies.interactor.impl

import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.withContext
import org.michaelbel.movies.common.dispatchers.MoviesDispatchers
import org.michaelbel.movies.interactor.SearchInteractor
import org.michaelbel.movies.network.model.MovieResponse
import org.michaelbel.movies.network.model.Result
import org.michaelbel.movies.repository.SearchRepository

@Singleton
internal class SearchInteractorImpl @Inject constructor(
private val dispatchers: MoviesDispatchers,
private val searchRepository: SearchRepository
): SearchInteractor {

override suspend fun searchMoviesResult(query: String, page: Int): Result<MovieResponse> {
return withContext(dispatchers.io) {
searchRepository.searchMoviesResult(query, page)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
import org.michaelbel.movies.network.service.account.AccountService
import org.michaelbel.movies.network.service.authentication.AuthenticationService
import org.michaelbel.movies.network.service.image.ImageService
import org.michaelbel.movies.network.service.ktx.createService
import org.michaelbel.movies.network.service.movie.MovieService
import org.michaelbel.movies.network.service.search.SearchService
import retrofit2.Retrofit

@Module
Expand All @@ -18,25 +18,25 @@ internal object ServiceModule {

@Provides
@Singleton
fun provideMovieService(
fun provideAuthenticationService(
retrofit: Retrofit
): MovieService = retrofit.createService()
): AuthenticationService = retrofit.createService()

@Provides
@Singleton
fun provideImageService(
fun provideAccountService(
retrofit: Retrofit
): ImageService = retrofit.createService()
): AccountService = retrofit.createService()

@Provides
@Singleton
fun provideAuthenticationService(
fun provideMovieService(
retrofit: Retrofit
): AuthenticationService = retrofit.createService()
): MovieService = retrofit.createService()

@Provides
@Singleton
fun provideAccountService(
fun provideSearchService(
retrofit: Retrofit
): AccountService = retrofit.createService()
): SearchService = retrofit.createService()
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.michaelbel.movies.network.service.movie

import org.michaelbel.movies.network.model.ImagesResponse
import org.michaelbel.movies.network.model.Movie
import org.michaelbel.movies.network.model.MovieResponse
import org.michaelbel.movies.network.model.Result
Expand All @@ -21,4 +22,9 @@ interface MovieService {
@Path("movie_id") id: Int,
@Query("language") language: String
): Movie

@GET("movie/{movie_id}/images")
suspend fun images(
@Path("movie_id") id: Int
): ImagesResponse
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.michaelbel.movies.network.service.search

import org.michaelbel.movies.network.model.MovieResponse
import org.michaelbel.movies.network.model.Result
import retrofit2.http.GET
import retrofit2.http.Query

interface SearchService {

@GET("search/movie")
suspend fun searchMovies(
@Query("query") query: String,
@Query("language") language: String,
@Query("page") page: Int
): Result<MovieResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import org.michaelbel.movies.persistence.database.entity.MovieDb

interface MovieRepository {

fun moviesPagingSource(movieList: String): PagingSource<Int, MovieDb>
fun moviesPagingSource(pagingKey: String): PagingSource<Int, MovieDb>

suspend fun moviesResult(movieList: String, page: Int): Result<MovieResponse>

suspend fun movieDetails(movieId: Int): Either<MovieDb>

suspend fun removeAllMovies(movieList: String)
suspend fun removeAllMovies(pagingKey: String)

suspend fun insertAllMovies(movieList: String, movies: List<MovieResponse>)
suspend fun insertAllMovies(pagingKey: String, movies: List<MovieResponse>)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.michaelbel.movies.repository

import org.michaelbel.movies.network.model.MovieResponse
import org.michaelbel.movies.network.model.Result

interface SearchRepository {

suspend fun searchMoviesResult(query: String, page: Int): Result<MovieResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import org.michaelbel.movies.repository.ImageRepository
import org.michaelbel.movies.repository.MovieRepository
import org.michaelbel.movies.repository.NotificationRepository
import org.michaelbel.movies.repository.PagingKeyRepository
import org.michaelbel.movies.repository.SearchRepository
import org.michaelbel.movies.repository.SettingsRepository
import org.michaelbel.movies.repository.impl.AccountRepositoryImpl
import org.michaelbel.movies.repository.impl.AuthenticationRepositoryImpl
import org.michaelbel.movies.repository.impl.ImageRepositoryImpl
import org.michaelbel.movies.repository.impl.MovieRepositoryImpl
import org.michaelbel.movies.repository.impl.NotificationRepositoryImpl
import org.michaelbel.movies.repository.impl.PagingKeyRepositoryImpl
import org.michaelbel.movies.repository.impl.SearchRepositoryImpl
import org.michaelbel.movies.repository.impl.SettingsRepositoryImpl

@Module
Expand Down Expand Up @@ -60,6 +62,12 @@ internal interface RepositoryModule {
repository: PagingKeyRepositoryImpl
): PagingKeyRepository

@Binds
@Singleton
fun provideSearchRepository(
repository: SearchRepositoryImpl
): SearchRepository

@Binds
@Singleton
fun provideSettingsRepository(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.flow.Flow
import org.michaelbel.movies.network.model.ImagesResponse
import org.michaelbel.movies.network.service.image.ImageService
import org.michaelbel.movies.network.service.movie.MovieService
import org.michaelbel.movies.persistence.database.dao.ImageDao
import org.michaelbel.movies.persistence.database.entity.ImageDb
import org.michaelbel.movies.persistence.database.ktx.imageDb
import org.michaelbel.movies.repository.ImageRepository

@Singleton
internal class ImageRepositoryImpl @Inject constructor(
private val imageService: ImageService,
private val movieService: MovieService,
private val imageDao: ImageDao
): ImageRepository {

Expand All @@ -21,7 +21,7 @@ internal class ImageRepositoryImpl @Inject constructor(
}

override suspend fun images(movieId: Int) {
val imageResponse: ImagesResponse = imageService.images(movieId)
val imageResponse: ImagesResponse = movieService.images(movieId)
val posters: List<ImageDb> = imageResponse.posters.mapIndexed { index, image ->
image.imageDb(
movieId = movieId,
Expand Down
Loading