mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-09 07:16:04 -04:00
Created ComposeDimens to Centralize dimensions and avoiding harcoding the values everwhere in code for better maintainability and consistency
This commit is contained in:
parent
307b6b080c
commit
fd47586e40
@ -29,9 +29,12 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.colorResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.em
|
||||
import org.kiwix.kiwixmobile.core.R
|
||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.BUTTON_DEFAULT_ELEVATION
|
||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.BUTTON_DEFAULT_PADDING
|
||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.BUTTON_PRESSED_ELEVATION
|
||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.BUTTON_ROUND_CORNER_SHAPE
|
||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.DEFAULT_LETTER_SPACING
|
||||
|
||||
/**
|
||||
* This is our custom composable button according to our theme.
|
||||
@ -47,13 +50,16 @@ fun ComposeButton(
|
||||
containerColor = colorResource(id = R.color.denim_blue800),
|
||||
contentColor = Color.White
|
||||
),
|
||||
modifier = Modifier.padding(4.dp),
|
||||
shape = RoundedCornerShape(5.dp),
|
||||
elevation = ButtonDefaults.buttonElevation(defaultElevation = 2.dp, pressedElevation = 4.dp)
|
||||
modifier = Modifier.padding(BUTTON_DEFAULT_PADDING),
|
||||
shape = RoundedCornerShape(BUTTON_ROUND_CORNER_SHAPE),
|
||||
elevation = ButtonDefaults.buttonElevation(
|
||||
defaultElevation = BUTTON_DEFAULT_ELEVATION,
|
||||
pressedElevation = BUTTON_PRESSED_ELEVATION
|
||||
)
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = buttonTextId).uppercase(),
|
||||
letterSpacing = 0.0333.em
|
||||
letterSpacing = DEFAULT_LETTER_SPACING
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -28,18 +28,18 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.colorResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import org.kiwix.kiwixmobile.core.R
|
||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.CRASH_CHECKBOX_START_PADDING
|
||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.CRASH_CHECKBOX_TOP_PADDING
|
||||
|
||||
@Composable
|
||||
fun CrashCheckBox(checkBoxItem: Pair<Int, MutableState<Boolean>>) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(start = 100.dp, top = 8.dp),
|
||||
.padding(start = CRASH_CHECKBOX_START_PADDING, top = CRASH_CHECKBOX_TOP_PADDING),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Checkbox(
|
||||
@ -48,13 +48,13 @@ fun CrashCheckBox(checkBoxItem: Pair<Int, MutableState<Boolean>>) {
|
||||
colors = CheckboxDefaults.colors(
|
||||
checkedColor = colorResource(id = R.color.denim_blue200),
|
||||
checkmarkColor = colorResource(id = R.color.error_activity_background),
|
||||
uncheckedColor = Color.White
|
||||
uncheckedColor = colorResource(R.color.denim_blue200)
|
||||
)
|
||||
)
|
||||
Text(
|
||||
text = stringResource(id = checkBoxItem.first),
|
||||
color = colorResource(id = R.color.white),
|
||||
modifier = Modifier.padding(start = 8.dp)
|
||||
modifier = Modifier.padding(start = CRASH_CHECKBOX_TOP_PADDING)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -41,12 +41,19 @@ import androidx.compose.ui.res.colorResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.tonyodev.fetch2.R.string
|
||||
import org.kiwix.kiwixmobile.core.R
|
||||
import org.kiwix.kiwixmobile.core.composeviews.ComposeButton
|
||||
import org.kiwix.kiwixmobile.core.composeviews.CrashCheckBox
|
||||
import org.kiwix.kiwixmobile.core.extensions.loadBitmapFromMipmap
|
||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.CRASH_IMAGE_SIZE
|
||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.CRASH_MESSAGE_TEXT_SIZE
|
||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.CRASH_TITLE_TEXT_SIZE
|
||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.EIGHT_DP
|
||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.SIXTEEN_DP
|
||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.SIXTY_DP
|
||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.THIRTY_TWO_DP
|
||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.TWELVE_DP
|
||||
|
||||
@Composable
|
||||
fun ErrorActivityScreen(
|
||||
@ -60,30 +67,30 @@ fun ErrorActivityScreen(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(colorResource(id = R.color.error_activity_background))
|
||||
.padding(16.dp),
|
||||
.padding(SIXTEEN_DP),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(crashTitleStringId),
|
||||
fontSize = 24.sp,
|
||||
fontSize = CRASH_TITLE_TEXT_SIZE,
|
||||
color = colorResource(id = R.color.alabaster_white),
|
||||
modifier = Modifier.padding(top = 60.dp, start = 8.dp, end = 8.dp)
|
||||
modifier = Modifier.padding(top = SIXTY_DP, start = EIGHT_DP, end = EIGHT_DP)
|
||||
)
|
||||
|
||||
Image(
|
||||
bitmap = ImageBitmap.loadBitmapFromMipmap(LocalContext.current, R.mipmap.ic_launcher),
|
||||
contentDescription = stringResource(id = string.app_name),
|
||||
modifier = Modifier
|
||||
.height(70.dp)
|
||||
.padding(top = 12.dp, start = 8.dp, end = 8.dp)
|
||||
.height(CRASH_IMAGE_SIZE)
|
||||
.padding(top = TWELVE_DP, start = EIGHT_DP, end = EIGHT_DP)
|
||||
)
|
||||
|
||||
Text(
|
||||
text = stringResource(messageStringId),
|
||||
fontSize = 14.sp,
|
||||
fontSize = CRASH_MESSAGE_TEXT_SIZE,
|
||||
textAlign = TextAlign.Center,
|
||||
color = colorResource(id = R.color.white),
|
||||
modifier = Modifier.padding(start = 8.dp, top = 8.dp, end = 8.dp)
|
||||
modifier = Modifier.padding(start = EIGHT_DP, top = EIGHT_DP, end = EIGHT_DP)
|
||||
)
|
||||
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
@ -99,7 +106,7 @@ fun ErrorActivityScreen(
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 32.dp),
|
||||
.padding(bottom = THIRTY_TWO_DP),
|
||||
horizontalArrangement = Arrangement.SpaceEvenly
|
||||
) {
|
||||
ComposeButton(
|
||||
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2025 Kiwix <android.kiwix.org>
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.kiwix.kiwixmobile.core.utils
|
||||
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.em
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
object ComposeDimens {
|
||||
// Crash checkbox dimens
|
||||
val CRASH_CHECKBOX_START_PADDING = 100.dp
|
||||
val CRASH_CHECKBOX_TOP_PADDING = 8.dp
|
||||
|
||||
// Our default Button dimens
|
||||
val BUTTON_ROUND_CORNER_SHAPE = 5.dp
|
||||
val BUTTON_DEFAULT_ELEVATION = 2.dp
|
||||
val BUTTON_PRESSED_ELEVATION = 4.dp
|
||||
val BUTTON_DEFAULT_PADDING = 4.dp
|
||||
|
||||
// Error screen dimens
|
||||
val CRASH_TITLE_TEXT_SIZE = 24.sp
|
||||
val CRASH_MESSAGE_TEXT_SIZE = 14.sp
|
||||
val CRASH_IMAGE_SIZE = 70.dp
|
||||
|
||||
// Padding & Margins
|
||||
val SIXTY_DP = 60.dp
|
||||
val THIRTY_TWO_DP = 30.dp
|
||||
val SIXTEEN_DP = 16.dp
|
||||
val TWELVE_DP = 12.dp
|
||||
val EIGHT_DP = 8.dp
|
||||
val FIVE_DP = 5.dp
|
||||
val FOUR_DP = 4.dp
|
||||
val TWO_DP = 2.dp
|
||||
val SEVENTY_DP = 70.dp
|
||||
|
||||
// Font Sizes
|
||||
val TWENTY_FOUR_SP = 24.sp
|
||||
val FOURTEEN_SP = 14.sp
|
||||
|
||||
// Default letter spacing in text according to theme
|
||||
val DEFAULT_LETTER_SPACING = 0.0333.em
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user