Detect empty server addresses

If the app detects an empty server URL, it will change it to the default server address.
This commit is contained in:
luca0N! 2021-03-10 00:23:36 -03:00
parent 02f7b5b444
commit cff137eded
Signed by: luca0N
GPG Key ID: 2E7B4655CF16D7D6
1 changed files with 7 additions and 2 deletions

View File

@ -92,11 +92,16 @@ public class TriviaQuery implements Serializable {
// Load custom server URL.
Context c = PluckApplication.getAppContext();
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(c);
String key = c.getResources().getString(R.string.pref_network_server);
String serverKey = c.getResources().getString(R.string.pref_network_server);
// Load default server URL in case the player did not specify a custom server URL.
String defaultServer = c.getResources().getString(R.string.pref_network_server_default);
String base = sp.getString(serverKey, defaultServer) + "?"; // append "?" to the end of the URL so we can specify GET parameters.
String base = sp.getString(key, defaultServer) + "?"; // append "?" to the end of the URL so we can specify GET parameters.
// Check if the custom server URL preference was empty. If it was, change it to the default URL.
if (base.equals("?")){
base = defaultServer + "?";
sp.edit().putString(serverKey, defaultServer).commit();
}
url.append(base);
url.append("amount=").append(this.amount);