Error handling and highscore bug fix
This commit is contained in:
@@ -108,7 +108,7 @@ public class MainFragment extends Fragment {
|
|||||||
textView.setText(String.format(Locale.getDefault(), "%1$d", category.getScore()));
|
textView.setText(String.format(Locale.getDefault(), "%1$d", category.getScore()));
|
||||||
|
|
||||||
catProgress = (ProgressBar) categoryView.findViewById(R.id.progressBarCategory);
|
catProgress = (ProgressBar) categoryView.findViewById(R.id.progressBarCategory);
|
||||||
catProgress.setProgress(category.getPlace());
|
catProgress.setProgress(scores.getAll()-category.getPlace()+1);
|
||||||
catProgress.setMax(scores.getAll());
|
catProgress.setMax(scores.getAll());
|
||||||
|
|
||||||
gridLayoutCategories.addView(categoryView);
|
gridLayoutCategories.addView(categoryView);
|
||||||
@@ -119,7 +119,7 @@ public class MainFragment extends Fragment {
|
|||||||
|
|
||||||
userStatusTextViewScore.setText(String.format(Locale.getDefault(), "%1$d", scores.getScore()));
|
userStatusTextViewScore.setText(String.format(Locale.getDefault(), "%1$d", scores.getScore()));
|
||||||
userStatusProgressBar.setMax(scores.getAll());
|
userStatusProgressBar.setMax(scores.getAll());
|
||||||
userStatusProgressBar.setProgress(scores.getPlace());
|
userStatusProgressBar.setProgress(scores.getAll()-scores.getPlace()+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -396,10 +396,7 @@ public class GameService {
|
|||||||
|
|
||||||
HashMap<String, String> params = new HashMap<>();
|
HashMap<String, String> params = new HashMap<>();
|
||||||
String uid;
|
String uid;
|
||||||
if (LoginService.isLoggedIn())
|
|
||||||
uid = LoginService.getLoginUID();
|
uid = LoginService.getLoginUID();
|
||||||
else
|
|
||||||
throw new NotLoggedInException();
|
|
||||||
params.put("answer", Integer.toString(id));
|
params.put("answer", Integer.toString(id));
|
||||||
params.put("uid", uid);
|
params.put("uid", uid);
|
||||||
params.put("time", Long.toString(time));
|
params.put("time", Long.toString(time));
|
||||||
@@ -457,10 +454,7 @@ public class GameService {
|
|||||||
|
|
||||||
HashMap<String, String> params = new HashMap<>();
|
HashMap<String, String> params = new HashMap<>();
|
||||||
String uid;
|
String uid;
|
||||||
if (LoginService.isLoggedIn())
|
|
||||||
uid = LoginService.getLoginUID();
|
uid = LoginService.getLoginUID();
|
||||||
else
|
|
||||||
throw new NotLoggedInException();
|
|
||||||
params.put("uid", uid);
|
params.put("uid", uid);
|
||||||
params.put("length", Conversion.intToStr(GameService.QUESTION_COUNT));
|
params.put("length", Conversion.intToStr(GameService.QUESTION_COUNT));
|
||||||
JsonRequestPG requester = new JsonRequestPG("start.php", params, GameService.activity, new JsonRequestPG.AsyncResponse() {
|
JsonRequestPG requester = new JsonRequestPG("start.php", params, GameService.activity, new JsonRequestPG.AsyncResponse() {
|
||||||
@@ -481,6 +475,13 @@ public class GameService {
|
|||||||
@Override
|
@Override
|
||||||
public void processError(int status, String message) {
|
public void processError(int status, String message) {
|
||||||
GameService.setStateSave(States.END);
|
GameService.setStateSave(States.END);
|
||||||
|
if (status==12104) { // user uid not found
|
||||||
|
try {
|
||||||
|
LoginService.setLogout(status, message);
|
||||||
|
} catch (NotInstantiatedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
requester.execute();
|
requester.execute();
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
import de.hwr_berlin.it14.postgrachelor.Exceptions.NotInstantiatedException;
|
import de.hwr_berlin.it14.postgrachelor.Exceptions.NotInstantiatedException;
|
||||||
|
import de.hwr_berlin.it14.postgrachelor.Exceptions.NotLoggedInException;
|
||||||
import de.hwr_berlin.it14.postgrachelor.Types.GameScores;
|
import de.hwr_berlin.it14.postgrachelor.Types.GameScores;
|
||||||
import de.hwr_berlin.it14.postgrachelor.Types.Highscores;
|
import de.hwr_berlin.it14.postgrachelor.Types.Highscores;
|
||||||
import de.hwr_berlin.it14.postgrachelor.Utils.JsonRequestPG;
|
import de.hwr_berlin.it14.postgrachelor.Utils.JsonRequestPG;
|
||||||
@@ -54,7 +56,7 @@ public class HighscoreService {
|
|||||||
public void onLoginEvent(String name, String uid) {
|
public void onLoginEvent(String name, String uid) {
|
||||||
try {
|
try {
|
||||||
HighscoreService.updateHighscores();
|
HighscoreService.updateHighscores();
|
||||||
} catch (NotInstantiatedException e) {
|
} catch (NotInstantiatedException | NotLoggedInException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
HighscoreService.setLatestScores(null);
|
HighscoreService.setLatestScores(null);
|
||||||
}
|
}
|
||||||
@@ -71,7 +73,7 @@ public class HighscoreService {
|
|||||||
public void onGameEndEvent(GameScores scores) {
|
public void onGameEndEvent(GameScores scores) {
|
||||||
try {
|
try {
|
||||||
HighscoreService.updateHighscores();
|
HighscoreService.updateHighscores();
|
||||||
} catch (NotInstantiatedException e) {
|
} catch (NotInstantiatedException | NotLoggedInException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
HighscoreService.setLatestScores(null);
|
HighscoreService.setLatestScores(null);
|
||||||
}
|
}
|
||||||
@@ -92,10 +94,15 @@ public class HighscoreService {
|
|||||||
emitHighscoreUpdateEvent();
|
emitHighscoreUpdateEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void updateHighscores() throws NotInstantiatedException {
|
private static void updateHighscores() throws NotInstantiatedException, NotLoggedInException {
|
||||||
if (!instantiated)
|
if (!instantiated)
|
||||||
throw new NotInstantiatedException();
|
throw new NotInstantiatedException();
|
||||||
JsonRequestPG requester = new JsonRequestPG("highscores.php", null, activity, new JsonRequestPG.AsyncResponse() {
|
|
||||||
|
HashMap<String, String> params = new HashMap<>();
|
||||||
|
String uid = LoginService.getLoginUID();
|
||||||
|
Log.d(NAME, uid);
|
||||||
|
params.put("uid", LoginService.getLoginUID());
|
||||||
|
JsonRequestPG requester = new JsonRequestPG("highscores.php", params, activity, new JsonRequestPG.AsyncResponse() {
|
||||||
@Override
|
@Override
|
||||||
public void processFinish(JSONObject output) {
|
public void processFinish(JSONObject output) {
|
||||||
Log.d("Activity fragment", "output");
|
Log.d("Activity fragment", "output");
|
||||||
@@ -130,6 +137,13 @@ public class HighscoreService {
|
|||||||
@Override
|
@Override
|
||||||
public void processError(int status, String message) {
|
public void processError(int status, String message) {
|
||||||
setLatestScores(null);
|
setLatestScores(null);
|
||||||
|
if (status==15102) { // user uid not found
|
||||||
|
try {
|
||||||
|
LoginService.setLogout(status, message);
|
||||||
|
} catch (NotInstantiatedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
requester.execute();
|
requester.execute();
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.json.JSONObject;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import de.hwr_berlin.it14.postgrachelor.Exceptions.NotInstantiatedException;
|
import de.hwr_berlin.it14.postgrachelor.Exceptions.NotInstantiatedException;
|
||||||
|
import de.hwr_berlin.it14.postgrachelor.Exceptions.NotLoggedInException;
|
||||||
import de.hwr_berlin.it14.postgrachelor.Utils.JsonRequestPG;
|
import de.hwr_berlin.it14.postgrachelor.Utils.JsonRequestPG;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,7 +36,7 @@ public class LoginService {
|
|||||||
if (isLoggedInSave()) {
|
if (isLoggedInSave()) {
|
||||||
try {
|
try {
|
||||||
onLoginEventListener.onLoginEvent(getLoginName(), getLoginUID());
|
onLoginEventListener.onLoginEvent(getLoginName(), getLoginUID());
|
||||||
} catch (NotInstantiatedException e) {
|
} catch (NotInstantiatedException | NotLoggedInException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -63,7 +64,7 @@ public class LoginService {
|
|||||||
String uid = null;
|
String uid = null;
|
||||||
try {
|
try {
|
||||||
name = getLoginName();
|
name = getLoginName();
|
||||||
uid = getLoginUID();
|
uid = getLoginUIDSave();
|
||||||
} catch (NotInstantiatedException e) {
|
} catch (NotInstantiatedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -94,7 +95,13 @@ public class LoginService {
|
|||||||
return settings.getString("loginName", "");
|
return settings.getString("loginName", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
static String getLoginUID() throws NotInstantiatedException {
|
static String getLoginUID() throws NotInstantiatedException, NotLoggedInException {
|
||||||
|
if (!LoginService.isLoggedIn())
|
||||||
|
throw new NotLoggedInException();
|
||||||
|
return settings.getString("loginUID", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getLoginUIDSave() throws NotInstantiatedException {
|
||||||
if (!LoginService.isLoggedIn())
|
if (!LoginService.isLoggedIn())
|
||||||
return "";
|
return "";
|
||||||
return settings.getString("loginUID", "");
|
return settings.getString("loginUID", "");
|
||||||
@@ -111,7 +118,7 @@ public class LoginService {
|
|||||||
emitLoginEvent(name, uid);
|
emitLoginEvent(name, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setLogout(int status, String message) throws NotInstantiatedException {
|
static void setLogout(int status, String message) throws NotInstantiatedException {
|
||||||
if (!instantiated)
|
if (!instantiated)
|
||||||
throw new NotInstantiatedException();
|
throw new NotInstantiatedException();
|
||||||
SharedPreferences.Editor editor = settings.edit();
|
SharedPreferences.Editor editor = settings.edit();
|
||||||
|
|||||||
Reference in New Issue
Block a user