Commit bd3ccfd7 authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

Download and update management

Can download now updates
parent cb1df112
......@@ -676,7 +676,19 @@ public abstract class BaseActivity extends InternetActivity {
}
}
})
.setNegativeButton(R.string.cancel, null);
.setNegativeButton(R.string.cancel, null)
.setNeutralButton(R.string.set_download, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
if (!haveStoragePermission()) {
updateDialog.stopLoading();
updateDialog.errorDialog(BaseActivity.this, getString(R.string.update), getString(R.string.need_storage_permission));
}
else if (!update(matcher.group(2), true)) {
updateDialog.stopLoading();
updateDialog.errorDialog(BaseActivity.this, getString(R.string.download), getString(R.string.can_not_download));
}
}
});
updateDialog.createDialog(alertDialogBuilder);
}
......@@ -704,7 +716,8 @@ public abstract class BaseActivity extends InternetActivity {
}.start();
}
protected boolean update(final String version) {
protected boolean update(final String version) { return update(version, false); }
protected boolean update(final String version, final boolean downloadOnly) {
final String destination = this.downloadLocation + getString(R.string.app_name) + " " + version + ".apk";
final String url = this.gitUrl + getString(R.string.app_name) + " " + version + ".apk";
final Uri uri = Uri.parse("file://" + destination);
......@@ -721,16 +734,28 @@ public abstract class BaseActivity extends InternetActivity {
final DownloadManager manager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
final long downloadId = manager.enqueue(request);
BroadcastReceiver onComplete = new BroadcastReceiver() {
public void onReceive(Context ctx, Intent intent) {
Intent install = new Intent(Intent.ACTION_VIEW);
install.setDataAndType(uri, "application/vnd.android.package-archive");
install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(install);
BroadcastReceiver onComplete;
if (downloadOnly) {
onComplete = new BroadcastReceiver() {
public void onReceive(Context ctx, Intent intent) {
new Dialog(BaseActivity.this).infoDialog(BaseActivity.this, getString(R.string.download), getString(R.string.download_successful));
unregisterReceiver(this);
}
};
unregisterReceiver(this);
}
};
}
else {
onComplete = new BroadcastReceiver() {
public void onReceive(Context ctx, Intent intent) {
Intent install = new Intent(Intent.ACTION_VIEW);
install.setDataAndType(uri, "application/vnd.android.package-archive");
install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(install);
unregisterReceiver(this);
}
};
}
registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
......
......@@ -67,6 +67,7 @@
<string name="type">Type</string>
<string name="day_s_">jour(s)</string>
<string name="update">Mise à jour</string>
<string name="download">Téléchargement</string>
<string name="qrcode">QR Code</string>
<string name="credit">Crédits</string>
<string name="price">Prix</string>
......@@ -169,10 +170,13 @@
<string name="contribute_admin">Membre d\'honneur (0€)</string>
<string name="contribute_temp">Temporaire</string>
<string name="set_update">Mettre à jour</string>
<string name="set_download">Télécharger</string>
<string name="check_update">Recherche d\'une mise à jour</string>
<string name="available_update">Mise à jour disponible</string>
<string name="can_not_detect_update">Impossible de détecter si une mise à jour disponible</string>
<string name="can_not_update">Impossible de réaliser la mise à jour</string>
<string name="can_not_download">Impossible de télécharger la mise à jour</string>
<string name="download_successful">Téléchagement réussi</string>
<string name="no_update">Aucune mise à jour disponible</string>
<string name="actual_version">Version actuelle</string>
<string name="available_version">Version disponible</string>
......@@ -213,7 +217,6 @@
<string name="article_deleting">Suppression d\'un article</string>
<string name="article_delete_confirmation">Voulez-vous vraiment supprimer cet article:</string>
<string name="print_mode">Mode d\'affichage</string>
<string name="filters">Filtres d\'affichage</string>
<string name="print_cotisant">Afficher le filtre cotisant</string>
......
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