-
Notifications
You must be signed in to change notification settings - Fork 664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Migrate Settings from XML to compose #2601
Conversation
MaterialAlertDialogBuilder(requireContext()).setTitle(getString(R.string.choose_language)) | ||
.setSingleChoiceItems( | ||
resources.getStringArray(R.array.languages), | ||
getSelectedLanguageIndex(), | ||
) { dialog, selectedLanguageIndex -> | ||
val selectedLanguageValue = | ||
resources.getStringArray(R.array.languages_value)[selectedLanguageIndex] | ||
|
||
val sharedPreferences = | ||
PreferenceManager.getDefaultSharedPreferences(requireContext()) | ||
sharedPreferences.edit() | ||
.putString(getString(R.string.language_type), selectedLanguageValue).apply() | ||
|
||
dialog.dismiss() | ||
}.show() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Migrate Alert dialogs as well in compose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
private fun changeTheme() { | ||
val previouslySelectedTheme = prefsHelper.appTheme | ||
|
||
MaterialAlertDialogBuilder(requireContext()).setTitle(getString(R.string.change_app_theme)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
migrate dialog to compose
c0cdb8b
to
f8250e9
Compare
fix: Migrate Settings from XML to compose openMF#2570 fix: Migrate Settings from XML to compose openMF#2570 refactor: Migrate Settings from XML to compose openMF#2570 fix: Migrate Settings from XML to compose openMF#2570 migrate Settings to compose openMF#2570 migrate Settings to compose openMF#2570
private fun changeLanguage() { | ||
withMutableSnapshot { | ||
viewModel.invokeLanguageUpdate = true | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do this in compose screen.
private fun updateLanguage(language: String) { | ||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) | ||
sharedPreferences.edit().putString(getString(R.string.language_type), language).apply() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update shared prefs from compose screen only
private fun getSelectedLanguageIndex(): Int { | ||
var selectedLanguageValue: String? = | ||
prefsHelper.getString(getString(R.string.language_type), null) | ||
val languageValuesArray = resources.getStringArray(R.array.languages_value) | ||
|
||
if (!(languageValuesArray.contains(selectedLanguageValue))) { | ||
if (languageValuesArray.contains(Locale.getDefault().language)) { | ||
selectedLanguageValue = "System_Language" | ||
} else selectedLanguageValue = "en" | ||
} | ||
return languageValuesArray.indexOf(selectedLanguageValue) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in compose screen
private fun getCurrentTheme() : Int{ | ||
return prefsHelper.appTheme | ||
} | ||
|
||
private fun updateTheme(selectedTheme : Int){ | ||
prefsHelper.applyTheme(AppTheme.fromIndex(selectedTheme)) | ||
prefsHelper.applySavedTheme() | ||
} | ||
|
||
private fun changeTheme(){ | ||
withMutableSnapshot { | ||
viewModel.invokeThemeUpdate = true | ||
} | ||
} | ||
|
||
private fun updateEndpoint() { | ||
withMutableSnapshot { | ||
viewModel.invokeEndpointUpdate = true | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in compose screen
) { | ||
val context = LocalContext.current | ||
|
||
Scaffold( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use MF SCaffold
Fixes #2570
Screencast_06_04_2024_03.29.22_AM.webm
Apply the
AndroidStyle.xml
style template to your code in Android Studio.Run the unit tests with
./gradlew check
to make sure you didn't break anythingIf you have multiple commits please combine them into one commit by squashing them.