Improved the divider height on HelpScreen to match the previous design.

This commit is contained in:
MohitMaliFtechiz 2025-03-26 18:40:50 +05:30 committed by Kelson
parent 64db5ad3e5
commit 056b809717
3 changed files with 70 additions and 22 deletions

View File

@ -19,6 +19,7 @@
package org.kiwix.kiwixmobile.core.help package org.kiwix.kiwixmobile.core.help
import android.app.Activity import android.app.Activity
import android.content.res.Configuration
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.isSystemInDarkTheme
@ -33,6 +34,7 @@ import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.minimumInteractiveComponentSize
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
@ -40,13 +42,16 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import org.kiwix.kiwixmobile.core.R import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.core.error.DiagnosticReportActivity import org.kiwix.kiwixmobile.core.error.DiagnosticReportActivity
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.start import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.start
import org.kiwix.kiwixmobile.core.ui.components.KiwixAppBar import org.kiwix.kiwixmobile.core.ui.components.KiwixAppBar
import org.kiwix.kiwixmobile.core.ui.components.NavigationIcon
import org.kiwix.kiwixmobile.core.ui.theme.KiwixTheme import org.kiwix.kiwixmobile.core.ui.theme.KiwixTheme
import org.kiwix.kiwixmobile.core.ui.theme.MineShaftGray350 import org.kiwix.kiwixmobile.core.ui.theme.MineShaftGray350
import org.kiwix.kiwixmobile.core.ui.theme.MineShaftGray600 import org.kiwix.kiwixmobile.core.ui.theme.MineShaftGray600
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.HELP_SCREEN_DIVIDER_HEIGHT
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.SIXTEEN_DP import org.kiwix.kiwixmobile.core.utils.ComposeDimens.SIXTEEN_DP
@Suppress("ComposableLambdaParameterNaming") @Suppress("ComposableLambdaParameterNaming")
@ -69,7 +74,7 @@ fun HelpScreen(
) { innerPadding -> ) { innerPadding ->
Column(modifier = Modifier.padding(innerPadding)) { Column(modifier = Modifier.padding(innerPadding)) {
SendReportRow() SendReportRow()
HorizontalDivider(color = dividerColor) HorizontalDivider(color = dividerColor, thickness = HELP_SCREEN_DIVIDER_HEIGHT)
HelpItemList(data, dividerColor) HelpItemList(data, dividerColor)
} }
} }
@ -79,7 +84,7 @@ fun HelpScreen(
@Composable @Composable
fun SendReportRow() { fun SendReportRow() {
val context = LocalContext.current val context = LocalContext.current
// val isDarkTheme = isSystemInDarkTheme() val isDarkTheme = isSystemInDarkTheme()
Row( Row(
modifier = Modifier modifier = Modifier
@ -91,14 +96,14 @@ fun SendReportRow() {
Image( Image(
painter = painterResource(R.drawable.ic_feedback_orange_24dp), painter = painterResource(R.drawable.ic_feedback_orange_24dp),
contentDescription = stringResource(R.string.send_report), contentDescription = stringResource(R.string.send_report),
modifier = Modifier modifier = Modifier.padding(SIXTEEN_DP)
.padding(SIXTEEN_DP)
) )
Text( Text(
text = stringResource(R.string.send_report), text = stringResource(R.string.send_report),
// color = if (isDarkTheme) Color.LightGray else Color.DarkGray, color = if (isDarkTheme) Color.LightGray else Color.DarkGray,
style = MaterialTheme.typography.titleMedium style = MaterialTheme.typography.titleMedium,
modifier = Modifier.minimumInteractiveComponentSize()
) )
} }
} }
@ -111,7 +116,40 @@ fun HelpItemList(data: List<HelpScreenItemDataClass>, dividerColor: Color) {
) { ) {
itemsIndexed(data, key = { _, item -> item.title }) { _, item -> itemsIndexed(data, key = { _, item -> item.title }) { _, item ->
HelpScreenItem(data = item) HelpScreenItem(data = item)
HorizontalDivider(color = dividerColor) HorizontalDivider(color = dividerColor, thickness = HELP_SCREEN_DIVIDER_HEIGHT)
} }
} }
} }
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
// @Preview()
@Composable
fun PreviewScreen() {
HelpScreen(
data = transformToHelpScreenData(LocalContext.current, rawTitleDescriptionMap())
) { NavigationIcon(onClick = { }) }
}
fun rawTitleDescriptionMap(): List<Pair<Int, Any>> =
listOf(
R.string.help_2 to R.array.description_help_2,
R.string.help_5 to R.array.description_help_5,
R.string.how_to_update_content to R.array.update_content_description
)
// fun transformToHelpScreenData(
// context: Context,
// rawTitleDescriptionMap: List<Pair<Int, Any>>
// ): List<HelpScreenItemDataClass> {
// return rawTitleDescriptionMap.map { (titleResId, description) ->
// val title = context.getString(titleResId)
// val descriptionValue = when (description) {
// is String -> description
// is Int -> context.resources.getStringArray(description).joinToString(separator = "\n")
// else -> {
// throw IllegalArgumentException("Invalid description resource type for title: $titleResId")
// }
// }
// HelpScreenItemDataClass(title, descriptionValue)
// }
// }

