Skip to content

Commit

Permalink
fix: [FC-0078] RTL, user avatar and dark theme bugs (openedx#426)
Browse files Browse the repository at this point in the history
* fix: color fixes

* fix: user image rotation fix

* fix: rtl support
  • Loading branch information
PavloNetrebchuk authored Feb 14, 2025
1 parent c0e1cfc commit e465552
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 133 deletions.
4 changes: 2 additions & 2 deletions auth/src/main/java/org/openedx/auth/presentation/ui/AuthUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import androidx.compose.material.OutlinedTextField
import androidx.compose.material.Text
import androidx.compose.material.TextFieldDefaults
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ChevronRight
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
import androidx.compose.material.icons.filled.ExpandMore
import androidx.compose.material.icons.filled.Visibility
import androidx.compose.material.icons.filled.VisibilityOff
Expand Down Expand Up @@ -524,7 +524,7 @@ fun ExpandableText(
} else {
stringResource(id = R.string.auth_show_optional_fields)
}
val icon = Icons.Filled.ChevronRight
val icon = Icons.AutoMirrored.Filled.KeyboardArrowRight

Row(
modifier = modifier
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 @@ -52,6 +52,7 @@ import androidx.compose.material.ScaffoldState
import androidx.compose.material.Text
import androidx.compose.material.TextFieldDefaults
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.AccountCircle
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Info
Expand Down Expand Up @@ -1163,7 +1164,7 @@ fun BackBtn(
}
) {
Icon(
painter = painterResource(id = R.drawable.core_ic_back),
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = stringResource(id = R.string.core_accessibility_btn_back),
tint = tint
)
Expand Down
31 changes: 0 additions & 31 deletions core/src/main/res/drawable/core_ic_back.xml

This file was deleted.

31 changes: 0 additions & 31 deletions core/src/main/res/drawable/core_ic_forward.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import androidx.compose.material.IconButton
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowForward
import androidx.compose.material.icons.filled.ArrowDownward
import androidx.compose.material.icons.filled.Close
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.ViewCompositionStrategy
Expand Down Expand Up @@ -153,6 +154,11 @@ private fun ChapterEndDialogScreen(
onProceedButtonClick: () -> Unit,
onCancelButtonClick: () -> Unit
) {
val nextSectionButtonIcon = if (isVerticalNavigation) {
Icons.Default.ArrowDownward
} else {
Icons.AutoMirrored.Filled.ArrowForward
}
Card(
modifier = Modifier
.fillMaxWidth(fraction = 0.95f)
Expand Down Expand Up @@ -208,10 +214,9 @@ private fun ChapterEndDialogScreen(
content = {
TextIcon(
text = stringResource(id = R.string.course_next_section),
painter = painterResource(org.openedx.core.R.drawable.core_ic_forward),
icon = nextSectionButtonIcon,
color = MaterialTheme.appColors.primaryButtonText,
textStyle = MaterialTheme.appTypography.labelLarge,
iconModifier = Modifier.rotate(if (isVerticalNavigation) 90f else 0f)
)
},
onClick = onProceedButtonClick
Expand Down Expand Up @@ -324,7 +329,7 @@ private fun ChapterEndDialogScreenLandscape(
content = {
TextIcon(
text = stringResource(id = R.string.course_next_section),
painter = painterResource(org.openedx.core.R.drawable.core_ic_forward),
icon = Icons.AutoMirrored.Filled.ArrowForward,
color = MaterialTheme.appColors.primaryButtonText,
textStyle = MaterialTheme.appTypography.labelLarge
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowForward
import androidx.compose.material.rememberScaffoldState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
Expand Down Expand Up @@ -75,7 +77,6 @@ import org.openedx.foundation.presentation.WindowSize
import org.openedx.foundation.presentation.WindowType
import org.openedx.foundation.presentation.windowSizeValue
import java.util.Date
import org.openedx.core.R as CoreR

@Composable
fun CourseOutlineScreen(
Expand Down Expand Up @@ -397,7 +398,7 @@ private fun ResumeCourse(
content = {
TextIcon(
text = stringResource(id = R.string.course_resume),
painter = painterResource(id = CoreR.drawable.core_ic_forward),
icon = Icons.AutoMirrored.Filled.ArrowForward,
color = MaterialTheme.appColors.primaryButtonText,
textStyle = MaterialTheme.appTypography.labelLarge
)
Expand Down Expand Up @@ -456,7 +457,7 @@ private fun ResumeCourseTablet(
content = {
TextIcon(
text = stringResource(id = R.string.course_resume),
painter = painterResource(id = CoreR.drawable.core_ic_forward),
icon = Icons.AutoMirrored.Filled.ArrowForward,
color = MaterialTheme.appColors.primaryButtonText,
textStyle = MaterialTheme.appTypography.labelLarge
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import androidx.compose.material.Snackbar
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ChevronRight
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.CloudDone
import androidx.compose.material.icons.outlined.CloudDownload
Expand Down Expand Up @@ -305,7 +305,7 @@ fun CardArrow(
degrees: Float,
) {
Icon(
imageVector = Icons.Filled.ChevronRight,
imageVector = Icons.AutoMirrored.Filled.KeyboardArrowRight,
tint = MaterialTheme.appColors.textDark,
contentDescription = "Expandable Arrow",
modifier = Modifier.rotate(degrees),
Expand Down Expand Up @@ -822,7 +822,7 @@ fun CourseSubSectionItem(
Spacer(modifier = Modifier.width(16.dp))
if (isAssignmentEnable) {
Icon(
imageVector = Icons.Filled.ChevronRight,
imageVector = Icons.AutoMirrored.Filled.KeyboardArrowRight,
tint = MaterialTheme.appColors.onSurface,
contentDescription = null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import androidx.compose.material.SwitchDefaults
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ChevronRight
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.material.icons.outlined.Videocam
import androidx.compose.material.rememberScaffoldState
Expand Down Expand Up @@ -598,7 +598,7 @@ private fun AllVideosDownloadItem(
Icon(
modifier = Modifier
.padding(end = 16.dp),
imageVector = Icons.Filled.ChevronRight,
imageVector = Icons.AutoMirrored.Filled.KeyboardArrowRight,
tint = MaterialTheme.appColors.onSurface,
contentDescription = "Expandable Arrow"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
Expand Down Expand Up @@ -179,13 +178,12 @@ fun HtmlUnitView(
Surface(
modifier = Modifier
.clip(RoundedCornerShape(topStart = 24.dp, topEnd = 24.dp)),
color = Color.White
color = MaterialTheme.colors.background
) {
Box(
modifier = Modifier
.fillMaxSize()
.padding(bottom = bottomPadding)
.background(Color.White)
.then(border),
contentAlignment = Alignment.TopCenter
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ import androidx.compose.material.Scaffold
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowForwardIos
import androidx.compose.material.icons.filled.ChevronRight
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
import androidx.compose.material.icons.filled.School
import androidx.compose.material.icons.filled.Warning
import androidx.compose.material.pullrefresh.PullRefreshIndicator
Expand Down Expand Up @@ -347,7 +346,7 @@ private fun SecondaryCourses(
modifier = Modifier.padding(horizontal = 18.dp),
text = stringResource(R.string.dashboard_view_all_with_count, courses.size + 1),
textStyle = MaterialTheme.appTypography.titleSmall,
icon = Icons.Default.ChevronRight,
icon = Icons.AutoMirrored.Filled.KeyboardArrowRight,
color = MaterialTheme.appColors.textDark,
iconModifier = Modifier.size(22.dp),
onClick = onViewAllClick
Expand Down Expand Up @@ -512,8 +511,8 @@ private fun AssignmentItem(
}
}
Icon(
modifier = Modifier.size(16.dp),
imageVector = Icons.AutoMirrored.Filled.ArrowForwardIos,
modifier = Modifier.size(22.dp),
imageVector = Icons.AutoMirrored.Filled.KeyboardArrowRight,
tint = MaterialTheme.appColors.textDark,
contentDescription = null
)
Expand Down Expand Up @@ -690,8 +689,8 @@ private fun ResumeButton(
}
}
Icon(
modifier = Modifier.size(16.dp),
imageVector = Icons.AutoMirrored.Filled.ArrowForwardIos,
modifier = Modifier.size(22.dp),
imageVector = Icons.AutoMirrored.Filled.KeyboardArrowRight,
tint = MaterialTheme.appColors.primaryButtonText,
contentDescription = null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
import androidx.compose.material.icons.automirrored.outlined.HelpOutline
import androidx.compose.material.icons.filled.ChevronRight
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
Expand Down Expand Up @@ -661,7 +661,7 @@ fun TopicItem(
color = MaterialTheme.appColors.textPrimary
)
Icon(
imageVector = Icons.Filled.ChevronRight,
imageVector = Icons.AutoMirrored.Filled.KeyboardArrowRight,
tint = MaterialTheme.appColors.primary,
contentDescription = "Expandable Arrow"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ private fun CalendarTitleTextField(
onValueChanged(it.text.trim())
},
colors = TextFieldDefaults.outlinedTextFieldColors(
unfocusedBorderColor = MaterialTheme.appColors.textFieldBorder
unfocusedBorderColor = MaterialTheme.appColors.textFieldBorder,
textColor = MaterialTheme.appColors.textPrimary
),
shape = MaterialTheme.appShapes.textFieldShape,
placeholder = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import android.content.res.Configuration
import android.content.res.Configuration.UI_MODE_NIGHT_YES
import android.graphics.Bitmap
import android.graphics.ImageDecoder
import android.graphics.Matrix
import android.media.ExifInterface
import android.net.Uri
import android.os.Build
import android.os.Bundle
Expand Down Expand Up @@ -236,8 +234,6 @@ class EditProfileFragment : Fragment() {

@Suppress("DEPRECATION")
private fun cropImage(uri: Uri): Uri {
val matrix = Matrix()
matrix.postRotate(getImageOrientation(uri).toFloat())
val originalBitmap = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
ImageDecoder.decodeBitmap(
ImageDecoder.createSource(
Expand All @@ -248,26 +244,17 @@ class EditProfileFragment : Fragment() {
} else {
MediaStore.Images.Media.getBitmap(requireContext().contentResolver, uri)
}
val rotatedBitmap = Bitmap.createBitmap(
originalBitmap,
0,
0,
originalBitmap.width,
originalBitmap.height,
matrix,
true
)
val newFile = File.createTempFile(
"Image_${System.currentTimeMillis()}",
".jpg",
requireContext().getExternalFilesDir(Environment.DIRECTORY_PICTURES)
)

val ratio: Float = rotatedBitmap.width.toFloat() / TARGET_IMAGE_WIDTH
val ratio: Float = originalBitmap.width.toFloat() / TARGET_IMAGE_WIDTH
val newBitmap = Bitmap.createScaledBitmap(
rotatedBitmap,
originalBitmap,
TARGET_IMAGE_WIDTH,
(rotatedBitmap.height.toFloat() / ratio).toInt(),
(originalBitmap.height.toFloat() / ratio).toInt(),
false
)
val bos = ByteArrayOutputStream()
Expand All @@ -285,28 +272,9 @@ class EditProfileFragment : Fragment() {
)!!
}

private fun getImageOrientation(uri: Uri): Int {
var rotation = 0
val exif = ExifInterface(requireActivity().contentResolver.openInputStream(uri)!!)
when (
exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL
)
) {
ExifInterface.ORIENTATION_ROTATE_270 -> rotation = ORIENTATION_ROTATE_270
ExifInterface.ORIENTATION_ROTATE_180 -> rotation = ORIENTATION_ROTATE_180
ExifInterface.ORIENTATION_ROTATE_90 -> rotation = ORIENTATION_ROTATE_90
}
return rotation
}

companion object {
private const val ARG_ACCOUNT = "argAccount"
const val LEAVE_PROFILE_WIDTH_FACTOR = 0.7f
private const val ORIENTATION_ROTATE_270 = 270
private const val ORIENTATION_ROTATE_180 = 180
private const val ORIENTATION_ROTATE_90 = 90
private const val IMAGE_QUALITY = 90
private const val TARGET_IMAGE_WIDTH = 500

Expand Down
Loading

0 comments on commit e465552

Please sign in to comment.