Skip to content

Commit

Permalink
fix: Draft commit - 2
Browse files Browse the repository at this point in the history
  • Loading branch information
omerhabib26 committed Feb 1, 2024
1 parent 03dce5c commit b1af700
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand All @@ -56,6 +59,7 @@ fun AppUpgradeRequiredScreen(
)
}

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun AppUpgradeRequiredScreen(
modifier: Modifier = Modifier,
Expand All @@ -67,13 +71,15 @@ fun AppUpgradeRequiredScreen(
modifier = modifier
.fillMaxSize()
.background(color = MaterialTheme.appColors.background)
.statusBarsInset(),
.statusBarsInset()
.semantics { testTagsAsResourceId = true },
contentAlignment = Alignment.TopCenter
) {
Text(
modifier = Modifier
.fillMaxWidth()
.padding(top = 10.dp, bottom = 12.dp),
.padding(top = 10.dp, bottom = 12.dp)
.testTag("txt_app_upgrade_deprecated"),
text = stringResource(id = R.string.core_deprecated_app_version),
color = MaterialTheme.appColors.textPrimary,
style = MaterialTheme.appTypography.titleMedium,
Expand All @@ -93,6 +99,7 @@ fun AppUpgradeRequiredScreen(
}
}

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun AppUpgradeRecommendDialog(
modifier: Modifier = Modifier,
Expand All @@ -107,7 +114,7 @@ fun AppUpgradeRecommendDialog(
}

Surface(
modifier = modifier,
modifier = modifier.semantics { testTagsAsResourceId = true },
color = Color.Transparent
) {
Box(
Expand All @@ -116,7 +123,8 @@ fun AppUpgradeRecommendDialog(
.padding(horizontal = 4.dp)
.noRippleClickable {
onNotNowClick()
},
}
.testTag("btn_upgrade_dialog_not_now"),
contentAlignment = Alignment.Center
) {
Box(
Expand All @@ -143,11 +151,13 @@ fun AppUpgradeRecommendDialog(
contentDescription = null
)
Text(
modifier = Modifier.testTag("txt_app_upgrade_title"),
text = stringResource(id = R.string.core_app_upgrade_title),
color = MaterialTheme.appColors.textPrimary,
style = MaterialTheme.appTypography.titleMedium
)
Text(
modifier = Modifier.testTag("txt_app_upgrade_description"),
text = stringResource(id = R.string.core_app_upgrade_dialog_description),
color = MaterialTheme.appColors.textPrimary,
textAlign = TextAlign.Center,
Expand All @@ -163,6 +173,7 @@ fun AppUpgradeRecommendDialog(
}
}

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun AppUpgradeRequiredContent(
modifier: Modifier = Modifier,
Expand All @@ -171,7 +182,7 @@ fun AppUpgradeRequiredContent(
onUpdateClick: () -> Unit
) {
Column(
modifier = modifier,
modifier = modifier.semantics { testTagsAsResourceId = true },
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(32.dp)
) {
Expand All @@ -184,11 +195,13 @@ fun AppUpgradeRequiredContent(
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
Text(
modifier = Modifier.testTag("txt_app_upgrade_required_title"),
text = stringResource(id = R.string.core_app_update_required_title),
color = MaterialTheme.appColors.textPrimary,
style = MaterialTheme.appTypography.titleMedium
)
Text(
modifier = Modifier.testTag("txt_app_upgrade_required_description"),
text = stringResource(id = R.string.core_app_update_required_description),
color = MaterialTheme.appColors.textPrimary,
textAlign = TextAlign.Center,
Expand Down Expand Up @@ -251,7 +264,8 @@ fun TransparentTextButton(
) {
Button(
modifier = Modifier
.height(42.dp),
.height(42.dp)
.testTag("btn_upgrade_dialog_$text"),
colors = ButtonDefaults.buttonColors(
backgroundColor = Color.Transparent
),
Expand All @@ -260,6 +274,7 @@ fun TransparentTextButton(
onClick = onClick
) {
Text(
modifier = Modifier.testTag("txt_app_upgrade_dialog_$text"),
color = MaterialTheme.appColors.textAccent,
style = MaterialTheme.appTypography.labelLarge,
text = text
Expand All @@ -274,7 +289,8 @@ fun DefaultTextButton(
) {
Button(
modifier = Modifier
.height(42.dp),
.height(42.dp)
.testTag("btn_upgrade_dialog_$text"),
colors = ButtonDefaults.buttonColors(
backgroundColor = MaterialTheme.appColors.buttonBackground
),
Expand All @@ -287,6 +303,7 @@ fun DefaultTextButton(
horizontalArrangement = Arrangement.Center
) {
Text(
modifier = Modifier.testTag("txt_app_upgrade_dialog_$text"),
text = text,
color = MaterialTheme.appColors.buttonText,
style = MaterialTheme.appTypography.labelLarge
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/openedx/core/ui/ComposeCommon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ fun SearchBar(
isFocused = it.hasFocus
}
.clip(MaterialTheme.appShapes.textFieldShape)
.then(modifier),
.then(modifier)
.testTag("tf_search"),
shape = MaterialTheme.appShapes.textFieldShape,
value = textFieldValue,
onValueChange = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.compose.ui.text.TextRange
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.style.TextAlign
Expand Down Expand Up @@ -205,7 +208,8 @@ private fun CourseSearchScreen(
scaffoldState = scaffoldState,
modifier = Modifier
.fillMaxSize()
.navigationBarsPadding(),
.navigationBarsPadding()
.semantics { testTagsAsResourceId = true },
backgroundColor = MaterialTheme.appColors.background,
bottomBar = {
if (!isUserLoggedIn) {
Expand Down Expand Up @@ -283,7 +287,8 @@ private fun CourseSearchScreen(
Text(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 56.dp),
.padding(horizontal = 56.dp)
.testTag("txt_search_title"),
text = stringResource(id = org.openedx.core.R.string.core_search),
color = MaterialTheme.appColors.textPrimary,
style = MaterialTheme.appTypography.titleMedium,
Expand Down Expand Up @@ -340,12 +345,15 @@ private fun CourseSearchScreen(
item {
Column {
Text(
modifier = Modifier.testTag("txt_search_results_title"),
text = stringResource(id = discoveryR.string.discovery_search_results),
color = MaterialTheme.appColors.textPrimary,
style = MaterialTheme.appTypography.displaySmall
)
Text(
modifier = Modifier.padding(top = 4.dp),
modifier = Modifier
.padding(top = 4.dp)
.testTag("txt_search_results_subtitle"),
text = typingText,
color = MaterialTheme.appColors.textPrimary,
style = MaterialTheme.appTypography.titleSmall
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.input.ImeAction
Expand Down Expand Up @@ -129,6 +132,7 @@ class DeleteProfileFragment : Fragment() {

}

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun DeleteProfileScreen(
windowSize: WindowSize,
Expand All @@ -154,7 +158,8 @@ fun DeleteProfileScreen(
Scaffold(
modifier = Modifier
.fillMaxSize()
.navigationBarsPadding(),
.navigationBarsPadding()
.semantics { testTagsAsResourceId = true },
scaffoldState = scaffoldState
) { paddingValues ->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ private fun EditProfileScreen(
bottomSheetScaffoldState.hide()
}
}
},
}
.testTag("btn_bottom_sheet_edit_profile"),
sheetShape = MaterialTheme.appShapes.screenBackgroundShape,
sheetState = bottomSheetScaffoldState,
scrimColor = Color.Black.copy(alpha = 0.4f),
Expand Down Expand Up @@ -829,7 +830,9 @@ private fun ChangeImageDialog(
val dialogWindowProvider = LocalView.current.parent as DialogWindowProvider
dialogWindowProvider.window.setGravity(Gravity.BOTTOM)
Box(
Modifier.padding(bottom = 24.dp)
Modifier
.padding(bottom = 24.dp)
.semantics { testTagsAsResourceId = true }
) {
Column(
Modifier
Expand Down Expand Up @@ -982,7 +985,7 @@ private fun SelectableField(
Text(
modifier = Modifier
.fillMaxWidth()
.testTag("txt_edit_profile_field_label"),
.testTag("txt_edit_profile_field_label_${name}"),
text = name,
style = MaterialTheme.appTypography.labelLarge,
color = MaterialTheme.appColors.textPrimary
Expand All @@ -1008,10 +1011,10 @@ private fun SelectableField(
.noRippleClickable {
onClick()
}
.testTag("tf_edit_profile_field_select"),
.testTag("tf_edit_profile_field_select_${name}"),
placeholder = {
Text(
modifier = Modifier.testTag("txt_edit_profile_field_placeholder"),
modifier = Modifier.testTag("txt_edit_profile_field_placeholder_${name}"),
text = name,
color = MaterialTheme.appColors.textFieldHint,
style = MaterialTheme.appTypography.bodyMedium
Expand All @@ -1038,7 +1041,7 @@ private fun InputEditField(
Text(
modifier = Modifier
.fillMaxWidth()
.testTag("txt_edit_profile_field_label"),
.testTag("txt_edit_profile_field_label_${name}"),
text = name,
style = MaterialTheme.appTypography.labelLarge,
color = MaterialTheme.appColors.textPrimary
Expand All @@ -1057,7 +1060,7 @@ private fun InputEditField(
shape = MaterialTheme.appShapes.textFieldShape,
placeholder = {
Text(
modifier = Modifier.testTag("txt_edit_profile_field_placeholder"),
modifier = Modifier.testTag("txt_edit_profile_field_${name}_placeholder"),
text = name,
color = MaterialTheme.appColors.textFieldHint,
style = MaterialTheme.appTypography.bodyMedium
Expand All @@ -1073,7 +1076,7 @@ private fun InputEditField(
onDoneClick()
},
textStyle = MaterialTheme.appTypography.bodyMedium,
modifier = modifier.testTag("tf_edit_profile_field_input")
modifier = modifier.testTag("tf_edit_profile_field_input_${name}")
)
}
}
Expand Down Expand Up @@ -1103,7 +1106,10 @@ private fun LeaveProfile(
MaterialTheme.appShapes.cardShape
)
.padding(horizontal = 40.dp)
.padding(top = 48.dp, bottom = 36.dp),
.padding(top = 48.dp, bottom = 36.dp)
.semantics {
testTagsAsResourceId = true
},
horizontalAlignment = Alignment.CenterHorizontally
) {
Icon(
Expand Down Expand Up @@ -1176,7 +1182,8 @@ private fun LeaveProfileLandscape(
Card(
modifier = Modifier
.width(screenWidth * 0.7f)
.clip(MaterialTheme.appShapes.courseImageShape),
.clip(MaterialTheme.appShapes.courseImageShape)
.semantics { testTagsAsResourceId = true },
backgroundColor = MaterialTheme.appColors.background,
shape = MaterialTheme.appShapes.courseImageShape
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ private fun LogoutButton(onClick: () -> Unit) {
}
}

@OptIn(ExperimentalComposeUiApi::class)
@Composable
private fun LogoutDialog(
onDismissRequest: () -> Unit,
Expand All @@ -428,7 +429,8 @@ private fun LogoutDialog(
MaterialTheme.appColors.cardViewBorder,
MaterialTheme.appShapes.cardShape
)
.padding(horizontal = 40.dp, vertical = 36.dp),
.padding(horizontal = 40.dp, vertical = 36.dp)
.semantics { testTagsAsResourceId = true },
horizontalAlignment = Alignment.CenterHorizontally
) {
Box(
Expand Down Expand Up @@ -516,14 +518,14 @@ private fun ProfileInfoItem(
.fillMaxWidth()
.clickable { onClick() }
.padding(20.dp)
.testTag("btn_profile_info_item"),
.testTag("btn_profile_info_item_$text"),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text(
modifier = Modifier
.weight(1f)
.testTag("txt_profile_info_item_title"),
.testTag("txt_profile_info_item_title_$text"),
text = text,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
Expand Down
Loading

0 comments on commit b1af700

Please sign in to comment.