-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ecc3ea5
commit f1f2094
Showing
34 changed files
with
817 additions
and
114 deletions.
There are no files selected for viewing
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
11 changes: 11 additions & 0 deletions
11
core/interactor/src/main/kotlin/org/michaelbel/movies/interactor/SuggestionInteractor.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,11 @@ | ||
package org.michaelbel.movies.interactor | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import org.michaelbel.movies.persistence.database.entity.SuggestionDb | ||
|
||
interface SuggestionInteractor { | ||
|
||
fun suggestions(): Flow<List<SuggestionDb>> | ||
|
||
suspend fun updateSuggestions() | ||
} |
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
27 changes: 27 additions & 0 deletions
27
...eractor/src/main/kotlin/org/michaelbel/movies/interactor/impl/SuggestionInteractorImpl.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,27 @@ | ||
package org.michaelbel.movies.interactor.impl | ||
|
||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.withContext | ||
import org.michaelbel.movies.common.dispatchers.MoviesDispatchers | ||
import org.michaelbel.movies.interactor.SuggestionInteractor | ||
import org.michaelbel.movies.persistence.database.entity.SuggestionDb | ||
import org.michaelbel.movies.repository.SuggestionRepository | ||
|
||
@Singleton | ||
internal class SuggestionInteractorImpl @Inject constructor( | ||
private val dispatchers: MoviesDispatchers, | ||
private val suggestionRepository: SuggestionRepository | ||
): SuggestionInteractor { | ||
|
||
override fun suggestions(): Flow<List<SuggestionDb>> { | ||
return suggestionRepository.suggestions() | ||
} | ||
|
||
override suspend fun updateSuggestions() { | ||
withContext(dispatchers.io) { | ||
suggestionRepository.updateSuggestions() | ||
} | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
...rsistence/src/main/kotlin/org/michaelbel/movies/persistence/database/dao/SuggestionDao.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 org.michaelbel.movies.persistence.database.dao | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import kotlinx.coroutines.flow.Flow | ||
import org.michaelbel.movies.persistence.database.entity.SuggestionDb | ||
|
||
/** | ||
* The Data Access Object for the [SuggestionDb] class. | ||
*/ | ||
@Dao | ||
interface SuggestionDao { | ||
|
||
@Query("SELECT * FROM suggestions") | ||
fun suggestionsFlow(): Flow<List<SuggestionDb>> | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun insert(suggestions: List<SuggestionDb>) | ||
|
||
@Query("DELETE FROM suggestions") | ||
suspend fun removeAll() | ||
} |
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
9 changes: 9 additions & 0 deletions
9
...istence/src/main/kotlin/org/michaelbel/movies/persistence/database/entity/SuggestionDb.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 org.michaelbel.movies.persistence.database.entity | ||
|
||
import androidx.room.Entity | ||
import org.jetbrains.annotations.NotNull | ||
|
||
@Entity(tableName = "suggestions", primaryKeys = ["title"]) | ||
data class SuggestionDb( | ||
@NotNull val title: String | ||
) |
7 changes: 5 additions & 2 deletions
7
.../persistence/src/main/kotlin/org/michaelbel/movies/persistence/database/ktx/MovieDbKtx.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,11 +1,14 @@ | ||
package org.michaelbel.movies.persistence.database.ktx | ||
|
||
import java.util.Locale | ||
import org.michaelbel.movies.network.TMDB_MOVIE_URL | ||
import org.michaelbel.movies.persistence.database.entity.MovieDb | ||
import java.util.Locale | ||
|
||
val MovieDb.isNotEmpty: Boolean | ||
get() = this != MovieDb.Empty | ||
|
||
val MovieDb.url: String | ||
get() = String.format(Locale.US, TMDB_MOVIE_URL, movieId) | ||
get() = String.format(Locale.US, TMDB_MOVIE_URL, movieId) | ||
|
||
val MovieDb?.orEmpty: MovieDb | ||
get() = this ?: MovieDb.Empty |
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
11 changes: 11 additions & 0 deletions
11
core/repository/src/main/kotlin/org/michaelbel/movies/repository/SuggestionRepository.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,11 @@ | ||
package org.michaelbel.movies.repository | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import org.michaelbel.movies.persistence.database.entity.SuggestionDb | ||
|
||
interface SuggestionRepository { | ||
|
||
fun suggestions(): Flow<List<SuggestionDb>> | ||
|
||
suspend fun updateSuggestions() | ||
} |
Oops, something went wrong.