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

IDE-235 Language change confirmation #4985

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ class FormulaEditorTouchesActorOrObjectTest {
pressBack()
pressBack()

openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext())
openActionBarOverflowOrOptionsMenu(getInstrumentation().targetContext)
hannesweilharter marked this conversation as resolved.
Show resolved Hide resolved
onView(withText(R.string.settings)).perform(click())
onView(withText(R.string.preference_title_language)).perform(click())
onData(Matchers.hasToString(germanLocale.getDisplayName(germanLocale))).perform(click())
onView(withText(R.string.confirm)).perform(click())
onView(withText(applicationContext.getString(R.string.main_menu_programs))).perform(click())
onView(withText(projectName)).perform(click())
onView(withText(spriteName)).perform(click())
Expand All @@ -140,7 +141,7 @@ class FormulaEditorTouchesActorOrObjectTest {
onFormulaEditor().checkShows(generateFormulaString())
}

fun generateFormulaString(): String =
private fun generateFormulaString(): String =
applicationContext.getString(R.string.formula_editor_function_collision) +
"(" + applicationContext.getString(R.string.background) + ")"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* An additional term exception under section 7 of the GNU Affero
* General Public License, version 3, is available at
* http://developer.catrobat.org/license_additional_term
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package android.preference

import android.app.AlertDialog
import android.content.Context
import android.util.AttributeSet
import org.catrobat.catroid.R

class LanguageSettingListPreference(context: Context, attrs: AttributeSet) : ListPreference(context, attrs) {

private var mClickedDialogEntryIndex: Int = 0

init {
setPositiveButtonText(R.string.confirm)
setNegativeButtonText(R.string.cancel)
}

private fun getValueIndex(): Int = findIndexOfValue(this.value.toString())

override fun onPrepareDialogBuilder(builder: AlertDialog.Builder?) {
super.onPrepareDialogBuilder(builder)

mClickedDialogEntryIndex = getValueIndex()
builder?.setSingleChoiceItems(this.entries, mClickedDialogEntryIndex) { _, which ->
mClickedDialogEntryIndex = which
}

builder?.setPositiveButton(positiveButtonText) { _, _ ->
val selectedLanguageTag = entryValues[mClickedDialogEntryIndex].toString()
if (callChangeListener(selectedLanguageTag)) {
value = selectedLanguageTag
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -30,7 +30,7 @@
import android.content.res.Resources;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.LanguageSettingListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
Expand Down Expand Up @@ -528,7 +528,8 @@ private void setLanguage() {
String[] languages = new String[languagesNames.size()];
languagesNames.toArray(languages);

final ListPreference listPreference = (ListPreference) findPreference(SETTINGS_MULTILINGUAL);
final LanguageSettingListPreference listPreference =
(LanguageSettingListPreference) findPreference(SETTINGS_MULTILINGUAL);
listPreference.setEntries(languages);
listPreference.setEntryValues(LANGUAGE_TAGS);
listPreference.setOnPreferenceChangeListener((preference, languageTag) -> {
Expand Down
4 changes: 2 additions & 2 deletions catroid/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Catroid: An on-device visual programming system for Android devices
~ Copyright (C) 2010-2022 The Catrobat Team
~ Copyright (C) 2010-2024 The Catrobat Team
~ (<http://developer.catrobat.org/credits>)
~
~ This program is free software: you can redistribute it and/or modify
Expand All @@ -25,7 +25,7 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">

<ListPreference
<LanguageSettingListPreference
android:defaultValue="false"
android:key="setting_multilingual"
android:summary="@string/preference_description_language"
Expand Down