Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

itsPronay
Copy link
Contributor

@itsPronay itsPronay commented Jun 3, 2024

Fixes #2570

xml compose
image image
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 anything

  • If you have multiple commits please combine them into one commit by squashing them.

@therajanmaurya
Copy link
Member

image Give 16dp end padding to update endpoint description

Comment on lines 113 to 127
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()
Copy link
Collaborator

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

Copy link
Contributor Author

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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

migrate dialog to compose

    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
@itsPronay itsPronay marked this pull request as ready for review June 14, 2024 17:19
Comment on lines 125 to 129
private fun changeLanguage() {
withMutableSnapshot {
viewModel.invokeLanguageUpdate = true
}
}
Copy link
Collaborator

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.

Comment on lines 131 to 134
private fun updateLanguage(language: String) {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
sharedPreferences.edit().putString(getString(R.string.language_type), language).apply()
}
Copy link
Collaborator

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

Comment on lines 136 to 147
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)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in compose screen

Comment on lines 149 to 168
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
}
}
Copy link
Collaborator

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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use MF SCaffold

@itsPronay itsPronay deleted the settings-1 branch June 23, 2024 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

refactor: Migrate Settings from XML to compose
3 participants