diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-10-18 20:41:11 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-10-18 20:41:11 +0200 |
commit | bbd443445876e916ed66c4e7ba385608cdac4f84 (patch) | |
tree | b4f654802efc3a664fedcfd232758b264ccab5f3 /src/main | |
parent | cfa5d01e0519ae8aff6a87c2165cb36e1e048262 (diff) |
fix crash while searching for updates and show error message if search was not successful
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/de/pixart/messenger/services/UpdateService.java | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/main/java/de/pixart/messenger/services/UpdateService.java b/src/main/java/de/pixart/messenger/services/UpdateService.java index 988b70df5..95204b584 100644 --- a/src/main/java/de/pixart/messenger/services/UpdateService.java +++ b/src/main/java/de/pixart/messenger/services/UpdateService.java @@ -40,21 +40,22 @@ public class UpdateService extends AsyncTask<String, Object, UpdateService.Wrapp public class Wrapper { public boolean UpdateAvailable = false; - public boolean showNoUpdateToast = false; + public boolean NoUpdate = false; + public boolean isError = false; } @Override protected Wrapper doInBackground(String... params) { - + String jsonString = ""; + boolean UpdateAvailable = false; boolean showNoUpdateToast = false; + boolean isError = false; + if (params[0].equals("true")) { showNoUpdateToast = true; } - HttpsURLConnection connection = null; - String jsonString = ""; - boolean UpdateAvailable = false; try { URL url = new URL(Config.UPDATE_URL); @@ -69,7 +70,7 @@ public class UpdateService extends AsyncTask<String, Object, UpdateService.Wrapp } catch (Exception e) { e.printStackTrace(); - return null; + isError = true; } finally { if (connection != null) { connection.disconnect(); @@ -100,20 +101,25 @@ public class UpdateService extends AsyncTask<String, Object, UpdateService.Wrapp e.printStackTrace(); } Wrapper w = new Wrapper(); + w.isError = isError; w.UpdateAvailable = UpdateAvailable; - w.showNoUpdateToast = showNoUpdateToast; + w.NoUpdate = showNoUpdateToast; return w; } @Override protected void onPostExecute(Wrapper w) { super.onPostExecute(w); + if (w.isError) { + showToastMessage(true, true); + return; + } if (!w.UpdateAvailable) { - noUpdateMessage(w.showNoUpdateToast); + showToastMessage(w.NoUpdate, false); } } - private void noUpdateMessage(boolean show) { + private void showToastMessage(boolean show, final boolean error) { if (!show) { return; } @@ -122,7 +128,13 @@ public class UpdateService extends AsyncTask<String, Object, UpdateService.Wrapp @Override public void run() { - Toast.makeText(context, context.getString(R.string.no_update_available), Toast.LENGTH_LONG).show(); + String ToastMessage = ""; + if (error) { + ToastMessage = context.getString(R.string.failed); + } else { + ToastMessage = context.getString(R.string.no_update_available); + } + Toast.makeText(context, ToastMessage, Toast.LENGTH_LONG).show(); } }); } |