Skip to content

Commit

Permalink
Fixed dialogs bugs, minor code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
PavloNetrebchuk committed Oct 27, 2023
1 parent 9d34a02 commit 3ac8dd0
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import org.openedx.core.ui.theme.appShapes
import org.openedx.core.ui.theme.appTypography
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.openedx.core.presentation.global.app_upgrade.AppUpgradeRequiredScreen
import org.openedx.core.utils.AppUpdateState
import org.openedx.core.AppUpdateState
import org.openedx.auth.R as authR

class RestorePasswordFragment : Fragment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.openedx.auth.presentation.restore
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.launch
import org.openedx.auth.domain.interactor.AuthInteractor
import org.openedx.auth.presentation.AuthAnalytics
import org.openedx.core.BaseViewModel
Expand All @@ -13,9 +14,7 @@ import org.openedx.core.extension.isEmailValid
import org.openedx.core.extension.isInternetError
import org.openedx.core.system.EdxError
import org.openedx.core.system.ResourceManager
import kotlinx.coroutines.launch
import org.openedx.core.system.notifier.AppUpgradeEvent
import org.openedx.core.system.notifier.AppUpgradeEventUIState
import org.openedx.core.system.notifier.AppUpgradeNotifier

class RestorePasswordViewModel(
Expand All @@ -33,9 +32,9 @@ class RestorePasswordViewModel(
val uiMessage: LiveData<UIMessage>
get() = _uiMessage

private val _appUpgradeEventUIState = SingleEventLiveData<AppUpgradeEventUIState>()
val appUpgradeEventUIState: LiveData<AppUpgradeEventUIState>
get() = _appUpgradeEventUIState
private val _appUpgradeEvent = SingleEventLiveData<AppUpgradeEvent>()
val appUpgradeEventUIState: LiveData<AppUpgradeEvent>
get() = _appUpgradeEvent

init {
collectAppUpgradeEvent()
Expand Down Expand Up @@ -80,13 +79,7 @@ class RestorePasswordViewModel(
private fun collectAppUpgradeEvent() {
viewModelScope.launch {
appUpgradeNotifier.notifier.collect { event ->
when (event) {
is AppUpgradeEvent.UpgradeRequiredEvent -> {
_appUpgradeEventUIState.value = AppUpgradeEventUIState.UpgradeRequiredScreen
}

else -> {}
}
_appUpgradeEvent.value = event
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ 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.utils.AppUpdateState
import org.openedx.core.AppUpdateState

class SignInFragment : Fragment() {

Expand All @@ -95,7 +95,7 @@ class SignInFragment : Fragment() {
val showProgress by viewModel.showProgress.observeAsState(initial = false)
val uiMessage by viewModel.uiMessage.observeAsState()
val loginSuccess by viewModel.loginSuccess.observeAsState(initial = false)
val appUpgradeEvent by viewModel.appUpgradeEventUIState.observeAsState(null)
val appUpgradeEvent by viewModel.appUpgradeEvent.observeAsState(null)

if (appUpgradeEvent == null) {
LoginScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import org.openedx.core.extension.isInternetError
import org.openedx.core.system.EdxError
import org.openedx.core.system.ResourceManager
import org.openedx.core.system.notifier.AppUpgradeEvent
import org.openedx.core.system.notifier.AppUpgradeEventUIState
import org.openedx.core.system.notifier.AppUpgradeNotifier
import org.openedx.core.R as CoreRes

Expand All @@ -41,9 +40,9 @@ class SignInViewModel(
val loginSuccess: LiveData<Boolean>
get() = _loginSuccess

private val _appUpgradeEventUIState = SingleEventLiveData<AppUpgradeEventUIState>()
val appUpgradeEventUIState: LiveData<AppUpgradeEventUIState>
get() = _appUpgradeEventUIState
private val _appUpgradeEvent = SingleEventLiveData<AppUpgradeEvent>()
val appUpgradeEvent: LiveData<AppUpgradeEvent>
get() = _appUpgradeEvent

init {
collectAppUpgradeEvent()
Expand Down Expand Up @@ -87,13 +86,7 @@ class SignInViewModel(
private fun collectAppUpgradeEvent() {
viewModelScope.launch {
appUpgradeNotifier.notifier.collect { event ->
when (event) {
is AppUpgradeEvent.UpgradeRequiredEvent -> {
_appUpgradeEventUIState.value = AppUpgradeEventUIState.UpgradeRequiredScreen
}

else -> {}
}
_appUpgradeEvent.value = event
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import org.openedx.core.domain.model.RegistrationFieldType
import org.openedx.core.presentation.global.app_upgrade.AppUpgradeRequiredScreen
import org.openedx.core.ui.*
import org.openedx.core.ui.theme.*
import org.openedx.core.utils.AppUpdateState
import org.openedx.core.AppUpdateState

class SignUpFragment : Fragment() {

Expand All @@ -75,7 +75,7 @@ class SignUpFragment : Fragment() {
val isButtonClicked by viewModel.isButtonLoading.observeAsState(false)
val successLogin by viewModel.successLogin.observeAsState()
val validationError by viewModel.validationError.observeAsState(false)
val appUpgradeEvent by viewModel.appUpgradeEventUIState.observeAsState(null)
val appUpgradeEvent by viewModel.appUpgradeEvent.observeAsState(null)

if (appUpgradeEvent == null) {
RegistrationScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.openedx.auth.presentation.signup
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.launch
import org.openedx.auth.domain.interactor.AuthInteractor
import org.openedx.auth.presentation.AuthAnalytics
import org.openedx.core.ApiConstants
Expand All @@ -14,9 +15,7 @@ import org.openedx.core.data.storage.CorePreferences
import org.openedx.core.domain.model.RegistrationField
import org.openedx.core.extension.isInternetError
import org.openedx.core.system.ResourceManager
import kotlinx.coroutines.launch
import org.openedx.core.system.notifier.AppUpgradeEvent
import org.openedx.core.system.notifier.AppUpgradeEventUIState
import org.openedx.core.system.notifier.AppUpgradeNotifier

class SignUpViewModel(
Expand Down Expand Up @@ -47,9 +46,9 @@ class SignUpViewModel(
val validationError: LiveData<Boolean>
get() = _validationError

private val _appUpgradeEventUIState = SingleEventLiveData<AppUpgradeEventUIState>()
val appUpgradeEventUIState: LiveData<AppUpgradeEventUIState>
get() = _appUpgradeEventUIState
private val _appUpgradeEvent = SingleEventLiveData<AppUpgradeEvent>()
val appUpgradeEvent: LiveData<AppUpgradeEvent>
get() = _appUpgradeEvent

private val optionalFields = mutableMapOf<String, String>()
private val allFields = mutableListOf<RegistrationField>()
Expand Down Expand Up @@ -143,13 +142,7 @@ class SignUpViewModel(
private fun collectAppUpgradeEvent() {
viewModelScope.launch {
appUpgradeNotifier.notifier.collect { event ->
when (event) {
is AppUpgradeEvent.UpgradeRequiredEvent -> {
_appUpgradeEventUIState.value = AppUpgradeEventUIState.UpgradeRequiredScreen
}

else -> {}
}
_appUpgradeEvent.value = event
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package org.openedx.core.utils
package org.openedx.core

import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.compose.runtime.mutableStateOf
import org.openedx.core.system.notifier.AppUpgradeEvent

object AppUpdateState {
var wasUpdateDialogDisplayed = false
var wasUpdateDialogClosed = mutableStateOf(false)

fun openPlayMarket(context: Context) {
try {
Expand All @@ -20,4 +23,12 @@ object AppUpdateState {
)
}
}

data class AppUpgradeParameters(
val appUpgradeEvent: AppUpgradeEvent? = null,
val wasUpdateDialogClosed: Boolean = AppUpdateState.wasUpdateDialogClosed.value,
val appUpgradeRecommendedDialog: () -> Unit = {},
val onAppUpgradeRecommendedBoxClick: () -> Unit = {},
val onAppUpgradeRequired: () -> Unit = {},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.fragment.app.DialogFragment
import org.openedx.core.presentation.global.app_upgrade.AppUpgradeRecommendDialog
import org.openedx.core.ui.theme.OpenEdXTheme
import org.openedx.core.utils.AppUpdateState
import org.openedx.core.AppUpdateState

class AppUpgradeDialogFragment : DialogFragment() {

Expand All @@ -33,12 +33,14 @@ class AppUpgradeDialogFragment : DialogFragment() {
}

private fun onNotNowClick() {
AppUpdateState.wasUpdateDialogClosed.value = true
dismiss()
}

private fun onUpdateClick() {
AppUpdateState.openPlayMarket(requireContext())
AppUpdateState.wasUpdateDialogClosed.value = true
dismiss()
AppUpdateState.openPlayMarket(requireContext())
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ fun AppUpgradeRequiredButtons(
if (showAccountSettingsButton) {
TransparentTextButton(
text = stringResource(id = R.string.core_account_settings),
onNotNowClick = onAccountSettingsClick
onClick = onAccountSettingsClick
)
}
DefaultTextButton(
text = stringResource(id = R.string.core_update),
onUpdateClick = onUpdateClick
onClick = onUpdateClick
)
}
}
Expand All @@ -230,19 +230,19 @@ fun AppUpgradeDialogButtons(
) {
TransparentTextButton(
text = stringResource(id = R.string.core_not_now),
onNotNowClick = onNotNowClick
onClick = onNotNowClick
)
DefaultTextButton(
text = stringResource(id = R.string.core_update),
onUpdateClick = onUpdateClick
onClick = onUpdateClick
)
}
}

@Composable
fun TransparentTextButton(
text: String,
onNotNowClick: () -> Unit
onClick: () -> Unit
) {
Button(
modifier = Modifier
Expand All @@ -252,7 +252,7 @@ fun TransparentTextButton(
),
elevation = null,
shape = MaterialTheme.appShapes.navigationButtonShape,
onClick = onNotNowClick
onClick = onClick
) {
Text(
color = MaterialTheme.appColors.textAccent,
Expand All @@ -265,7 +265,7 @@ fun TransparentTextButton(
@Composable
fun DefaultTextButton(
text: String,
onUpdateClick: () -> Unit
onClick: () -> Unit
) {
Button(
modifier = Modifier
Expand All @@ -275,7 +275,7 @@ fun DefaultTextButton(
),
elevation = null,
shape = MaterialTheme.appShapes.navigationButtonShape,
onClick = onUpdateClick
onClick = onClick
) {
Row(
verticalAlignment = Alignment.CenterVertically,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.fragment.app.setFragmentResult
import org.openedx.core.ui.theme.OpenEdXTheme
import org.openedx.core.utils.AppUpdateState
import org.openedx.core.AppUpdateState

class UpgradeRequiredFragment : Fragment() {

Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion core/src/main/java/org/openedx/core/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private val DarkColorPalette = AppColors(
textPrimaryVariant = Color(0xFF79889F),
textSecondary = Color(0xFFB3B3B3),
textDark = Color(0xFF19212F),
textAccent = Color(0xFF5478F9),
textAccent = Color(0xFF879FF5),

textFieldBackground = Color(0xFF273346),
textFieldBackgroundVariant = Color(0xFF273346),
Expand Down
Loading

0 comments on commit 3ac8dd0

Please sign in to comment.