Skip to content

Commit

Permalink
fix: Address PR comments + crash fix
Browse files Browse the repository at this point in the history
  • Loading branch information
omerhabib26 committed Nov 30, 2023
1 parent 6bb8713 commit 6a42e9c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Logistration : Fragment() {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
OpenEdXTheme {
PreLoginScreen(
LogistrationScreen(
onSignInClick = {
router.navigateToSignIn(parentFragmentManager)
},
Expand All @@ -81,7 +81,7 @@ class Logistration : Fragment() {
}

@Composable
private fun PreLoginScreen(
private fun LogistrationScreen(
onSearchClick: (String) -> Unit,
onRegisterClick: () -> Unit,
onSignInClick: () -> Unit,
Expand Down Expand Up @@ -196,9 +196,9 @@ private fun PreLoginScreen(
@Preview(name = "NEXUS_9_Light", device = Devices.NEXUS_9, uiMode = Configuration.UI_MODE_NIGHT_NO)
@Preview(name = "NEXUS_9_Night", device = Devices.NEXUS_9, uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
private fun SignInScreenPreview() {
private fun LogistrationPreview() {
OpenEdXTheme {
PreLoginScreen(
LogistrationScreen(
onSearchClick = {},
onSignInClick = {},
onRegisterClick = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ import org.openedx.auth.R
import org.openedx.auth.presentation.AuthRouter
import org.openedx.auth.presentation.ui.LoginTextField
import org.openedx.core.AppUpdateState
import org.openedx.core.BuildConfig
import org.openedx.core.UIMessage
import org.openedx.core.presentation.global.WhatsNewGlobalManager
import org.openedx.core.presentation.global.app_upgrade.AppUpgradeRequiredScreen
import org.openedx.core.ui.BackBtn
import org.openedx.core.ui.HandleUIMessage
Expand All @@ -80,7 +80,6 @@ import org.openedx.core.ui.theme.appColors
import org.openedx.core.ui.theme.appShapes
import org.openedx.core.ui.theme.appTypography
import org.openedx.core.ui.windowSizeValue
import org.openedx.core.presentation.global.WhatsNewGlobalManager

class SignInFragment : Fragment() {

Expand All @@ -102,7 +101,7 @@ class SignInFragment : Fragment() {
val uiMessage by viewModel.uiMessage.observeAsState()
val loginSuccess by viewModel.loginSuccess.observeAsState(initial = false)
val appUpgradeEvent by viewModel.appUpgradeEvent.observeAsState(null)
val isLogistrationEnabled = BuildConfig.PRE_LOGIN_EXPERIENCE_ENABLED
val isLogistrationEnabled by viewModel.isLogistrationEnabled.observeAsState(initial = false)

if (appUpgradeEvent == null) {
LoginScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.openedx.auth.R
import org.openedx.auth.domain.interactor.AuthInteractor
import org.openedx.auth.presentation.AuthAnalytics
import org.openedx.core.BaseViewModel
import org.openedx.core.BuildConfig
import org.openedx.core.SingleEventLiveData
import org.openedx.core.UIMessage
import org.openedx.core.Validator
Expand Down Expand Up @@ -44,7 +45,11 @@ class SignInViewModel(
val appUpgradeEvent: LiveData<AppUpgradeEvent>
get() = _appUpgradeEvent

private val _isLogistrationEnabled = MutableLiveData<Boolean>()
val isLogistrationEnabled: LiveData<Boolean> = _isLogistrationEnabled

init {
_isLogistrationEnabled.value = BuildConfig.PRE_LOGIN_EXPERIENCE_ENABLED
collectAppUpgradeEvent()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class DiscoveryScreenTest {
canLoadMore = false,
refreshing = false,
hasInternetConnection = true,
isUserLoggedIn = false,
canShowBackButton = false,
appUpgradeParameters = AppUpdateState.AppUpgradeParameters(),
onSearchClick = {},
onSwipeRefresh = {},
Expand Down Expand Up @@ -94,7 +94,7 @@ class DiscoveryScreenTest {
canLoadMore = false,
refreshing = false,
hasInternetConnection = true,
isUserLoggedIn = false,
canShowBackButton = false,
appUpgradeParameters = AppUpdateState.AppUpgradeParameters(),
onSearchClick = {},
onSwipeRefresh = {},
Expand All @@ -120,7 +120,7 @@ class DiscoveryScreenTest {
canLoadMore = true,
refreshing = false,
hasInternetConnection = true,
isUserLoggedIn = false,
canShowBackButton = false,
appUpgradeParameters = AppUpdateState.AppUpgradeParameters(),
onSearchClick = {},
onSwipeRefresh = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.openedx.core.AppUpdateState
import org.openedx.core.AppUpdateState.wasUpdateDialogClosed
import org.openedx.core.BuildConfig
import org.openedx.core.UIMessage
import org.openedx.core.data.storage.CorePreferences
import org.openedx.core.domain.model.Course
Expand Down Expand Up @@ -67,7 +66,8 @@ class DiscoveryFragment : Fragment() {
val appUpgradeEvent by viewModel.appUpgradeEvent.observeAsState()
val wasUpdateDialogClosed by remember { wasUpdateDialogClosed }
val querySearch = arguments?.getString(ARG_SEARCH_QUERY, "") ?: ""
val isUserLoggedIn = corePreferencesManager.user != null
val isLogistrationEnabled by viewModel.isLogistrationEnabled.observeAsState(false)
val canShowBackButton = isLogistrationEnabled && corePreferencesManager.user == null

DiscoveryScreen(
windowSize = windowSize,
Expand All @@ -76,7 +76,7 @@ class DiscoveryFragment : Fragment() {
canLoadMore = canLoadMore,
refreshing = refreshing,
hasInternetConnection = viewModel.hasInternetConnection,
isUserLoggedIn = isUserLoggedIn,
canShowBackButton = canShowBackButton,
appUpgradeParameters = AppUpdateState.AppUpgradeParameters(
appUpgradeEvent = appUpgradeEvent,
wasUpdateDialogClosed = wasUpdateDialogClosed,
Expand Down Expand Up @@ -157,7 +157,7 @@ internal fun DiscoveryScreen(
canLoadMore: Boolean,
refreshing: Boolean,
hasInternetConnection: Boolean,
isUserLoggedIn: Boolean,
canShowBackButton: Boolean,
appUpgradeParameters: AppUpdateState.AppUpgradeParameters,
onSearchClick: () -> Unit,
onSwipeRefresh: () -> Unit,
Expand Down Expand Up @@ -216,7 +216,7 @@ internal fun DiscoveryScreen(

HandleUIMessage(uiMessage = uiMessage, scaffoldState = scaffoldState)

if (BuildConfig.PRE_LOGIN_EXPERIENCE_ENABLED && isUserLoggedIn.not()) {
if (canShowBackButton) {
Box(
modifier = Modifier
.statusBarsPadding()
Expand Down Expand Up @@ -436,7 +436,7 @@ private fun DiscoveryScreenPreview() {
hasInternetConnection = true,
appUpgradeParameters = AppUpdateState.AppUpgradeParameters(),
onBackClick = {},
isUserLoggedIn = false
canShowBackButton = false
)
}
}
Expand Down Expand Up @@ -472,7 +472,7 @@ private fun DiscoveryScreenTabletPreview() {
hasInternetConnection = true,
appUpgradeParameters = AppUpdateState.AppUpgradeParameters(),
onBackClick = {},
isUserLoggedIn = false
canShowBackButton = false
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.launch
import org.openedx.core.BaseViewModel
import org.openedx.core.BuildConfig
import org.openedx.core.R
import org.openedx.core.SingleEventLiveData
import org.openedx.core.UIMessage
Expand Down Expand Up @@ -46,6 +47,9 @@ class DiscoveryViewModel(
val appUpgradeEvent: LiveData<AppUpgradeEvent>
get() = _appUpgradeEvent

private val _isLogistrationEnabled = MutableLiveData<Boolean>()
val isLogistrationEnabled: LiveData<Boolean> = _isLogistrationEnabled

val hasInternetConnection: Boolean
get() = networkConnection.isOnline()

Expand All @@ -54,6 +58,7 @@ class DiscoveryViewModel(
private var isLoading = false

init {
_isLogistrationEnabled.value = BuildConfig.PRE_LOGIN_EXPERIENCE_ENABLED
getCoursesList()
collectAppUpgradeEvent()
}
Expand Down Expand Up @@ -157,7 +162,7 @@ class DiscoveryViewModel(
.collect { event ->
when (event) {
is AppUpgradeEvent.UpgradeRecommendedEvent -> {
_appUpgradeEvent.value = event
_appUpgradeEvent.value = event
}

is AppUpgradeEvent.UpgradeRequiredEvent -> {
Expand Down

0 comments on commit 6a42e9c

Please sign in to comment.