Skip to content
8 changes: 4 additions & 4 deletions app/src/main/java/com/london/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalView
Expand All @@ -25,9 +25,9 @@ import com.london.data.worker.MovieListSyncWorker
import com.london.designsystem.theme.NovixTheme
import com.london.domain.service.AppPreferencesService
import com.london.presentation.localization.LocalizationManager
import com.london.presentation.localization.wrapWithLocale
import com.london.presentation.shared.ContentRestrictionProvider
import com.london.presentation.shared.LocalContentRestrictionLevel
import com.london.presentation.shared.contentRestriction.ContentRestrictionProvider
import com.london.presentation.shared.contentRestriction.LocalContentRestrictionLevel
import com.london.presentation.utils.wrapWithLocale
import dagger.hilt.android.AndroidEntryPoint
import java.util.Locale
import javax.inject.Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.london.data.remote.model.authentication.SessionResponse
import com.london.data.remote.source.account.AccountRemoteDataSource
import com.london.data.remote.source.authentication.AuthenticationRemoteDataSource
import com.london.data.repository.authentication.AuthenticationRepositoryImpl
import com.london.domain.service.AppPreferencesService
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.every
Expand All @@ -30,14 +31,16 @@ class AuthenticationRepositoryImplTest {
private val authenticationPreferences: AuthenticationPreferences = mockk(relaxed = true)
private val customMovieListLocalDataSource: CustomMovieListLocalDataSource = mockk(relaxed = true)

private val appPreferencesService: AppPreferencesService = mockk(relaxed = true)

@Before
fun setUp() {
repository = AuthenticationRepositoryImpl(
authenticationRemoteDataSource = authRemoteDataSource,
accountRemoteDataSource = accountRemoteDataSource,
authenticationPreferences = authenticationPreferences,
customMovieListLocalDataSource = customMovieListLocalDataSource
customMovieListLocalDataSource = customMovieListLocalDataSource,
appPreferencesService = appPreferencesService,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ data class AccountUiState(
val error: ErrorState? = null,
val userAvatar: String? = null,
val isLoading: Boolean = false,
val isDarkMode: Boolean = false,
val isLightMode: Boolean = false,
val currentLanguage: String = "",
val showUserMenu: Boolean = false,
val currentAppearance: String = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,12 @@ class AccountViewModel @Inject constructor(
override fun onLogoutConfirmed() {
tryToExecute(
block = { authenticationUseCase.logout() },
onStart = {
updateState { copy(isLogoutLoading = true) }
},
onStart = { updateState { copy(isLogoutLoading = true) } },
onSuccess = { isSuccess: Boolean ->
if (isSuccess) {
updateState { copy(isLogoutLoading = false) }
} else {
updateState {
copy(error = ErrorState.RequestFailed("Logout failed"))
}
}
if (isSuccess) updateState { copy(isLogoutLoading = false) }
else updateState { copy(error = ErrorState.RequestFailed("Logout failed")) }
},
onCompleted = {
emitEffect(AccountEffect.LoginNavigation)
}
onCompleted = { emitEffect(AccountEffect.LoginNavigation) }
)
}

Expand All @@ -64,18 +55,13 @@ class AccountViewModel @Inject constructor(
)
}

override fun onWatchingHistoryClick() =
emitEffect(AccountEffect.WatchingHistoryNavigation)


override fun onMyRatingClick() =
emitEffect(AccountEffect.MyRatingNavigation)
override fun onWatchingHistoryClick() = emitEffect(AccountEffect.WatchingHistoryNavigation)

override fun onMyRatingClick() = emitEffect(AccountEffect.MyRatingNavigation)

override fun onContentRestrictionClick() =
updateState { copy(activeBottomSheet = ActiveBottomSheet.ContentRestriction) }


override fun onContentRestrictionSave(level: ContentRestrictionLevel) {
appPreferencesService.setContentRestrictionLevel(level)
updateState {
Expand All @@ -86,48 +72,28 @@ class AccountViewModel @Inject constructor(
}
}

override fun onChangePasswordClick() =
emitEffect(AccountEffect.ChangePasswordNavigation())

override fun onAppearanceClick() =
updateState {
copy(activeBottomSheet = ActiveBottomSheet.Appearance)
}
override fun onChangePasswordClick() = emitEffect(AccountEffect.ChangePasswordNavigation())

override fun onDarkModeSelected() =
updateState {
copy(appTheme = AppTheme.DARK)
}
override fun onAppearanceClick() = setActiveBottomSheet(ActiveBottomSheet.Appearance)
override fun onDarkModeSelected() = setAppTheme(AppTheme.DARK)

override fun onLightModeSelected() =
updateState {
copy(appTheme = AppTheme.LIGHT)
}
override fun onLightModeSelected() = setAppTheme(AppTheme.LIGHT)

override fun onAppearanceModeSave() {
appPreferencesService.setAppTheme(state.value.appTheme)
onBottomSheetDismiss()
}

override fun showAppearanceBottomSheet() =
updateState {
copy(activeBottomSheet = ActiveBottomSheet.Appearance)
}
override fun showAppearanceBottomSheet() = setActiveBottomSheet(ActiveBottomSheet.Appearance)

override fun onLanguageClick() =
updateState {
copy(activeBottomSheet = ActiveBottomSheet.Language)
}
override fun onLanguageClick() = setActiveBottomSheet(ActiveBottomSheet.Language)

override fun onEnglishSelected() =
updateState {
copy(appLanguage = AppLanguage.ENGLISH)
}

override fun onArabicSelected() =
updateState {
copy(appLanguage = AppLanguage.ARABIC)
}
override fun onEnglishSelected() = updateState {
copy(appLanguage = AppLanguage.ENGLISH)
}

override fun onArabicSelected() = updateState { copy(appLanguage = AppLanguage.ARABIC) }

override fun onLanguageSettingsSave() {
appPreferencesService.setAppLanguage(state.value.appLanguage)
Expand All @@ -150,45 +116,32 @@ class AccountViewModel @Inject constructor(
)
}

override fun onLoginClick() =
emitEffect(AccountEffect.LoginNavigation)
override fun onLoginClick() = emitEffect(AccountEffect.LoginNavigation)

private fun initializeAppTheme() {
val isAppDarkMode = appPreferencesService.isAppDarkMode.value
updateState {
copy(appTheme = if (isAppDarkMode) AppTheme.DARK else AppTheme.LIGHT)
}
setAppTheme(if (isAppDarkMode) AppTheme.DARK else AppTheme.LIGHT)
}

private fun initializeAppLanguage() {
updateState {
copy(appLanguage = appPreferencesService.appLanguage.value)
}
}
private fun initializeAppLanguage() =
updateState { copy(appLanguage = appPreferencesService.appLanguage.value) }

private fun observeContentRestrictionLevel() {
appPreferencesService.contentRestrictionLevel
.onEach { level ->
updateState { copy(currentContentRestriction = level) }
}
.onEach { level -> setCurrentContentRestrictionLevel(level) }
.launchIn(viewModelScope)
}

private fun setCurrentContentRestrictionLevel(level: ContentRestrictionLevel) =
updateState { copy(currentContentRestriction = level) }

private fun checkUserLoginStatus() {
tryToExecute(
block = { authenticationUseCase.isLoggedIn() },
onStart = {
updateState { copy(isLoading = true) }
},
onSuccess = { isLoggedIn: Boolean ->
updateState { copy(isUserLoggedIn = isLoggedIn) }
},
onError = {
updateState { copy(isUserLoggedIn = false) }
},
onCompleted = {
updateState { copy(isLoading = false) }
}
onStart = { updateState { copy(isLoading = true) } },
onSuccess = { isLoggedIn: Boolean -> updateState { copy(isUserLoggedIn = isLoggedIn) } },
onError = { updateState { copy(isUserLoggedIn = false) } },
onCompleted = { updateState { copy(isLoading = false) } }
)
}

Expand All @@ -206,4 +159,8 @@ class AccountViewModel @Inject constructor(
)
}

private fun setActiveBottomSheet(activeBottomSheet: ActiveBottomSheet) =
updateState { copy(activeBottomSheet = activeBottomSheet) }

private fun setAppTheme(appTheme: AppTheme) = updateState { copy(appTheme = appTheme) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import com.london.designsystem.component.Text
import com.london.designsystem.theme.NovixTheme
import com.london.domain.entity.contentrestriction.ContentRestrictionLevel
import com.london.presentation.R
import com.london.presentation.shared.ImageView
import com.london.presentation.shared.item.ImageView
import com.london.designsystem.R as dsR

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.london.presentation.feature.account.rating
interface MyRatingContract {
fun onBackClick()
fun onRetryClick()
fun onItemClick(id: Int)
fun onMovieClick(id: Int)
fun onTvShowClick(id: Int)
fun onDeleteMovieClick(id: Int)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import com.london.designsystem.theme.ThemePreviews
import com.london.domain.entity.shared.MediaType
import com.london.presentation.R
import com.london.presentation.shared.BackgroundGradient
import com.london.presentation.shared.EmptyGenreLayout
import com.london.presentation.shared.SnackBarAnimation
import com.london.presentation.shared.base.ErrorState
import com.london.presentation.shared.buildscreen.BuildScreen
import com.london.presentation.shared.container.MediaLazyVerticalGrid
import com.london.presentation.shared.layout.EmptyGenreLayout
import com.london.presentation.utils.Listen
import com.london.presentation.utils.detailsTopBar
import com.london.presentation.utils.toLocalizedNumbers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@ class MyRatingViewModel @Inject constructor(
)
}

override fun onItemClick(id: Int) {
tryToExecute(
block = { manageRatingUseCase.getRatedMediaById(id) },
onSuccess = { ratedMedia -> handleRatedMediaNavigation(ratedMedia, id) },
onError = { errorState -> updateState { copy(errorState = errorState) } }
)
}

override fun onRatingCategorySelected(category: RatingCategory) =
updateState { copy(selectedRatingCategory = category) }

Expand Down Expand Up @@ -85,15 +77,4 @@ class MyRatingViewModel @Inject constructor(
)
}
}

private fun handleRatedMediaNavigation(ratedMedia: RatedMedia?, id: Int) {
ratedMedia?.let { rated ->
val effect = when (rated.mediaType) {
MediaType.Movie -> MyRatingEffect.MovieDetailsNavigation(id)
MediaType.TvShow -> MyRatingEffect.TvShowDetailsNavigation(id)
}
emitEffect(effect)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ class RegistrationViewModel @Inject constructor() :
override fun onPageLoaded(url: String?) {
url?.let { currentUrl ->
updateState { copy(currentUrl = currentUrl, isLoading = false) }
if (isRegistrationCompleteUrl(currentUrl)) {
if (isRegistrationCompleteUrl(currentUrl))
emitEffect(RegistrationEffect.RegistrationComplete)
}
}
}

override fun onUrlChanged(url: String) {
updateState { copy(currentUrl = url) }
}
override fun onUrlChanged(url: String) = updateState { copy(currentUrl = url) }


override fun shouldInterceptUrl(url: String): Boolean {
if (!isUrlAllowed(url)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ import com.london.designsystem.theme.ThemePreviews
import com.london.designsystem.utils.string
import com.london.presentation.R
import com.london.presentation.shared.BackgroundGradient
import com.london.presentation.shared.CategoriesItem
import com.london.presentation.shared.MediaCategory
import com.london.presentation.shared.genre.MovieGenreUi
import com.london.presentation.shared.genre.TvShowGenreUi
import com.london.presentation.shared.item.CategoriesItem
import com.london.presentation.utils.Listen
import com.london.presentation.utils.gridColumns
import com.london.presentation.utils.navBarBottomPadding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.london.presentation.shared.genre.MovieGenreUi
import com.london.presentation.shared.genre.TvShowGenreUi

data class CategoriesUiState(

val selectedCategory: MediaCategory = MediaCategory.Movies,
val movieGenres: List<MovieGenreUi> = MovieGenreUi.getListWithoutAll(),
val tvShowGenres: List<TvShowGenreUi> = TvShowGenreUi.getListWithoutAll(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ class CategoriesViewModel : BaseViewModel<CategoriesUiState, CategoriesEffect>(C
if (category == state.value.selectedCategory) return
updateState { copy(selectedCategory = category) }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ package com.london.presentation.feature.category.tvshow

interface TvShowCategoryContract {
fun onBackClick()
fun onSavedClick(tvShowId: Int)
fun onTvShowClick(tvShowId: Int)
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ private fun Preview() {
Content(
state = TvShowCategoryUiState(),
contract = object : TvShowCategoryContract {
override fun onSavedClick(tvShowId: Int) {}
override fun onTvShowClick(tvShowId: Int) {}
override fun onBackClick() {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class TvShowCategoryViewModel @Inject constructor(
override fun onBackClick() =
emitEffect(TvShowCategoryEffect.BackNavigation)

override fun onSavedClick(tvShowId: Int) = Unit //TODO("Save Tv Show Not yet implemented")

private fun initializeTvShows(genreUi: TvShowGenreUi) {
tryToExecute(
onStart = { onInitializeTvShowsStarted(genreUi = genreUi) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ import com.london.designsystem.theme.NovixTheme
import com.london.domain.entity.actor.ActorMediaItems
import com.london.presentation.R
import com.london.presentation.shared.BackgroundGradient
import com.london.presentation.shared.ConditionalText
import com.london.presentation.shared.CustomBackDropImagePager
import com.london.presentation.shared.HomeCard
import com.london.presentation.shared.ImageView
import com.london.presentation.shared.TextWithIcon
import com.london.presentation.shared.bookmarkSheet.BookmarkBottomSheet
import com.london.presentation.shared.buildscreen.BuildScreen
import com.london.presentation.shared.item.ImageView
import com.london.presentation.shared.text.ConditionalText
import com.london.presentation.shared.text.TextWithIcon
import com.london.presentation.utils.Listen
import com.london.presentation.utils.detailsTopBar
import com.london.presentation.utils.offsetLayout
Expand Down
Loading
Loading