-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Mihai-Cristian Condrea
committed
Jun 2, 2024
1 parent
f75d276
commit d8f79b8
Showing
28 changed files
with
693 additions
and
434 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
111 changes: 111 additions & 0 deletions
111
app/src/main/kotlin/com/d4rk/cleaner/dialogs/LanguageDialogComposable.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,111 @@ | ||
package com.d4rk.cleaner.dialogs | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.outlined.Info | ||
import androidx.compose.material.icons.outlined.Language | ||
import androidx.compose.material3.AlertDialog | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.RadioButton | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TextButton | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.MutableState | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringArrayResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import com.d4rk.cleaner.R | ||
import com.d4rk.cleaner.data.store.DataStore | ||
import kotlinx.coroutines.flow.firstOrNull | ||
|
||
@Composable | ||
fun LanguageDialog( | ||
dataStore: DataStore , onDismiss: () -> Unit , onLanguageSelected: (String) -> Unit | ||
) { | ||
val selectedLanguage = remember { mutableStateOf("") } | ||
val languageEntries = stringArrayResource(R.array.preference_language_entries).toList() | ||
val languageValues = stringArrayResource(R.array.preference_language_values).toList() | ||
|
||
AlertDialog(onDismissRequest = onDismiss, text = { | ||
LanguageDialogContent( | ||
selectedLanguage, dataStore, languageEntries, languageValues | ||
) | ||
}, icon = { | ||
Icon(Icons.Outlined.Language, contentDescription = null) | ||
}, confirmButton = { | ||
TextButton(onClick = { | ||
onLanguageSelected(selectedLanguage.value) | ||
onDismiss() | ||
}) { | ||
Text(stringResource(android.R.string.ok)) | ||
} | ||
}, dismissButton = { | ||
TextButton(onClick = onDismiss) { | ||
Text(stringResource(android.R.string.cancel)) | ||
} | ||
}) | ||
} | ||
|
||
@Composable | ||
fun LanguageDialogContent( | ||
selectedLanguage: MutableState<String>, | ||
dataStore: DataStore, | ||
languageEntries: List<String>, | ||
languageValues: List<String> | ||
) { | ||
LaunchedEffect(Unit) { | ||
selectedLanguage.value = dataStore.getLanguage().firstOrNull() ?: "" | ||
} | ||
|
||
Column { | ||
Text(stringResource(id = R.string.dialog_language_subtitle)) | ||
Box( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.weight(1f) | ||
) { | ||
LazyColumn { | ||
items(languageEntries.size) { index -> | ||
Row( | ||
Modifier.fillMaxWidth(), | ||
verticalAlignment = Alignment.CenterVertically, | ||
horizontalArrangement = Arrangement.Start | ||
) { | ||
RadioButton( | ||
selected = selectedLanguage.value == languageValues[index], | ||
onClick = { | ||
selectedLanguage.value = languageValues[index] | ||
}) | ||
Text( | ||
modifier = Modifier.padding(start = 8.dp), | ||
text = languageEntries[index], | ||
style = MaterialTheme.typography.bodyMedium.merge() | ||
) | ||
} | ||
} | ||
} | ||
} | ||
Spacer(modifier = Modifier.height(24.dp)) | ||
Icon(imageVector = Icons.Outlined.Info, contentDescription = null) | ||
Spacer(modifier = Modifier.height(12.dp)) | ||
Text(stringResource(id = R.string.dialog_info_language)) | ||
} | ||
|
||
LaunchedEffect(selectedLanguage.value) { | ||
dataStore.saveLanguage(selectedLanguage.value) | ||
} | ||
} |
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
9 changes: 4 additions & 5 deletions
9
app/src/main/kotlin/com/d4rk/cleaner/ui/settings/about/AboutSettingsActivity.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
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
6 changes: 3 additions & 3 deletions
6
app/src/main/kotlin/com/d4rk/cleaner/ui/settings/advanced/AdvancedSettingsActivity.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
Oops, something went wrong.