-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Grammatical gender * Grammatical gender
- Loading branch information
1 parent
f39f1bd
commit 02ded41
Showing
30 changed files
with
395 additions
and
21 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
core/common/src/main/kotlin/org/michaelbel/movies/common/gender/GrammaticalGender.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
.../src/main/kotlin/org/michaelbel/movies/common/gender/exceptions/InvalidGenderException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
.../settings-impl/src/main/kotlin/org/michaelbel/movies/settings/ktx/GrammaticalGenderKtx.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
feature/settings-impl/src/main/kotlin/org/michaelbel/movies/settings/ui/SettingsGenderBox.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) | ||
} | ||
} |
Oops, something went wrong.