Skip to content

Commit

Permalink
Crop language SVG images in Translations screen
Browse files Browse the repository at this point in the history
  • Loading branch information
alialbaali committed May 24, 2023
1 parent 0bc3c50 commit a36f934
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 18 deletions.
37 changes: 27 additions & 10 deletions app/src/main/java/com/noto/app/settings/SettingsItem.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.noto.app.settings

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
Expand All @@ -32,13 +34,14 @@ fun SettingsItem(
titleColor: Color = MaterialTheme.colorScheme.onSurface,
painter: Painter? = null,
painterColor: Color = Color.Unspecified,
contentScale: ContentScale = ContentScale.Fit,
description: String? = null,
descriptionMaxLines: Int = Int.MAX_VALUE,
equalWeights: Boolean = true,
) {
Surface(modifier = Modifier.fillMaxWidth(), shape = MaterialTheme.shapes.small) {
Row(modifier.padding(NotoTheme.dimensions.medium), horizontalArrangement = Arrangement.spacedBy(NotoTheme.dimensions.medium)) {
SettingsItemContent(title, titleColor, type, painter, painterColor, description, descriptionMaxLines, equalWeights)
SettingsItemContent(title, titleColor, type, painter, painterColor, contentScale, description, descriptionMaxLines, equalWeights)
}
}
}
Expand All @@ -53,13 +56,14 @@ fun SettingsItem(
titleColor: Color = MaterialTheme.colorScheme.onSurface,
painter: Painter? = null,
painterColor: Color = Color.Unspecified,
contentScale: ContentScale = ContentScale.Fit,
description: String? = null,
descriptionMaxLines: Int = Int.MAX_VALUE,
equalWeights: Boolean = true,
) {
Surface(onClick, modifier = Modifier.fillMaxWidth(), shape = MaterialTheme.shapes.small) {
Row(modifier.padding(NotoTheme.dimensions.medium), horizontalArrangement = Arrangement.spacedBy(NotoTheme.dimensions.medium)) {
SettingsItemContent(title, titleColor, type, painter, painterColor, description, descriptionMaxLines, equalWeights)
SettingsItemContent(title, titleColor, type, painter, painterColor, contentScale, description, descriptionMaxLines, equalWeights)
}
}
}
Expand All @@ -71,19 +75,31 @@ private fun RowScope.SettingsItemContent(
type: SettingsItemType,
painter: Painter?,
painterColor: Color,
contentScale: ContentScale,
description: String?,
descriptionMaxLines: Int,
equalWeights: Boolean,
) {
if (painter != null) {
Icon(
painter = painter,
contentDescription = title,
modifier = Modifier
.size(IconSize)
.clip(MaterialTheme.shapes.extraSmall),
tint = painterColor,
)
if (contentScale == ContentScale.Fit) {
Icon(
painter = painter,
contentDescription = title,
modifier = Modifier
.size(IconSize)
.clip(MaterialTheme.shapes.extraSmall),
tint = painterColor,
)
} else {
Image(
painter = painter,
contentDescription = title,
modifier = Modifier
.size(IconSize)
.clip(MaterialTheme.shapes.extraSmall),
contentScale = contentScale,
)
}
}

Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(NotoTheme.dimensions.small)) {
Expand All @@ -109,6 +125,7 @@ private fun RowScope.SettingsItemContent(
modifier = if (equalWeights) Modifier.weight(1F) else Modifier
)
}

is SettingsItemType.Switch -> {
Spacer(Modifier.width(NotoTheme.dimensions.medium))
Switch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.activity.addCallback
import androidx.compose.runtime.Composable
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
Expand Down Expand Up @@ -61,6 +62,7 @@ class TranslationsSettingsFragment : Fragment() {
type = SettingsItemType.Text(context.stringResource(translation.language.toResource())),
painter = painterResource(id = translation.iconId),
equalWeights = false,
contentScale = ContentScale.Crop,
)

translation.translators.forEach { translator ->
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_china.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:width="32dp"
android:viewportWidth="640"
android:viewportHeight="480">
<path
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_czech.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
android:viewportHeight="480"
android:viewportWidth="640"
android:height="24dp"
android:width="24dp">
android:width="32dp">
<path
android:fillColor="#fff"
android:pathData="M0,0h640v240H0z" />
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_france.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:width="32dp"
android:viewportHeight="480"
android:viewportWidth="640">
<path
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_germany.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:width="32dp"
android:viewportHeight="480"
android:viewportWidth="640">
<path
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_lithuania.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:width="32dp"
android:viewportWidth="640"
android:viewportHeight="480">
<path
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_saudi_arabia.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:width="32dp"
android:viewportWidth="640"
android:viewportHeight="480">
<group>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_spain.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:width="32dp"
android:viewportHeight="480"
android:viewportWidth="640">
<path
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_turkey.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:width="32dp"
android:viewportHeight="480"
android:viewportWidth="640">
<path
Expand Down

0 comments on commit a36f934

Please sign in to comment.