Skip to content

Commit

Permalink
Update project
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbel committed Mar 4, 2024
1 parent 4eb678d commit 63fb6a1
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ interface SettingsInteractor {

val isReviewFeatureEnabled: Boolean

val isUpdateFeatureEnabled: Boolean

val currentTheme: Flow<AppTheme>

val currentFeedView: Flow<FeedView>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ internal class SettingsInteractorImpl @Inject constructor(
appService: AppService
): SettingsInteractor {

override val isReviewFeatureEnabled: Boolean
get() = settingsRepository.isReviewFeatureEnabled
override val isReviewFeatureEnabled: Boolean = settingsRepository.isReviewFeatureEnabled

override val isUpdateFeatureEnabled: Boolean = settingsRepository.isUpdateFeatureEnabled

override val currentTheme: Flow<AppTheme> = settingsRepository.currentTheme

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ interface SettingsRepository {

val isReviewFeatureEnabled: Boolean

val isUpdateFeatureEnabled: Boolean

val currentTheme: Flow<AppTheme>

val currentFeedView: Flow<FeedView>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ internal class SettingsRepositoryImpl @Inject constructor(
): SettingsRepository {

override val isReviewFeatureEnabled: Boolean
get() = BuildConfig.BUILD_TYPE == "Release" && appService.flavor == Flavor.Gms
get() = appService.flavor == Flavor.Gms

override val isUpdateFeatureEnabled: Boolean
get() = appService.flavor == Flavor.Gms

override val currentTheme: Flow<AppTheme> = preferences.themeFlow.map { name ->
AppTheme.transform(name ?: AppTheme.FollowSystem.toString())
Expand Down

This file was deleted.

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

import android.app.Activity
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
Expand Down Expand Up @@ -30,15 +29,12 @@ import org.michaelbel.movies.network.connectivity.NetworkStatus
import org.michaelbel.movies.notifications.NotificationClient
import org.michaelbel.movies.persistence.database.entity.AccountDb
import org.michaelbel.movies.persistence.database.entity.MovieDb
import org.michaelbel.movies.platform.update.UpdateListener
import org.michaelbel.movies.platform.update.UpdateService

@HiltViewModel
class FeedViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
private val interactor: Interactor,
private val notificationClient: NotificationClient,
private val updateService: UpdateService,
networkManager: NetworkManager
): BaseViewModel() {

Expand Down Expand Up @@ -81,14 +77,8 @@ class FeedViewModel @Inject constructor(
val notificationsPermissionRequired: StateFlow<Boolean> = _notificationsPermissionRequired.asStateFlow()

var isAuthFailureSnackbarShowed: Boolean by mutableStateOf(false)
var updateAvailableMessage: Boolean by mutableStateOf(false)

init {
updateService.setUpdateAvailableListener(object: UpdateListener {
override fun onAvailable(result: Boolean) {
updateAvailableMessage = result
}
})
authorizeAccount(requestToken, approved)
subscribeNotificationsPermissionRequired()
}
Expand All @@ -101,10 +91,6 @@ class FeedViewModel @Inject constructor(
}
}

fun startUpdate(activity: Activity) {
updateService.startUpdate(activity)
}

fun onNotificationBottomSheetHide() = launch {
_notificationsPermissionRequired.tryEmit(false)
notificationClient.updateNotificationExpireTime()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.michaelbel.movies.feed.ui

import android.app.Activity
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -25,7 +24,6 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
Expand Down Expand Up @@ -77,7 +75,6 @@ fun FeedRoute(
val currentMovieList by viewModel.currentMovieList.collectAsStateWithLifecycle()
val notificationsPermissionRequired by viewModel.notificationsPermissionRequired.collectAsStateWithLifecycle()
val networkStatus by viewModel.networkStatus.collectAsStateWithLifecycle()
val isUpdateAvailable by rememberUpdatedState(viewModel.updateAvailableMessage)
val isAuthFailureSnackbarShowed = viewModel.isAuthFailureSnackbarShowed

FeedScreenContent(
Expand All @@ -88,13 +85,11 @@ fun FeedRoute(
currentMovieList = currentMovieList,
notificationsPermissionRequired = notificationsPermissionRequired,
isAuthFailureSnackbarShowed = isAuthFailureSnackbarShowed,
isUpdateIconVisible = isUpdateAvailable,
onNavigateToSearch = onNavigateToSearch,
onNavigateToAuth = onNavigateToAuth,
onNavigateToAccount = onNavigateToAccount,
onNavigateToSettings = onNavigateToSettings,
onNavigateToDetails = onNavigateToDetails,
onUpdateIconClick = viewModel::startUpdate,
onNotificationBottomSheetHideClick = viewModel::onNotificationBottomSheetHide,
onSnackbarDismissed = viewModel::onSnackbarDismissed,
modifier = modifier
Expand All @@ -110,13 +105,11 @@ private fun FeedScreenContent(
currentMovieList: MovieList,
notificationsPermissionRequired: Boolean,
isAuthFailureSnackbarShowed: Boolean,
isUpdateIconVisible: Boolean,
onNavigateToSearch: () -> Unit,
onNavigateToAuth: () -> Unit,
onNavigateToAccount: () -> Unit,
onNavigateToSettings: () -> Unit,
onNavigateToDetails: (String, Int) -> Unit,
onUpdateIconClick: (Activity) -> Unit,
onNotificationBottomSheetHideClick: () -> Unit,
onSnackbarDismissed: () -> Unit,
modifier: Modifier = Modifier
Expand Down Expand Up @@ -151,15 +144,9 @@ private fun FeedScreenContent(
}

val onScrollToTop: () -> Unit = {
scope.launch {
lazyListState.animateScrollToItem(0)
}
scope.launch {
lazyGridState.animateScrollToItem(0)
}
scope.launch {
lazyStaggeredGridState.animateScrollToItem(0)
}
scope.launch { lazyListState.animateScrollToItem(0) }
scope.launch { lazyGridState.animateScrollToItem(0) }
scope.launch { lazyStaggeredGridState.animateScrollToItem(0) }
}

val onShowSnackbar: (String, SnackbarDuration) -> Unit = { message, snackbarDuration ->
Expand Down Expand Up @@ -217,7 +204,6 @@ private fun FeedScreenContent(
title = currentMovieList.titleText,
modifier = Modifier.clickableWithoutRipple(onScrollToTop),
account = account,
isUpdateIconVisible = isUpdateIconVisible,
onSearchIconClick = onNavigateToSearch,
onAuthIconClick = {
when {
Expand All @@ -226,7 +212,6 @@ private fun FeedScreenContent(
}
},
onAccountIconClick = onNavigateToAccount,
onUpdateIconClick = { onUpdateIconClick(context as Activity) },
topAppBarScrollBehavior = topAppBarScrollBehavior,
onSettingsIconClick = onNavigateToSettings
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import org.michaelbel.movies.common.theme.AppTheme
import org.michaelbel.movies.feed_impl.R
Expand All @@ -27,23 +26,19 @@ import org.michaelbel.movies.ui.accessibility.MoviesContentDescription
import org.michaelbel.movies.ui.compose.AccountAvatar
import org.michaelbel.movies.ui.compose.iconbutton.SearchIcon
import org.michaelbel.movies.ui.compose.iconbutton.SettingsIcon
import org.michaelbel.movies.ui.compose.iconbutton.UpdateIcon
import org.michaelbel.movies.ui.icons.MoviesIcons
import org.michaelbel.movies.ui.ktx.displayCutoutWindowInsets
import org.michaelbel.movies.ui.ktx.lettersTextFontSizeSmall
import org.michaelbel.movies.ui.preview.DevicePreviews
import org.michaelbel.movies.ui.preview.provider.BooleanPreviewParameterProvider
import org.michaelbel.movies.ui.theme.MoviesTheme

@Composable
fun FeedToolbar(
title: String,
account: AccountDb,
isUpdateIconVisible: Boolean,
onSearchIconClick: () -> Unit,
onAuthIconClick: () -> Unit,
onAccountIconClick: () -> Unit,
onUpdateIconClick: () -> Unit,
onSettingsIconClick: () -> Unit,
topAppBarScrollBehavior: TopAppBarScrollBehavior,
modifier: Modifier = Modifier
Expand All @@ -67,12 +62,6 @@ fun FeedToolbar(
Row(
modifier = Modifier.windowInsetsPadding(displayCutoutWindowInsets)
) {
if (isUpdateIconVisible) {
UpdateIcon(
onClick = onUpdateIconClick
)
}

SettingsIcon(
onClick = onSettingsIconClick
)
Expand Down Expand Up @@ -106,18 +95,14 @@ fun FeedToolbar(

@Composable
@DevicePreviews
private fun FeedToolbarPreview(
@PreviewParameter(BooleanPreviewParameterProvider::class) visible: Boolean
) {
private fun FeedToolbarPreview() {
MoviesTheme {
FeedToolbar(
title = stringResource(R.string.feed_title_now_playing),
account = AccountDb.Empty,
isUpdateIconVisible = visible,
onSearchIconClick = {},
onAccountIconClick = {},
onAuthIconClick = {},
onUpdateIconClick = {},
onSettingsIconClick = {},
topAppBarScrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(),
modifier = Modifier.statusBarsPadding()
Expand All @@ -127,20 +112,16 @@ private fun FeedToolbarPreview(

@Composable
@Preview
private fun FeedToolbarAmoledPreview(
@PreviewParameter(BooleanPreviewParameterProvider::class) visible: Boolean
) {
private fun FeedToolbarAmoledPreview() {
MoviesTheme(
theme = AppTheme.Amoled
) {
FeedToolbar(
title = stringResource(R.string.feed_title_now_playing),
account = AccountDb.Empty,
isUpdateIconVisible = visible,
onSearchIconClick = {},
onAccountIconClick = {},
onAuthIconClick = {},
onUpdateIconClick = {},
onSettingsIconClick = {},
topAppBarScrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(),
modifier = Modifier.statusBarsPadding()
Expand Down
Loading

0 comments on commit 63fb6a1

Please sign in to comment.