diff options
author | Christian S <christian@pix-art.de> | 2016-04-23 19:08:08 +0200 |
---|---|---|
committer | Christian S <christian@pix-art.de> | 2016-04-23 19:11:11 +0200 |
commit | d0aef46126dd70c73686dc141d3c027bc47e3816 (patch) | |
tree | 76781579f90bc03b3a24f2908e2e7df6cd44bb20 /src | |
parent | 97173fd512bd3948f6bfd9b27ae7d103d50a4ee9 (diff) |
changed updater a bit
Diffstat (limited to 'src')
5 files changed, 71 insertions, 74 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/CheckAppVersionService.java b/src/main/java/eu/siacs/conversations/services/CheckAppVersionService.java index 33faeaeca..dc57745f1 100644 --- a/src/main/java/eu/siacs/conversations/services/CheckAppVersionService.java +++ b/src/main/java/eu/siacs/conversations/services/CheckAppVersionService.java @@ -33,7 +33,7 @@ public class CheckAppVersionService extends HttpServlet { myObj.addProperty("success", false); myObj.addProperty("latestVersionCode", 2); myObj.addProperty("latestVersion", "1.0.0"); - myObj.addProperty("changelog", ""); + myObj.addProperty("filesize", ""); myObj.addProperty("appURI", ""); out.println(myObj.toString()); out.close(); diff --git a/src/main/java/eu/siacs/conversations/services/UpdaterWebService.java b/src/main/java/eu/siacs/conversations/services/UpdaterWebService.java index cb58b49eb..d7044d73a 100644 --- a/src/main/java/eu/siacs/conversations/services/UpdaterWebService.java +++ b/src/main/java/eu/siacs/conversations/services/UpdaterWebService.java @@ -24,7 +24,7 @@ import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.ui.UpdaterActivity.UpdateReceiver; -public class UpdaterWebService extends IntentService{ +public class UpdaterWebService extends IntentService { public static final String REQUEST_STRING = ""; public static final String RESPONSE_MESSAGE = ""; @@ -45,8 +45,7 @@ public class UpdaterWebService extends IntentService{ PackageInfo pInfo = null; try { pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); - } - catch (PackageManager.NameNotFoundException e) { + } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } //get the app version Name for display @@ -68,7 +67,7 @@ public class UpdaterWebService extends IntentService{ StatusLine statusLine = response.getStatusLine(); Log.d(Config.LOGTAG, "AppUpdater: HTTP Status Code: " + statusLine.getStatusCode()); - if(statusLine.getStatusCode() == HttpStatus.SC_OK){ + if (statusLine.getStatusCode() == HttpStatus.SC_OK) { ByteArrayOutputStream out = new ByteArrayOutputStream(); response.getEntity().writeTo(out); out.close(); @@ -85,7 +84,7 @@ public class UpdaterWebService extends IntentService{ } catch (IOException e) { Log.e(Config.LOGTAG, "AppUpdater: HTTP3:" + e); responseMessage = ""; - }catch (Exception e) { + } catch (Exception e) { Log.e(Config.LOGTAG, "AppUpdater: HTTP4:" + e); responseMessage = ""; } diff --git a/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java b/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java index 7c8efe5be..a9adfb174 100644 --- a/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java @@ -34,12 +34,34 @@ import eu.siacs.conversations.services.UpdaterWebService; public class UpdaterActivity extends Activity { + String appURI = ""; private UpdateReceiver receiver = null; private int versionCode = 0; - String appURI = ""; - private DownloadManager downloadManager; private long downloadReference; + //broadcast receiver to get notification about ongoing downloads + BroadcastReceiver downloadReceiver = new BroadcastReceiver() { + + @Override + public void onReceive(Context context, Intent intent) { + //check if the broadcast message is for our Enqueued download + long referenceId = intent.getExtras().getLong(DownloadManager.EXTRA_DOWNLOAD_ID); + if (downloadReference == referenceId) { + File file = new File(getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "Conversations.apk"); + Log.d(Config.LOGTAG, "AppUpdater: Downloading of the new app version complete. Starting installation from " + file); + + //start the installation of the latest version + Intent installIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE); + installIntent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); + installIntent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true); + installIntent.putExtra(Intent.EXTRA_RETURN_RESULT, true); + installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(installIntent); + + UpdaterActivity.this.finish(); + } + } + }; @Override protected void onCreate(Bundle savedInstanceState) { @@ -110,6 +132,44 @@ public class UpdaterActivity extends Activity { return false; } + public boolean isStoragePermissionGranted() { + if (Build.VERSION.SDK_INT >= 23) { + if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) + == PackageManager.PERMISSION_GRANTED) { + Log.d(Config.LOGTAG, "AppUpdater: Permission is granted"); + return true; + } else { + + Log.d(Config.LOGTAG, "AppUpdater: Permission is revoked"); + ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); + return false; + } + } else { //permission is automatically granted on sdk<23 upon installation + Log.d(Config.LOGTAG, "AppUpdater: Permission is granted"); + return true; + } + } + + //show warning on back pressed + @Override + public void onBackPressed() { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setMessage(R.string.cancel_update) + .setCancelable(false) + .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + UpdaterActivity.this.finish(); + } + }) + .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + } + }); + AlertDialog alert = builder.create(); + alert.show(); + } + //broadcast receiver to get notification when the web request finishes public class UpdateReceiver extends BroadcastReceiver { @@ -155,7 +215,7 @@ public class UpdaterActivity extends Activity { //get the latest version from the JSON string int latestVersionCode = reponseObj.getInt("latestVersionCode"); String latestVersion = reponseObj.getString("latestVersion"); - String changelog = reponseObj.getString("changelog"); + String filesize = reponseObj.getString("filesize"); //get the lastest application URI from the JSON string appURI = reponseObj.getString("appURI"); //check if we need to upgrade? @@ -178,7 +238,7 @@ public class UpdaterActivity extends Activity { builder.setCancelable(false); String UpdateMessageInfo = getResources().getString(R.string.update_available); - builder.setMessage(String.format(UpdateMessageInfo, latestVersion, changelog, versionName)) + builder.setMessage(String.format(UpdateMessageInfo, latestVersion, filesize, versionName)) .setPositiveButton(R.string.update, new DialogInterface.OnClickListener() { //if the user agrees to upgrade public void onClick(DialogInterface dialog, int id) { @@ -243,66 +303,4 @@ public class UpdaterActivity extends Activity { } } - - public boolean isStoragePermissionGranted() { - if (Build.VERSION.SDK_INT >= 23) { - if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) - == PackageManager.PERMISSION_GRANTED) { - Log.d(Config.LOGTAG, "AppUpdater: Permission is granted"); - return true; - } else { - - Log.d(Config.LOGTAG, "AppUpdater: Permission is revoked"); - ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); - return false; - } - } else { //permission is automatically granted on sdk<23 upon installation - Log.d(Config.LOGTAG, "AppUpdater: Permission is granted"); - return true; - } - } - - //broadcast receiver to get notification about ongoing downloads - BroadcastReceiver downloadReceiver = new BroadcastReceiver() { - - @Override - public void onReceive(Context context, Intent intent) { - //check if the broadcast message is for our Enqueued download - long referenceId = intent.getExtras().getLong(DownloadManager.EXTRA_DOWNLOAD_ID); - if (downloadReference == referenceId) { - File file = new File(getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "Conversations.apk"); - Log.d(Config.LOGTAG, "AppUpdater: Downloading of the new app version complete. Starting installation from " + file); - - //start the installation of the latest version - Intent installIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE); - installIntent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); - installIntent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true); - installIntent.putExtra(Intent.EXTRA_RETURN_RESULT, true); - installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(installIntent); - - UpdaterActivity.this.finish(); - } - } - }; - - //show warning on back pressed - @Override - public void onBackPressed() { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setMessage(R.string.cancel_update) - .setCancelable(false) - .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - UpdaterActivity.this.finish(); - } - }) - .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - } - }); - AlertDialog alert = builder.create(); - alert.show(); - } } diff --git a/src/main/res/values-de/strings.xml b/src/main/res/values-de/strings.xml index 9ce1b49c1..68875b683 100644 --- a/src/main/res/values-de/strings.xml +++ b/src/main/res/values-de/strings.xml @@ -499,7 +499,7 @@ <string name="checking_for_updates">Auf Pix-Art Messenger Updates prüfen</string> <string name="title_activity_updater">Update Dienst</string> <string name="update">aktualisieren</string> - <string name="update_available">Pix-Art Messenger %1$s mit folgenden Änderungen ist verfügbar:\n\n%2$s\n\nMöchtest Du auf Pix-Art Messenger %1$s aktualisieren?</string> + <string name="update_available">Version %1$s ist verfügbar.\n\nDateigröße: %2$s\n\nJetzt auf Version %1$s aktualisieren?</string> <string name="download_started">Download gestartet</string> <string name="no_update_available">Kein Update verfügbar</string> <string name="account_status_tor_unavailable">Tor-Netzwerk nicht verfügbar</string> diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index a8cad9769..7cdec8723 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -545,7 +545,7 @@ <string name="pref_use_white_background_summary">Show received messages as black text on a white background</string> <string name="action_check_update">Check for Updates</string> <string name="title_activity_updater">Update Service</string> - <string name="update_available">Pix-Art Messenger %1$s with the following changes is available:\n\n%2$s\n\nUpdate Pix-Art Messenger %3$s to Pix-Art Messenger %1$s now?</string> + <string name="update_available">Version %1$s is available.\n\nFilesize: %2$s\n\nUpdate to version %1$s now?</string> <string name="checking_for_updates">Checking for Pix-Art Messenger updates</string> <string name="remind_later">later</string> <string name="update">update</string> |