-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3145659
commit 46b85f8
Showing
9 changed files
with
193 additions
and
10 deletions.
There are no files selected for viewing
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
144 changes: 144 additions & 0 deletions
144
...rc/main/kotlin/ir/thatsmejavad/backgroundable/screens/settings/language/LanguageScreen.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,144 @@ | ||
package ir.thatsmejavad.backgroundable.screens.settings.language | ||
|
||
import androidx.appcompat.app.AppCompatDelegate | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.automirrored.filled.ArrowBack | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.MediumTopAppBar | ||
import androidx.compose.material3.RadioButton | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TopAppBarDefaults | ||
import androidx.compose.material3.rememberTopAppBarState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.input.nestedscroll.nestedScroll | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import androidx.core.os.LocaleListCompat | ||
import androidx.navigation.NavController | ||
import ir.thatsmejavad.backgroundable.R | ||
import ir.thatsmejavad.backgroundable.common.ui.BackgroundableScaffold | ||
|
||
@Composable | ||
fun LanguageScreen( | ||
navController: NavController, | ||
) { | ||
LanguageScreen( | ||
onBackClicked = { navController.navigateUp() }, | ||
) | ||
} | ||
|
||
@Composable | ||
private fun LanguageScreen( | ||
onBackClicked: () -> Unit, | ||
) { | ||
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior(rememberTopAppBarState()) | ||
|
||
val isPersianSelected = remember { | ||
AppCompatDelegate.getApplicationLocales().get(0)?.language == "fa" | ||
} | ||
BackgroundableScaffold( | ||
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), | ||
topBar = { | ||
MediumTopAppBar( | ||
title = { | ||
Text(text = stringResource(R.string.label_language)) | ||
}, | ||
navigationIcon = { | ||
IconButton(onClick = onBackClicked) { | ||
Icon( | ||
imageVector = Icons.AutoMirrored.Filled.ArrowBack, | ||
contentDescription = "Navigate back" | ||
) | ||
} | ||
}, | ||
scrollBehavior = scrollBehavior | ||
) | ||
} | ||
) { paddingValues -> | ||
Column( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(paddingValues) | ||
.verticalScroll(rememberScrollState()) | ||
.padding(vertical = 16.dp), | ||
verticalArrangement = Arrangement.spacedBy(24.dp) | ||
) { | ||
LanguageItem( | ||
text = stringResource(R.string.label_english_en), | ||
description = stringResource(R.string.label_english_lang_desc), | ||
isSelected = !isPersianSelected, | ||
onClick = { | ||
AppCompatDelegate.setApplicationLocales( | ||
LocaleListCompat.getEmptyLocaleList() | ||
) | ||
} | ||
) | ||
LanguageItem( | ||
text = stringResource(R.string.label_persian), | ||
description = stringResource(R.string.label_persian_lang_desc), | ||
isSelected = isPersianSelected, | ||
onClick = { | ||
AppCompatDelegate.setApplicationLocales( | ||
LocaleListCompat.forLanguageTags("fa") | ||
) | ||
} | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun LanguageItem( | ||
text: String, | ||
description: String, | ||
isSelected: Boolean, | ||
onClick: () -> Unit | ||
) { | ||
Row( | ||
modifier = Modifier | ||
.clickable(onClick = onClick) | ||
.fillMaxWidth() | ||
.padding( | ||
horizontal = 32.dp, | ||
vertical = 8.dp | ||
) | ||
) { | ||
Column { | ||
Text( | ||
text = text, | ||
style = MaterialTheme.typography.titleMedium, | ||
color = MaterialTheme.colorScheme.onSurface | ||
) | ||
|
||
Spacer(modifier = Modifier.size(8.dp)) | ||
|
||
Text( | ||
text = description, | ||
style = MaterialTheme.typography.titleSmall, | ||
color = MaterialTheme.colorScheme.primary | ||
) | ||
} | ||
|
||
Spacer(modifier = Modifier.weight(1f)) | ||
|
||
RadioButton( | ||
selected = isSelected, | ||
onClick = onClick | ||
) | ||
} | ||
} |
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,12 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="32dp" | ||
android:height="32dp" | ||
android:viewportWidth="32" | ||
android:viewportHeight="32"> | ||
<group> | ||
<clip-path android:pathData="M0,0h32v32h-32z" /> | ||
<path | ||
android:fillColor="#000" | ||
android:pathData="M15.987,2.667C8.627,2.667 2.667,8.64 2.667,16C2.667,23.36 8.627,29.333 15.987,29.333C23.36,29.333 29.333,23.36 29.333,16C29.333,8.64 23.36,2.667 15.987,2.667ZM25.227,10.667H21.293C20.867,9 20.253,7.4 19.453,5.92C21.907,6.76 23.947,8.467 25.227,10.667ZM16,5.387C17.107,6.987 17.973,8.76 18.547,10.667H13.453C14.027,8.76 14.893,6.987 16,5.387ZM5.68,18.667C5.467,17.813 5.333,16.92 5.333,16C5.333,15.08 5.467,14.187 5.68,13.333H10.187C10.08,14.213 10,15.093 10,16C10,16.907 10.08,17.787 10.187,18.667H5.68ZM6.773,21.333H10.707C11.133,23 11.747,24.6 12.547,26.08C10.093,25.24 8.053,23.547 6.773,21.333ZM10.707,10.667H6.773C8.053,8.453 10.093,6.76 12.547,5.92C11.747,7.4 11.133,9 10.707,10.667ZM16,26.613C14.893,25.013 14.027,23.24 13.453,21.333H18.547C17.973,23.24 17.107,25.013 16,26.613ZM19.12,18.667H12.88C12.76,17.787 12.667,16.907 12.667,16C12.667,15.093 12.76,14.2 12.88,13.333H19.12C19.24,14.2 19.333,15.093 19.333,16C19.333,16.907 19.24,17.787 19.12,18.667ZM19.453,26.08C20.253,24.6 20.867,23 21.293,21.333H25.227C23.947,23.533 21.907,25.24 19.453,26.08ZM21.813,18.667C21.92,17.787 22,16.907 22,16C22,15.093 21.92,14.213 21.813,13.333H26.32C26.533,14.187 26.667,15.08 26.667,16C26.667,16.92 26.533,17.813 26.32,18.667H21.813Z" /> | ||
</group> | ||
</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
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