View File

@ -21,6 +21,7 @@ package org.kiwix.kiwixmobile.core.help
import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateFloatAsState import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween import androidx.compose.animation.core.tween
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.isSystemInDarkTheme
@ -32,11 +33,10 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.KeyboardArrowDown import androidx.compose.material.icons.filled.KeyboardArrowDown
import androidx.compose.material3.Icon
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.minimumInteractiveComponentSize
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
@ -45,21 +45,23 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import org.kiwix.kiwixmobile.core.R import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.EIGHT_DP
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.HELP_SCREEN_ITEM_TITLE_LETTER_SPACING
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.HELP_SCREEN_ITEM_TITLE_TEXT_SIZE
// Define constants for spacing, font sizes, etc. // Define constants for spacing, font sizes, etc.
private val HelpItemTitleFontSize = 22.sp
private val HelpItemDescriptionFontSize = 17.sp private val HelpItemDescriptionFontSize = 17.sp
private val IconSize = 36.dp
private const val HELP_ITEM_ANIMATION_DURATION = 300 private const val HELP_ITEM_ANIMATION_DURATION = 300
private const val HELP_ITEM_ARROW_ROTATION_OPEN = 180f private const val HELP_ITEM_ARROW_ROTATION_OPEN = 180f
private const val HELP_ITEM_ARROW_ROTATION_CLOSE = 0f private const val HELP_ITEM_ARROW_ROTATION_CLOSE = 0f
@ -72,19 +74,18 @@ fun HelpScreenItem(
) { ) {
var isOpen by remember { mutableStateOf(initiallyOpened) } var isOpen by remember { mutableStateOf(initiallyOpened) }
val itemColor = if (isSystemInDarkTheme()) Color.White else Color.Black val itemColor = if (isSystemInDarkTheme()) Color.White else Color.Black
val topPadding: Dp = dimensionResource(id = R.dimen.dimen_medium_padding)
val horizontalPadding: Dp = dimensionResource(id = R.dimen.activity_horizontal_margin) val horizontalPadding: Dp = dimensionResource(id = R.dimen.activity_horizontal_margin)
Column( Column(
modifier = modifier modifier = modifier
.fillMaxWidth(), .fillMaxWidth()
.padding(vertical = EIGHT_DP),
verticalArrangement = Arrangement.Center, verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally
) { ) {
HelpItemHeader(data.title, isOpen, itemColor, horizontalPadding) { isOpen = !isOpen } HelpItemHeader(data.title, isOpen, itemColor, horizontalPadding) { isOpen = !isOpen }
AnimatedVisibility(visible = isOpen) { AnimatedVisibility(visible = isOpen) {
Spacer(modifier = Modifier.height(topPadding)) Spacer(modifier = Modifier.height(EIGHT_DP))
HelpItemDescription(data.description, itemColor, horizontalPadding) HelpItemDescription(data.description, itemColor, horizontalPadding)
} }
} }
@ -111,23 +112,26 @@ fun HelpItemHeader(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.clickable(interactionSource = interactionSource, indication = null, onClick = onToggle) .clickable(interactionSource = interactionSource, indication = null, onClick = onToggle)
.padding(horizontal = horizontalPadding, vertical = horizontalPadding) .padding(horizontal = horizontalPadding, vertical = EIGHT_DP)
) { ) {
Text( Text(
text = title, text = title,
fontSize = HelpItemTitleFontSize, fontSize = HELP_SCREEN_ITEM_TITLE_TEXT_SIZE,
color = itemColor, color = itemColor,
fontWeight = FontWeight.Normal fontWeight = FontWeight.Medium,
letterSpacing = HELP_SCREEN_ITEM_TITLE_LETTER_SPACING,
modifier = Modifier.minimumInteractiveComponentSize()
) )
Icon( Image(
imageVector = Icons.Default.KeyboardArrowDown, imageVector = Icons.Default.KeyboardArrowDown,
contentDescription = stringResource(R.string.expand), contentDescription = stringResource(R.string.expand),
modifier = Modifier modifier = Modifier
.graphicsLayer { .graphicsLayer {
rotationZ = arrowRotation rotationZ = arrowRotation
} }
.size(IconSize), .minimumInteractiveComponentSize(),
tint = itemColor contentScale = ContentScale.Inside,
colorFilter = ColorFilter.tint(color = itemColor)
) )
} }
} }

View File

@ -98,4 +98,10 @@ object ComposeDimens {
// LocalLibraryFragment dimens // LocalLibraryFragment dimens
val FAB_ICON_BOTTOM_MARGIN = 50.dp val FAB_ICON_BOTTOM_MARGIN = 50.dp
// HelpFragment dimens
val HELP_SCREEN_DIVIDER_HEIGHT = 0.7.dp
val HELP_SCREEN_ITEM_TITLE_TEXT_SIZE = 20.sp
val HELP_SCREEN_ITEM_TITLE_LETTER_SPACING = 0.0125.em
val HELP_SCREEN_ARROW_ICON_MINIMUM_SIZE = 48.dp
} }