Skip to content

Commit bb26759

Browse files
committed
Update project
1 parent a999507 commit bb26759

File tree

10 files changed

+71
-29
lines changed

10 files changed

+71
-29
lines changed

core/domain/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ android {
2424

2525
kotlinOptions {
2626
freeCompilerArgs = freeCompilerArgs + listOf(
27+
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
2728
"-opt-in=androidx.paging.ExperimentalPagingApi"
2829
)
2930
}

core/persistence/src/main/kotlin/org/michaelbel/movies/persistence/database/AppDatabase.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import org.michaelbel.movies.persistence.database.entity.MovieDb
1515
import org.michaelbel.movies.persistence.database.entity.PagingKeyDb
1616

1717
/**
18-
* The Room database for this app
18+
* The Room database for this app.
1919
*/
2020
@Database(
2121
entities = [
@@ -35,7 +35,7 @@ internal abstract class AppDatabase: RoomDatabase() {
3535

3636
companion object {
3737
private val DATABASE_NAME: String = if (BuildConfig.DEBUG) "movies-db-debug" else "movies-db"
38-
const val DATABASE_VERSION = 14
38+
const val DATABASE_VERSION = 15
3939

4040
@Volatile
4141
private var instance: AppDatabase? = null

core/persistence/src/main/kotlin/org/michaelbel/movies/persistence/database/entity/MovieDb.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ package org.michaelbel.movies.persistence.database.entity
22

33
import androidx.room.ColumnInfo
44
import androidx.room.Entity
5-
import androidx.room.PrimaryKey
65
import org.jetbrains.annotations.NotNull
76

8-
@Entity(tableName = "movies")
7+
@Entity(tableName = "movies", primaryKeys = ["movieList", "id"])
98
data class MovieDb(
109
@NotNull val movieList: String,
1110
@NotNull val dateAdded: Long,
1211
@NotNull val position: Int,
13-
@NotNull @PrimaryKey @ColumnInfo(name = "id") val movieId: Int,
12+
@NotNull @ColumnInfo(name = "id") val movieId: Int,
1413
@NotNull val overview: String,
1514
@NotNull val posterPath: String,
1615
@NotNull val backdropPath: String,

feature/feed-impl/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ android {
2525

2626
kotlinOptions {
2727
freeCompilerArgs = freeCompilerArgs + listOf(
28+
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
2829
"-opt-in=androidx.compose.material3.ExperimentalMaterial3Api",
2930
"-opt-in=androidx.paging.ExperimentalPagingApi"
3031
)

feature/feed-impl/src/main/kotlin/org/michaelbel/movies/feed/FeedViewModel.kt

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ import kotlinx.coroutines.flow.SharingStarted
1414
import kotlinx.coroutines.flow.StateFlow
1515
import kotlinx.coroutines.flow.asStateFlow
1616
import kotlinx.coroutines.flow.first
17+
import kotlinx.coroutines.flow.flatMapLatest
1718
import kotlinx.coroutines.flow.stateIn
1819
import kotlinx.coroutines.launch
1920
import kotlinx.coroutines.runBlocking
2021
import org.michaelbel.movies.common.appearance.FeedView
2122
import org.michaelbel.movies.common.inappupdate.di.InAppUpdate
23+
import org.michaelbel.movies.common.list.MovieList
2224
import org.michaelbel.movies.common.viewmodel.BaseViewModel
2325
import org.michaelbel.movies.domain.mediator.MoviesRemoteMediator
24-
import org.michaelbel.movies.entities.isTmdbApiKeyEmpty
26+
import org.michaelbel.movies.feed.ktx.nameOrLocalList
2527
import org.michaelbel.movies.interactor.Interactor
2628
import org.michaelbel.movies.network.connectivity.NetworkManager
2729
import org.michaelbel.movies.network.connectivity.NetworkStatus
@@ -39,26 +41,6 @@ class FeedViewModel @Inject constructor(
3941
inAppUpdate: InAppUpdate
4042
): BaseViewModel() {
4143

42-
private val moviesList: String
43-
get() = if (isTmdbApiKeyEmpty) MovieDb.MOVIES_LOCAL_LIST else MovieResponse.NOW_PLAYING
44-
45-
val pagingItems: Flow<PagingData<MovieDb>> = Pager(
46-
config = PagingConfig(
47-
pageSize = MovieResponse.DEFAULT_PAGE_SIZE
48-
),
49-
remoteMediator = MoviesRemoteMediator(
50-
interactor = interactor,
51-
movieList = MovieResponse.NOW_PLAYING
52-
),
53-
pagingSourceFactory = { interactor.moviesPagingSource(moviesList) }
54-
).flow
55-
.stateIn(
56-
scope = this,
57-
started = SharingStarted.Lazily,
58-
initialValue = PagingData.empty()
59-
)
60-
.cachedIn(this)
61-
6244
val account: StateFlow<AccountDb?> = interactor.account
6345
.stateIn(
6446
scope = this,
@@ -87,6 +69,32 @@ class FeedViewModel @Inject constructor(
8769
initialValue = runBlocking { interactor.currentFeedView.first() }
8870
)
8971

72+
val currentMovieList: StateFlow<MovieList> = interactor.currentMovieList
73+
.stateIn(
74+
scope = this,
75+
started = SharingStarted.Lazily,
76+
initialValue = runBlocking { interactor.currentMovieList.first() }
77+
)
78+
79+
val pagingItems: Flow<PagingData<MovieDb>> = currentMovieList.flatMapLatest { movieList ->
80+
Pager(
81+
config = PagingConfig(
82+
pageSize = MovieResponse.DEFAULT_PAGE_SIZE
83+
),
84+
remoteMediator = MoviesRemoteMediator(
85+
interactor = interactor,
86+
movieList = movieList.name
87+
),
88+
pagingSourceFactory = { interactor.moviesPagingSource(movieList.nameOrLocalList) }
89+
).flow
90+
.stateIn(
91+
scope = this,
92+
started = SharingStarted.Lazily,
93+
initialValue = PagingData.empty()
94+
)
95+
.cachedIn(this)
96+
}
97+
9098
private var _notificationsPermissionRequired: MutableStateFlow<Boolean> = MutableStateFlow(false)
9199
val notificationsPermissionRequired: StateFlow<Boolean> = _notificationsPermissionRequired.asStateFlow()
92100

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.michaelbel.movies.feed.ktx
2+
3+
import androidx.compose.runtime.Composable
4+
import androidx.compose.ui.res.stringResource
5+
import org.michaelbel.movies.common.list.MovieList
6+
import org.michaelbel.movies.entities.isTmdbApiKeyEmpty
7+
import org.michaelbel.movies.feed_impl.R
8+
import org.michaelbel.movies.persistence.database.entity.MovieDb
9+
10+
internal val MovieList.nameOrLocalList: String
11+
get() = if (isTmdbApiKeyEmpty) MovieDb.MOVIES_LOCAL_LIST else name
12+
13+
internal val MovieList.titleText: String
14+
@Composable get() = when (this) {
15+
is MovieList.NowPlaying -> stringResource(R.string.feed_title_now_playing)
16+
is MovieList.Popular -> stringResource(R.string.feed_title_popular)
17+
is MovieList.TopRated -> stringResource(R.string.feed_title_top_rated)
18+
is MovieList.Upcoming -> stringResource(R.string.feed_title_upcoming)
19+
}

feature/feed-impl/src/main/kotlin/org/michaelbel/movies/feed/ui/FeedScreenContent.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ import kotlinx.coroutines.CoroutineScope
4343
import kotlinx.coroutines.launch
4444
import org.michaelbel.movies.common.appearance.FeedView
4545
import org.michaelbel.movies.common.exceptions.ApiKeyNotNullException
46+
import org.michaelbel.movies.common.list.MovieList
4647
import org.michaelbel.movies.entities.isTmdbApiKeyEmpty
4748
import org.michaelbel.movies.feed.FeedViewModel
49+
import org.michaelbel.movies.feed.ktx.titleText
4850
import org.michaelbel.movies.feed_impl.R
4951
import org.michaelbel.movies.network.connectivity.NetworkStatus
5052
import org.michaelbel.movies.persistence.database.entity.AccountDb
@@ -70,6 +72,7 @@ fun FeedRoute(
7072
val pagingItems: LazyPagingItems<MovieDb> = viewModel.pagingItems.collectAsLazyPagingItems()
7173
val account: AccountDb? by viewModel.account.collectAsStateWithLifecycle()
7274
val currentFeedView: FeedView by viewModel.currentFeedView.collectAsStateWithLifecycle()
75+
val currentMovieList: MovieList by viewModel.currentMovieList.collectAsStateWithLifecycle()
7376
val notificationsPermissionRequired: Boolean by viewModel.notificationsPermissionRequired.collectAsStateWithLifecycle()
7477
val networkStatus: NetworkStatus by viewModel.networkStatus.collectAsStateWithLifecycle()
7578
val isUpdateAvailable: Boolean by rememberUpdatedState(viewModel.updateAvailableMessage)
@@ -79,6 +82,7 @@ fun FeedRoute(
7982
account = account.orEmpty,
8083
networkStatus = networkStatus,
8184
currentFeedView = currentFeedView,
85+
currentMovieList = currentMovieList,
8286
notificationsPermissionRequired = notificationsPermissionRequired,
8387
isUpdateIconVisible = isUpdateAvailable,
8488
onNavigateToAuth = onNavigateToAuth,
@@ -97,6 +101,7 @@ private fun FeedScreenContent(
97101
account: AccountDb,
98102
networkStatus: NetworkStatus,
99103
currentFeedView: FeedView,
104+
currentMovieList: MovieList,
100105
notificationsPermissionRequired: Boolean,
101106
isUpdateIconVisible: Boolean,
102107
onNavigateToAuth: () -> Unit,
@@ -191,6 +196,7 @@ private fun FeedScreenContent(
191196
.nestedScroll(topAppBarScrollBehavior.nestedScrollConnection),
192197
topBar = {
193198
FeedToolbar(
199+
title = currentMovieList.titleText,
194200
modifier = Modifier
195201
.fillMaxWidth()
196202
.clickableWithoutRipple { onScrollToTop() },

feature/feed-impl/src/main/kotlin/org/michaelbel/movies/feed/ui/FeedToolbar.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import org.michaelbel.movies.ui.theme.MoviesTheme
2828

2929
@Composable
3030
fun FeedToolbar(
31+
title: String,
3132
account: AccountDb,
3233
isUpdateIconVisible: Boolean,
3334
onAuthIconClick: () -> Unit,
@@ -40,7 +41,7 @@ fun FeedToolbar(
4041
TopAppBar(
4142
title = {
4243
Text(
43-
text = stringResource(R.string.feed_title),
44+
text = title,
4445
overflow = TextOverflow.Ellipsis,
4546
maxLines = 1,
4647
style = MaterialTheme.typography.titleLarge.copy(
@@ -105,6 +106,7 @@ private fun FeedToolbarPreview(
105106
) {
106107
MoviesTheme {
107108
FeedToolbar(
109+
title = stringResource(R.string.feed_title_now_playing),
108110
account = AccountDb.Empty,
109111
isUpdateIconVisible = visible,
110112
onAccountIconClick = {},

feature/feed-impl/src/main/res/values-ru/strings.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<string name="feed_title">Популярные фильмы</string>
3+
<string name="feed_title_now_playing">Фильмы премьеры</string>
4+
<string name="feed_title_popular">Популярные фильмы</string>
5+
<string name="feed_title_top_rated">Топ фильмов</string>
6+
<string name="feed_title_upcoming">Предстоящие фильмы</string>
47
<string name="feed_retry">Повторить</string>
58
<string name="feed_error_loading">При загрузке фильмов произошла ошибка</string>
69
<string name="feed_error_check_internet_connectivity">Проверить подключение к интернету</string>

feature/feed-impl/src/main/res/values/strings.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<string name="feed_title">Popular Movies</string>
3+
<string name="feed_title_now_playing">Now Playing Movies</string>
4+
<string name="feed_title_popular">Popular Movies</string>
5+
<string name="feed_title_top_rated">Top Rated Movies</string>
6+
<string name="feed_title_upcoming">Upcoming Movies</string>
47
<string name="feed_retry">Retry</string>
58
<string name="feed_error_loading">Error while loading movies</string>
69
<string name="feed_error_check_internet_connectivity">Check Internet Connectivity</string>

0 commit comments

Comments
 (0)