Commit b6d77816 authored by Drahomír Karchňák's avatar Drahomír Karchňák

#448 Shows dialog when user download fails or user enters wrong UUID.

parent 40dd6cd7
......@@ -10,6 +10,7 @@ system_decline=Zrušit
system_exit=Konec
system_retry=Znovu
system_back=Zpět
system_understand=Rozumím
zipassetloader_error=Chyba: Nemohu stáhnout dodatečná data! Zkontrolujte prosím připojení k internetu.
zipassetloader_download_request: Právě využíváte mobilní připojení k internetu. Tablexia potřebuje stáhnout ~150 MB herních dat. Přejete si je stáhnout nyní ?
......@@ -39,7 +40,6 @@ usermenu_dialog_no = Ne
user_logout_message=Opravdu chcete odhlásit stávajícího uživatele?
preloader_title=Jak hrát?
confirm_button=Rozumím
gamedifficulty_name=Obtížnost:
gamedifficulty_tutorial=Cvičení
......@@ -207,6 +207,9 @@ user_rank_11=Vrchní rada
sync_request_dialog_text=Zadej číslo průkazu:
sync_request_button=Synchronizovat uživatele
sync_request_wrong_id=Špatně zadaný kód.
sync_request_error=Synchronizace se nezdařila, zkuste to prosím později.
game_runes_preloader1=Podívej se na symboly v\u00A0pásu vpravo.
game_runes_preloader2_easy=Najdi je na domech a\u00A0označ dřív, než ti dojde čas.
game_runes_preloader2_medium=Najdi na domech jejich zrcadlově otočené varianty a\u00A0označ je dřív, než ti dojde čas.
......
......@@ -10,6 +10,7 @@ system_decline=Beenden
system_exit=Verlassen
system_retry=Wieder
system_back=Zurück
system_understand=Ich verstehe
zipassetloader_error=Fehler: Nicht, um zusätzliche Daten Download! Bitte überprüfen Sie Ihre Internetverbindung.
zipassetloader_download_request=Sie verwenden im Moment das mobile Internet. Tablexia lädt ~ 150 MB an Spieldaten herunter. Möchten Sie die Daten wirklich jetzt runterladen?
......@@ -39,7 +40,6 @@ usermenu_dialog_yes=Ja
usermenu_dialog_no=Nein
user_logout_message=Möchtest du abmelden?
preloader_title=Wie spielt man?
confirm_button=Ich verstehe
gamedifficulty_name=Schwierigkeitsgrad:
gamedifficulty_tutorial=Lernprogramm
......@@ -207,6 +207,9 @@ user_rank_11=Oberrat
sync_request_dialog_text=Trage deine Ausweisnummer ein\:
sync_request_button=Account synchronisieren
sync_request_wrong_id=Falsch geschriebener Code.
sync_request_error=Die synchronisierung ist fehlgeschlagen, bitte versuche es später noch einmal.
game_runes_preloader1=**Podívej se na symboly v pásu vpravo.[DE]**
game_runes_preloader2_easy=**Najdi je na domech a označ dřív, než ti dojde čas.[DE]**
game_runes_preloader2_medium=**Najdi na domech jejich [BLACK]zrcadlově otočené varianty[] a označ je dřív, než ti dojde čas.[DE]**\
......
......@@ -10,6 +10,7 @@ system_decline=Zrušiť
system_exit=Koniec
system_retry=Znovu
system_back=Späť
system_understand=Rozumiem
zipassetloader_error=Chyba: Nemôžem stiahnuť dodatočná dáta! Skontrolujte prosím pripojenie k internetu.
zipassetloader_download_request: [SK upravit v application_sk.properties] Právě využíváte mobilní připojení k internetu. Tablexia potřebuje stáhnout ~150 MB herních dat. Přejete si je stáhnout nyní ?
......@@ -41,7 +42,6 @@ usermenu_dialog_no=Nie
user_logout_message=Naozaj chceš odhlásiť súčasného užívateľa?
preloader_title=Ako hrať?
confirm_button=Rozumiem
gamedifficulty_name=Obtiažnosť:
gamedifficulty_tutorial=Cvičenie
......@@ -210,6 +210,9 @@ user_rank_11=Šefmajster
sync_request_dialog_text=Zadaj číslo preukazu:
sync_request_button=Synchronizovať užívateľa
sync_request_wrong_id=Zle zadaný kód.
sync_request_error=Synchronizácia sa nepodarila, skúste to prosím neskôr.
game_runes_preloader1=**Podívej se na symboly v pásu vpravo.[SK]**
game_runes_preloader2_easy=**Najdi je na domech a označ dřív, než ti dojde čas.[DE]**
game_runes_preloader2_medium=**Najdi na domech jejich zrcadlově otočené varianty a označ je dřív, než ti dojde čas.[SK]**\
......
......@@ -462,7 +462,7 @@ public abstract class TablexiaApplication implements ApplicationListener {
screen.preparePreloaderContent(PRELOADER_DIALOG_WIDTH, PRELOADER_DIALOG_HEIGHT, preloaderAssetsManager, screenComponents);
// build dialog from generic and screen specific components
preloaderCloseButtonComponent = new CloseButtonContentDialogComponent(ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.CONFIRM_BUTTON))
preloaderCloseButtonComponent = new CloseButtonContentDialogComponent(ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.SYSTEM_UNDERSTAND))
.setEnabled(false)
.useOnce(true)
.setInputListener(new ClickListener() {
......
......@@ -30,7 +30,6 @@ public class ApplicationTextManager extends TablexiaDataManager<I18NBundle> impl
public static final String USER_LOGOUT_MESSAGE = "user_logout_message";
public static final String PRELOADER_TITLE = "preloader_title";
public static final String CONFIRM_BUTTON = "confirm_button";
public static final String SYSTEM_CONFIRM = "system_confirm";
public static final String SYSTEM_DECLINE = "system_decline";
......@@ -39,6 +38,7 @@ public class ApplicationTextManager extends TablexiaDataManager<I18NBundle> impl
public static final String SYSTEM_EXIT = "system_exit";
public static final String SYSTEM_RETRY = "system_retry";
public static final String SYSTEM_BACK = "system_back";
public static final String SYSTEM_UNDERSTAND = "system_understand";
public static final String ZIPASSETLOADER_ERROR = "zipassetloader_error";
public static final String ZIPASSETLOADER_DOWNLOAD_REQUEST = "zipassetloader_download_request";
......@@ -107,6 +107,8 @@ public class ApplicationTextManager extends TablexiaDataManager<I18NBundle> impl
public static final String SYNC_REQUEST_DIALOG_TEXT = "sync_request_dialog_text";
public static final String SYNC_REQUEST_BUTTON = "sync_request_button";
public static final String SYNC_REQUEST_WRONG_ID = "sync_request_wrong_id";
public static final String SYNC_REQUEST_ERROR = "sync_request_error";
public static final String USER_RANK_1 = "user_rank_1";
public static final String USER_RANK_2 = "user_rank_2";
......
......@@ -31,14 +31,18 @@ import cz.nic.tablexia.sync.work.DownloadUser;
import cz.nic.tablexia.sync.work.PushDataToServer;
import cz.nic.tablexia.sync.work.SyncWork;
import cz.nic.tablexia.util.ui.ClickListenerWithSound;
import cz.nic.tablexia.util.ui.dialog.TablexiaComponentDialog;
import cz.nic.tablexia.util.ui.dialog.TablexiaComponentDialogFactory;
import cz.nic.tablexia.util.ui.dialog.components.AdaptiveSizeDialogComponent;
import cz.nic.tablexia.util.ui.dialog.components.AlertOnShowDialogComponent;
import cz.nic.tablexia.util.ui.dialog.components.BackButtonHideComponent;
import cz.nic.tablexia.util.ui.dialog.components.CenterPositionDialogComponent;
import cz.nic.tablexia.util.ui.dialog.components.CloseButtonContentDialogComponent;
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.TablexiaDialogComponentAdapter;
import cz.nic.tablexia.util.ui.dialog.components.TextContentDialogComponent;
import cz.nic.tablexia.util.ui.dialog.components.TextFiledDialogComponent;
import cz.nic.tablexia.util.ui.dialog.components.ViewportMaximumSizeComponent;
......@@ -61,6 +65,10 @@ public class UserMenu extends AbstractMenu {
private static final int SYNC_REQUEST_DIALOG_MAXIMUM_LENGTH = 36;
private static final float SYNC_DIALOG_TITLE_PAD = 0.15f;
private static final float SYNC_DIALOG_TEXT_FIELD_PAD = 0.05f;
private static final int SYNC_FAILED_DIALOG_WIDTH = 280;
private static final int SYNC_FAILED_DIALOG_HEIGHT = 220;
private static final float SYNC_FAILED_DIALOG_BOTTOM_PADDING = 1/40f;
public static final String CODE_REGEX = "(([0-9]|[a-f]){8})-(([0-9]|[a-f]){4})-(([0-9]|[a-f]){4})-(([0-9]|[a-f]){4})-(([0-9]|[a-f]){12})$";
......@@ -167,17 +175,34 @@ public class UserMenu extends AbstractMenu {
new PositiveNegativeButtonContentDialogComponent(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
if (textFiledDialogComponent.getText().length()>0 && textFiledDialogComponent.getText().toLowerCase().matches(CODE_REGEX)) {
if (textFiledDialogComponent.getText().length() > 0 && textFiledDialogComponent.getText().toLowerCase().matches(CODE_REGEX)) {
DownloadUser syncWork = new DownloadUser(textFiledDialogComponent.getText());
syncWork.registerListener(new SyncWork.RestSyncListener() {
@Override
public void onSuccess(User user) {
ApplicationBus.getInstance().post(new RefreshUserMenu()).asynchronously();
}
@Override
public void onFailure(Throwable t) {
showSyncFailedDialog(ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.SYNC_REQUEST_ERROR));
}
@Override
protected void onWrongResponseCode(int responseCode) {
if(responseCode == DownloadUser.USER_NOT_FOUND_STATUS_CODE)
showSyncFailedDialog(ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.SYNC_REQUEST_WRONG_ID));
else {
showSyncFailedDialog(ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.SYNC_REQUEST_ERROR));
}
}
});
RestSynchronizationService.doSyncWork(syncWork);
}
else { //ID was blank or didn't match the ID regex
showSyncFailedDialog(ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.SYNC_REQUEST_WRONG_ID));
}
//Prevents keyboard getting stuck
Gdx.input.setOnscreenKeyboardVisible(false);
}
......@@ -185,7 +210,6 @@ public class UserMenu extends AbstractMenu {
new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
//Prevents keyboard getting stuck
Gdx.input.setOnscreenKeyboardVisible(false);
}
......@@ -215,6 +239,38 @@ public class UserMenu extends AbstractMenu {
layoutContainer.setActor(container);
}
private void showSyncFailedDialog(final String reason) {
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
TablexiaComponentDialog dialog;
List<TablexiaDialogComponentAdapter> components = new ArrayList<TablexiaDialogComponentAdapter>() {
{
add(new CenterPositionDialogComponent());
add(new DimmerDialogComponent());
add(new ViewportMaximumSizeComponent());
add(new AdaptiveSizeDialogComponent());
add(new ResizableSpaceContentDialogComponent());
add(new TextContentDialogComponent(reason));
add(new ResizableSpaceContentDialogComponent());
add(new CloseButtonContentDialogComponent(ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.SYSTEM_UNDERSTAND)));
add(new FixedSpaceContentDialogComponent(SYNC_FAILED_DIALOG_BOTTOM_PADDING));
add(new AlertOnShowDialogComponent());
add(new AdaptiveSizeDialogComponent());
add(new CenterPositionDialogComponent());
}
};
dialog = TablexiaComponentDialogFactory.getInstance().createDialog(components.toArray(new TablexiaDialogComponentAdapter[]{}));
dialog.show(SYNC_FAILED_DIALOG_WIDTH, SYNC_FAILED_DIALOG_HEIGHT, false);
}
});
}
@Override
public void dispose() {
ApplicationBus.getInstance().unsubscribe(this);
......
......@@ -31,7 +31,7 @@ public class ConfirmDataReceived extends SyncWork {
}
@Override
protected void onResponse(Net.HttpResponse httpResponse) {
protected void onSuccessfulResponse(Net.HttpResponse httpResponse) {
GameDAO.markGamesAsSync(getUser().getGames());
ScreenDAO.markScreensAsSync(getUser().getScreens());
Log.debug(this.getClass(), String.format("Marking %d of games as synchronized", getUser().getGames() != null ? getUser().getGames().size() : 0));
......
......@@ -16,6 +16,7 @@ import cz.nic.tablexia.util.Log;
*/
public class DownloadUser extends SyncWork {
public static final int USER_NOT_FOUND_STATUS_CODE = 404;
private final String uuid;
public DownloadUser(String uuid) {
......@@ -34,7 +35,7 @@ public class DownloadUser extends SyncWork {
}
@Override
protected void onResponse(Net.HttpResponse httpResponse) {
protected void onSuccessfulResponse(Net.HttpResponse httpResponse) {
String userJson = httpResponse.getResultAsString();
Json json = new Json();
json.setIgnoreUnknownFields(true);
......
......@@ -61,7 +61,7 @@ public class PushDataToServer extends SyncWork {
}
@Override
protected void onResponse(Net.HttpResponse httpResponse) {
protected void onSuccessfulResponse(Net.HttpResponse httpResponse) {
Log.debug(this.getClass(), "received uuid: " + httpResponse.getHeader("uuid"));
......
......@@ -63,20 +63,19 @@ public abstract class SyncWork implements Net.HttpResponseListener {
}
if (httpResponse.getStatus().getStatusCode() != getExpectedSuccessResponseCode()) {
failed(new Exception(String.format("expected response code was %d but received %d", getExpectedSuccessResponseCode(), httpResponse.getStatus().getStatusCode())));
Log.debug(getClass(), "Wrong Response Code received! " + httpResponse.getStatus().getStatusCode() + " (expected: " + getExpectedSuccessResponseCode() + ")");
if(listener != null) listener.onWrongResponseCode(httpResponse.getStatus().getStatusCode());
return;
}
onResponse(httpResponse);
onSuccessfulResponse(httpResponse);
if (listener != null) {
listener.onSuccess(getUser());
}
}
// override this method to handle success response from server
protected void onResponse(Net.HttpResponse httpResponse) {
}
protected void onSuccessfulResponse(Net.HttpResponse httpResponse) {}
@Override
public void failed(Throwable t) {
......@@ -190,10 +189,12 @@ public abstract class SyncWork implements Net.HttpResponseListener {
}
public void onCancelled() {
// on wrong response from the server
protected void onWrongResponseCode(int responseCode) {
}
public void onCancelled() {}
public abstract void onSuccess(User user);
}
}
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