Commit e300d981 authored by Matyáš Latner's avatar Matyáš Latner

Merge branch 'feature-languagescreen' into 'V3.4'

#590, #627 Language choose dialog

* If language not supported, choose dialog will appear
* Removed option for "system language" in side menu

See merge request !510
parents 53fad295 91d601d3
......@@ -49,6 +49,7 @@ import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.screen.loader.IConnectionManager;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.Utility;
import cz.nic.tablexia.util.ui.button.StandardTablexiaButton;
import cz.nic.tablexia.util.ui.QRCodeScanner;
import cz.nic.tablexia.util.ui.button.TablexiaButton;
import cz.nic.tablexia.util.ui.dialog.TablexiaComponentDialog;
......@@ -60,6 +61,7 @@ import cz.nic.tablexia.util.ui.dialog.components.DimmerDialogComponent;
import cz.nic.tablexia.util.ui.dialog.components.FixedSpaceContentDialogComponent;
import cz.nic.tablexia.util.ui.dialog.components.PositiveNegativeButtonContentDialogComponent;
import cz.nic.tablexia.util.ui.dialog.components.ResizableSpaceContentDialogComponent;
import cz.nic.tablexia.util.ui.dialog.components.SingleButtonContentDialogComponent;
import cz.nic.tablexia.util.ui.dialog.components.TablexiaDialogComponentAdapter;
import cz.nic.tablexia.util.ui.dialog.components.TextContentDialogComponent;
......@@ -73,6 +75,8 @@ public class Tablexia extends TablexiaApplication {
public static final String ERROR_DIALOG_BACKGROUND_INTERNAL = INTERNAL_GFX_ASSETS_PATH + "dialog_square_borderlines.9.png";
public static final int ERROR_DIALOG_WIDTH = 460;
public static final int ERROR_DIALOG_HEIGHT = 300;
public static final int LOCALE_DIALOG_WIDTH = 320;
public static final int LOCALE_DIALOG_HEIGHT = 320;
public static final float ERROR_DIALOG_DIMMER = 0.7f;
public static final int BACK_BUTTON_SIZE = 50;
......@@ -97,7 +101,9 @@ public class Tablexia extends TablexiaApplication {
private boolean reset;
private boolean loadingComplete = false;
private boolean errorDialogShown = false;
private TablexiaComponentDialog dialog;
private boolean languageDialogShown = false;
private TablexiaComponentDialog errorDialog;
private TablexiaComponentDialog languageDialog;
public static class SQLConnectionType {
......@@ -379,9 +385,10 @@ public class Tablexia extends TablexiaApplication {
if (!loadingComplete) {
// load internal assets
if (!ApplicationFontManager.getInstance().update()) return;
if (!ApplicationTextManager.getInstance().update()) return;
if (!ApplicationInternalSoundManager.getInstance().update()) return;
if (!ApplicationInternalSoundManager.getInstance().update()) return;
if (!ApplicationInternalTextureManager.getInstance().update()) return;
if (!processLanguageChoose()) return;
if (!ApplicationTextManager.getInstance().update()) return;
// load external assets
if (!zipAssetLoader.update()) return;
......@@ -508,8 +515,35 @@ public class Tablexia extends TablexiaApplication {
}
});
components.add(new FixedSpaceContentDialogComponent());
dialog = TablexiaComponentDialogFactory.getInstance().createDialog(components.toArray(new TablexiaDialogComponentAdapter[]{}));
dialog.show(dialogWidth, dialogHeight);
errorDialog = TablexiaComponentDialogFactory.getInstance().createDialog(components.toArray(new TablexiaDialogComponentAdapter[]{}));
errorDialog.show(dialogWidth, dialogHeight);
}
private void showLanguageChooseDialog() {
languageDialogShown = true;
ArrayList<TablexiaDialogComponentAdapter> adapters = new ArrayList<>();
adapters.add(new CenterPositionDialogComponent());
for(final TablexiaSettings.LocaleDefinition localeDefinition : TablexiaSettings.LocaleDefinition.values()) {
if(localeDefinition.getNativeLocaleName() != null) {
adapters.add(new SingleButtonContentDialogComponent(
localeDefinition.getNativeLocaleName(),
true,
StandardTablexiaButton.TablexiaButtonType.GREEN,
new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
TablexiaSettings.getInstance().setLocale(localeDefinition);
TablexiaSettings.languageChosen = true;
languageDialog.hide();
}
}
));
}
}
languageDialog = TablexiaComponentDialogFactory.getInstance().createDialog(adapters.toArray(new TablexiaDialogComponentAdapter[]{}));
languageDialog.show(LOCALE_DIALOG_WIDTH, LOCALE_DIALOG_HEIGHT);
}
private void returnToLastLocale() {
......@@ -526,12 +560,19 @@ public class Tablexia extends TablexiaApplication {
if (loaderError != null && !errorDialogShown) {
showLoaderErrorDialog(ERROR_DIALOG_WIDTH, ERROR_DIALOG_HEIGHT, loaderError);
errorDialogShown = true;
} else if (loaderError == null && dialog != null) {
dialog.hide();
} else if (loaderError == null && errorDialog != null) {
errorDialog.hide();
}
return errorDialogShown;
}
private boolean processLanguageChoose() {
if(!languageDialogShown && !TablexiaSettings.languageChosen) {
showLanguageChooseDialog();
}
return TablexiaSettings.languageChosen;
}
public static class ApplicationLoadingCompleteEvent implements ApplicationEvent {
private ApplicationLoadingCompleteEvent(){}
}
......
......@@ -82,6 +82,7 @@ public class TablexiaSettings {
private User selectedUser;
private boolean soundMuted = false;
protected static boolean languageChosen = false;
public enum Platform {
......@@ -207,6 +208,7 @@ public class TablexiaSettings {
BUILD_TYPE = buildType;
HAS_SOFT_BACK_BUTTON = hasSoftBackButton;
this.systemLocale = LocaleDefinition.getLocaleDefinitionForLocale(systemLocale);
languageChosen = selectedLocale == LocaleDefinition.FALLBACK_VARIANT || languageChosen;
}
public static TablexiaSettings getInstance() {
......@@ -244,6 +246,13 @@ public class TablexiaSettings {
lastLocale = LocaleDefinition.getLocaleDefinitionForKey(preferences.getString(LAST_LOCALE_KEY));
selectedLocale = LocaleDefinition.getLocaleDefinitionForKey(preferences.getString(LOCALE_KEY));
selectedUser = reset ? null : UserDAO.selectUser(preferences.getLong(SELECTED_USER));
languageChosen = selectedLocale != LocaleDefinition.FALLBACK_VARIANT || languageChosen;
//If system speech is supported and is not default speech (czech), set flag.
//If czech was fallback variant, correct flag is already set.
for (LocaleDefinition localeDefinition : LocaleDefinition.values()) {
if (localeDefinition == getSystemLocale() && localeDefinition != LocaleDefinition.cs_CZ) languageChosen = true;
}
Calendar calendar = GregorianCalendar.getInstance();
winterMode = (calendar.get(Calendar.MONTH) > WINTER_MODE_START_MONTH) || (calendar.get(Calendar.MONTH) < WINTER_MODE_END_MONTH);
......@@ -424,15 +433,15 @@ public class TablexiaSettings {
}
public enum LocaleDefinition {
SYSTEM (null, null, "system", ApplicationTextManager.ApplicationTextsAssets.LANGUAGE_SYSTEM, true) {
SYSTEM (null, null, "system", ApplicationTextManager.ApplicationTextsAssets.LANGUAGE_SYSTEM, true, null, false) {
@Override
public int getLocaleNumber() {
return getLocaleDefinitionForLocale(instance.systemLocale.locale).modelLocaleDefinition.number();
}
},
cs_CZ (cz.nic.tablexia.shared.model.definitions.LocaleDefinition.cs_CZ, new Locale("cs", "CZ"), "cs_CZ", ApplicationTextManager.ApplicationTextsAssets.LANGUAGE_CZECH, true),
sk_SK (cz.nic.tablexia.shared.model.definitions.LocaleDefinition.sk_SK, new Locale("sk", "SK"), "sk_SK", ApplicationTextManager.ApplicationTextsAssets.LANGUAGE_SLOVAK, true),
de_DE (cz.nic.tablexia.shared.model.definitions.LocaleDefinition.de_DE, new Locale("de", "DE"), "de_DE", ApplicationTextManager.ApplicationTextsAssets.LANGUAGE_GERMAN, true);
cs_CZ (cz.nic.tablexia.shared.model.definitions.LocaleDefinition.cs_CZ, new Locale("cs", "CZ"), "cs_CZ", ApplicationTextManager.ApplicationTextsAssets.LANGUAGE_CZECH, true, "čeština", true),
sk_SK (cz.nic.tablexia.shared.model.definitions.LocaleDefinition.sk_SK, new Locale("sk", "SK"), "sk_SK", ApplicationTextManager.ApplicationTextsAssets.LANGUAGE_SLOVAK, true, "slovenčina", true),
de_DE (cz.nic.tablexia.shared.model.definitions.LocaleDefinition.de_DE, new Locale("de", "DE"), "de_DE", ApplicationTextManager.ApplicationTextsAssets.LANGUAGE_GERMAN, true, "deutsch", true);
public final static LocaleDefinition DEFAULT_LOCALE = LocaleDefinition.cs_CZ;
private final static LocaleDefinition FALLBACK_VARIANT = LocaleDefinition.SYSTEM;
......@@ -442,15 +451,19 @@ public class TablexiaSettings {
private final String localeKey;
private final String descriptionKey;
private final boolean enabled;
private final String nativeLocaleName;
private final boolean selectable;
private static List<LocaleDefinition> enabledLocaleDefinitions;
LocaleDefinition(cz.nic.tablexia.shared.model.definitions.LocaleDefinition modelLocaleDefinition, Locale locale, String localeKey, String descriptionKey, boolean enabled) {
LocaleDefinition(cz.nic.tablexia.shared.model.definitions.LocaleDefinition modelLocaleDefinition, Locale locale, String localeKey, String descriptionKey, boolean enabled, String nativeLocaleName, boolean selectable) {
this.modelLocaleDefinition = modelLocaleDefinition;
this.locale = locale;
this.localeKey = localeKey;
this.descriptionKey = descriptionKey;
this.enabled = enabled;
this.nativeLocaleName = nativeLocaleName;
this.selectable = selectable;
}
public String getLocaleKey() {
......@@ -465,6 +478,10 @@ public class TablexiaSettings {
return descriptionKey;
}
public String getNativeLocaleName() {
return nativeLocaleName;
}
public Locale getLocale() {
return locale != null ? locale : instance.systemLocale.locale;
}
......@@ -490,9 +507,11 @@ public class TablexiaSettings {
public static LocaleDefinition getLocaleDefinitionForLocale(Locale locale) {
for (LocaleDefinition localeDefinition : getEnabledLocaleDefinitions()) {
if (localeDefinition.locale != null && localeDefinition.locale.equals(locale)) {
languageChosen = true;
return localeDefinition;
}
}
languageChosen = false;
return DEFAULT_LOCALE;
}
......@@ -507,6 +526,16 @@ public class TablexiaSettings {
}
return enabledLocaleDefinitions;
}
public static List<LocaleDefinition> getSelectableLocaleDefinitions() {
List<LocaleDefinition> selectableLocaleDefinitions = new ArrayList<>();
for (LocaleDefinition localeDefinition : LocaleDefinition.values()) {
if (localeDefinition.selectable) {
selectableLocaleDefinitions.add(localeDefinition);
}
}
return selectableLocaleDefinitions;
}
}
public void setLocale(LocaleDefinition localeDefinition) {
......@@ -541,6 +570,10 @@ public class TablexiaSettings {
return selectedLocale.getLocale();
}
public LocaleDefinition getSystemLocale() {
return systemLocale;
}
//////////////////////////// SCREEN SIZE
......
......@@ -97,7 +97,7 @@ public class LocaleSelectBox extends AbstractTablexiaSelectBox<LocaleSelectBox.L
LocaleItem selectedLocaleItem = null;
List<LocaleItem> localeItems = new ArrayList<LocaleItem>();
for (TablexiaSettings.LocaleDefinition localeDefinition: TablexiaSettings.LocaleDefinition.getEnabledLocaleDefinitions()) {
for (TablexiaSettings.LocaleDefinition localeDefinition: TablexiaSettings.LocaleDefinition.getSelectableLocaleDefinitions()) {
LocaleItem localeItem = new LocaleItem(localeDefinition);
if (localeDefinition.equals(TablexiaSettings.getInstance().getLocaleDefinition())) {
selectedLocaleItem = localeItem;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment