Skip to content

Commit

Permalink
Grammatical gender (#230)
Browse files Browse the repository at this point in the history
* Grammatical gender

* Grammatical gender
  • Loading branch information
michaelbel authored Feb 25, 2024
1 parent f39f1bd commit 02ded41
Show file tree
Hide file tree
Showing 30 changed files with 395 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.michaelbel.movies.common.gender

import android.content.res.Configuration
import org.michaelbel.movies.common.gender.exceptions.InvalidGenderException

sealed class GrammaticalGender(
val value: Int
) {
data object NotSpecified: GrammaticalGender(Configuration.GRAMMATICAL_GENDER_NOT_SPECIFIED)

data object Neutral: GrammaticalGender(Configuration.GRAMMATICAL_GENDER_NEUTRAL)

data object Feminine: GrammaticalGender(Configuration.GRAMMATICAL_GENDER_FEMININE)

data object Masculine: GrammaticalGender(Configuration.GRAMMATICAL_GENDER_MASCULINE)

companion object {
val VALUES = listOf(
NotSpecified,
Neutral,
Feminine,
Masculine
)

fun transform(gender: Int): GrammaticalGender {
return when (gender) {
Configuration.GRAMMATICAL_GENDER_NOT_SPECIFIED -> NotSpecified
Configuration.GRAMMATICAL_GENDER_NEUTRAL -> Neutral
Configuration.GRAMMATICAL_GENDER_FEMININE -> Feminine
Configuration.GRAMMATICAL_GENDER_MASCULINE -> Masculine
else -> throw InvalidGenderException
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.michaelbel.movies.common.gender.exceptions

internal data object InvalidGenderException: Exception("Invalid gender")
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ object MoviesIcons {
@DrawableRes val MovieFilter24 = R.drawable.ic_movie_filter_24
@DrawableRes val FileDownload24 = R.drawable.ic_file_download_24
@DrawableRes val AdultOutline = R.drawable.ic_18_up_rating_outline_24
@DrawableRes val Cat = R.drawable.ic_cat_24

val AccountCircle = Icons.Outlined.AccountCircle
val ArrowBack = Icons.AutoMirrored.Outlined.ArrowBack
Expand Down
11 changes: 11 additions & 0 deletions core/ui/src/main/res/drawable/ic_cat_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFF"
android:pathData="M12,8L10.67,8.09C9.81,7.07 7.4,4.5 5,4.5C5,4.5 3.03,7.46 4.96,11.41C4.41,12.24 4.07,12.67 4,13.66L2.07,13.95L2.28,14.93L4.04,14.67L4.18,15.38L2.61,16.32L3.08,17.21L4.53,16.32C5.68,18.76 8.59,20 12,20C15.41,20 18.32,18.76 19.47,16.32L20.92,17.21L21.39,16.32L19.82,15.38L19.96,14.67L21.72,14.93L21.93,13.95L20,13.66C19.93,12.67 19.59,12.24 19.04,11.41C20.97,7.46 19,4.5 19,4.5C16.6,4.5 14.19,7.07 13.33,8.09L12,8M9,11A1,1 0 0,1 10,12A1,1 0 0,1 9,13A1,1 0 0,1 8,12A1,1 0 0,1 9,11M15,11A1,1 0 0,1 16,12A1,1 0 0,1 15,13A1,1 0 0,1 14,12A1,1 0 0,1 15,11M11,14H13L12.3,15.39C12.5,16.03 13.06,16.5 13.75,16.5A1.5,1.5 0 0,0 15.25,15H15.75A2,2 0 0,1 13.75,17C13,17 12.35,16.59 12,16V16H12C11.65,16.59 11,17 10.25,17A2,2 0 0,1 8.25,15H8.75A1.5,1.5 0 0,0 10.25,16.5C10.94,16.5 11.5,16.03 11.7,15.39L11,14Z" />
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class SettingsViewModel @Inject constructor(
private val reviewService: ReviewService
): BaseViewModel(), DefaultLifecycleObserver {

val isGrammaticalGenderFeatureEnabled = Build.VERSION.SDK_INT >= 34

val isDynamicColorsFeatureEnabled = Build.VERSION.SDK_INT >= 31

val isPostNotificationsFeatureEnabled = Build.VERSION.SDK_INT >= 33
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.michaelbel.movies.settings.ktx

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import org.michaelbel.movies.common.gender.GrammaticalGender
import org.michaelbel.movies.settings_impl.R

internal val GrammaticalGender.genderText: String
@Composable get() = when (this) {
is GrammaticalGender.NotSpecified -> stringResource(R.string.settings_gender_not_specified)
is GrammaticalGender.Neutral -> stringResource(R.string.settings_gender_neutral)
is GrammaticalGender.Feminine -> stringResource(R.string.settings_gender_feminine)
is GrammaticalGender.Masculine -> stringResource(R.string.settings_gender_masculine)
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import org.michaelbel.movies.ui.preview.provider.IconAliasPreviewParameterProvid
import org.michaelbel.movies.ui.theme.MoviesTheme

@Composable
fun AppIconBox(
internal fun AppIconBox(
iconAlias: IconAlias,
modifier: Modifier = Modifier
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.michaelbel.movies.ui.preview.DevicePreviews
import org.michaelbel.movies.ui.theme.MoviesTheme

@Composable
fun SettingsAppIconBox(
internal fun SettingsAppIconBox(
onAppIconChanged: (IconAlias) -> Unit,
modifier: Modifier = Modifier
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import androidx.compose.foundation.layout.height
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
Expand All @@ -23,12 +26,12 @@ import org.michaelbel.movies.ui.theme.MoviesTheme
import org.michaelbel.movies.widget.ktx.pin

@Composable
fun SettingsAppWidgetBox(
internal fun SettingsAppWidgetBox(
modifier: Modifier = Modifier
) {
val context = LocalContext.current
val appWidgetManager = AppWidgetManager.getInstance(context)
val appWidgetProvider = appWidgetManager.getInstalledProvidersForPackage(context.packageName, null).first()
val appWidgetManager by remember { mutableStateOf(AppWidgetManager.getInstance(context)) }
val appWidgetProvider by remember { mutableStateOf(appWidgetManager.getInstalledProvidersForPackage(context.packageName, null).first()) }

ConstraintLayout(
modifier = modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.michaelbel.movies.ui.preview.provider.AppearancePreviewParameterProvi
import org.michaelbel.movies.ui.theme.MoviesTheme

@Composable
fun SettingsAppearanceBox(
internal fun SettingsAppearanceBox(
currentFeedView: FeedView,
onFeedViewSelect: (FeedView) -> Unit,
modifier: Modifier = Modifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Text
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.RadioButton
import androidx.compose.material3.RadioButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
Expand All @@ -35,7 +35,7 @@ import org.michaelbel.movies.ui.preview.provider.AppearancePreviewParameterProvi
import org.michaelbel.movies.ui.theme.MoviesTheme

@Composable
fun SettingsAppearanceDialog(
internal fun SettingsAppearanceDialog(
currentFeedView: FeedView,
onFeedViewSelect: (FeedView) -> Unit,
onDismissRequest: () -> Unit
Expand Down Expand Up @@ -96,7 +96,7 @@ private fun SettingAppearanceDialogContent(
Column(
modifier = modifier.verticalScroll(scrollState)
) {
FeedView.VALUES.forEach { feedView: FeedView ->
FeedView.VALUES.forEach { feedView ->
Row(
modifier = Modifier
.fillMaxWidth()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.michaelbel.movies.ui.preview.provider.BooleanPreviewParameterProvider
import org.michaelbel.movies.ui.theme.MoviesTheme

@Composable
fun SettingsDynamicColorsBox(
internal fun SettingsDynamicColorsBox(
isDynamicColorsEnabled: Boolean,
modifier: Modifier = Modifier
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package org.michaelbel.movies.settings.ui

import android.app.GrammaticalInflectionManager
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.constraintlayout.compose.ConstraintLayout
import androidx.constraintlayout.compose.Dimension
import org.michaelbel.movies.common.gender.GrammaticalGender
import org.michaelbel.movies.common.theme.AppTheme
import org.michaelbel.movies.settings.ktx.genderText
import org.michaelbel.movies.settings_impl.R
import org.michaelbel.movies.ui.preview.DevicePreviews
import org.michaelbel.movies.ui.theme.MoviesTheme

@Composable
internal fun SettingsGenderBox(
modifier: Modifier = Modifier,
) {
val context = LocalContext.current
val grammaticalInflectionManager by remember { mutableStateOf(context.getSystemService(GrammaticalInflectionManager::class.java)) }
val grammaticalGender by remember { mutableStateOf(grammaticalInflectionManager.applicationGrammaticalGender) }
val currentGrammaticalGender by remember { mutableStateOf(GrammaticalGender.transform(grammaticalGender)) }

var genderDialog by remember { mutableStateOf(false) }

if (genderDialog) {
SettingsGenderDialog(
onDismissRequest = {
genderDialog = false
}
)
}

ConstraintLayout(
modifier = modifier
.fillMaxWidth()
.height(52.dp)
.clickable {
genderDialog = true
}
.testTag("ConstraintLayout")
) {
val (title, value) = createRefs()

Text(
text = stringResource(R.string.settings_gender),
modifier = Modifier
.constrainAs(title) {
width = Dimension.wrapContent
height = Dimension.wrapContent
start.linkTo(parent.start, 16.dp)
top.linkTo(parent.top)
bottom.linkTo(parent.bottom)
}
.testTag("TitleText"),
style = MaterialTheme.typography.bodyLarge.copy(MaterialTheme.colorScheme.onPrimaryContainer)
)

Text(
text = currentGrammaticalGender.genderText,
modifier = Modifier
.constrainAs(value) {
width = Dimension.wrapContent
height = Dimension.wrapContent
top.linkTo(parent.top)
end.linkTo(parent.end, 16.dp)
bottom.linkTo(parent.bottom)
}
.testTag("ValueText"),
style = MaterialTheme.typography.bodyLarge.copy(MaterialTheme.colorScheme.primary)
)
}
}

@Composable
@DevicePreviews
private fun SettingsGenderBoxPreview() {
MoviesTheme {
SettingsGenderBox(
modifier = Modifier
.fillMaxWidth()
.height(52.dp)
.background(MaterialTheme.colorScheme.primaryContainer)
)
}
}

@Composable
@Preview
private fun SettingsGenderBoxAmoledPreview() {
MoviesTheme(
theme = AppTheme.Amoled
) {
SettingsGenderBox(
modifier = Modifier
.fillMaxWidth()
.height(52.dp)
.background(MaterialTheme.colorScheme.primaryContainer)
)
}
}
Loading

0 comments on commit 02ded41

Please sign in to comment.