From 67f98b08c67368ae276859518f484bf82d630831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Wed, 20 Nov 2019 17:11:08 +0100 Subject: [PATCH] [Update] Update update code to allow update from direct download. --- .../main/java/pl/szczodrzynski/edziennik/Notifier.java | 5 +++-- .../edziennik/receivers/BootReceiver.java | 10 +++++++--- .../edziennik/sync/MyFirebaseMessagingService.java | 5 ++++- .../edziennik/utils/models/AppConfig.java | 1 + 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/Notifier.java b/app/src/main/java/pl/szczodrzynski/edziennik/Notifier.java index 660647b9..32f769dc 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/Notifier.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/Notifier.java @@ -311,13 +311,14 @@ public class Notifier { \____/| .__/ \__,_|\__,_|\__\___||___/ | | |*/ - public void notificationUpdatesShow(String updateVersion, String updateUrl, String updateFilename) { + public void notificationUpdatesShow(String updateVersion, String updateUrl, String updateFilename, boolean updateDirect) { if (!app.appConfig.notifyAboutUpdates) return; Intent notificationIntent = new Intent(app.getContext(), BootReceiver.NotificationActionService.class) .putExtra("update_version", updateVersion) .putExtra("update_url", updateUrl) - .putExtra("update_filename", updateFilename); + .putExtra("update_filename", updateFilename) + .putExtra("update_direct", updateDirect); PendingIntent pendingIntent = PendingIntent.getService(app.getContext(), 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/receivers/BootReceiver.java b/app/src/main/java/pl/szczodrzynski/edziennik/receivers/BootReceiver.java index f1427ff3..018cd0fe 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/receivers/BootReceiver.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/receivers/BootReceiver.java @@ -125,19 +125,22 @@ public class BootReceiver extends BroadcastReceiver { String updateUrl = result.get("update_url").getAsString(); String updateFilename = result.get("update_filename").getAsString(); boolean updateMandatory = result.get("update_mandatory").getAsBoolean(); + boolean updateDirect = result.get("update_direct").getAsBoolean(); if (app.appConfig.updateVersion == null || !app.appConfig.updateVersion.equals(updateVersion)) { app.appConfig.updateVersion = updateVersion; app.appConfig.updateUrl = updateUrl; app.appConfig.updateFilename = updateFilename; app.appConfig.updateMandatory = updateMandatory; + app.appConfig.updateDirect = updateDirect; app.saveConfig(); } if (!UPDATES_ON_PLAY_STORE || intent.getBooleanExtra("UserChecked", false)) { app.notifier.notificationUpdatesShow( updateVersion, updateUrl, - updateFilename); + updateFilename, + updateDirect); } } else { if (app.appConfig.updateVersion == null || !app.appConfig.updateVersion.equals("")) { @@ -259,7 +262,7 @@ public class BootReceiver extends BroadcastReceiver { @Override protected void onHandleIntent(Intent intent) { - if (UPDATES_ON_PLAY_STORE) { + if (UPDATES_ON_PLAY_STORE && !intent.getBooleanExtra("update_direct", false)) { Utils.openGooglePlay(this, "pl.szczodrzynski.edziennik"); return; } @@ -270,7 +273,8 @@ public class BootReceiver extends BroadcastReceiver { app.notifier.notificationUpdatesShow( intent.getStringExtra("update_version"), intent.getStringExtra("update_url"), - intent.getStringExtra("update_filename")); + intent.getStringExtra("update_filename"), + intent.getBooleanExtra("update_direct", false)); return; } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/sync/MyFirebaseMessagingService.java b/app/src/main/java/pl/szczodrzynski/edziennik/sync/MyFirebaseMessagingService.java index 45630fe9..3bacc7ff 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/sync/MyFirebaseMessagingService.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/sync/MyFirebaseMessagingService.java @@ -154,19 +154,22 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService { String updateUrl = remoteMessage.getData().get("update_url"); String updateFilename = remoteMessage.getData().get("update_filename"); boolean updateMandatory = Boolean.parseBoolean(remoteMessage.getData().get("update_mandatory")); + boolean updateDirect = Boolean.parseBoolean(remoteMessage.getData().get("update_direct")); if (app.appConfig.updateVersion == null || !app.appConfig.updateVersion.equals(updateVersion)) { app.appConfig.updateVersion = updateVersion; app.appConfig.updateUrl = updateUrl; app.appConfig.updateFilename = updateFilename; app.appConfig.updateMandatory = updateMandatory; + app.appConfig.updateDirect = updateDirect; app.saveConfig("updateVersion", "updateUrl", "updateFilename", "updateMandatory"); } if (!remoteMessage.getData().containsKey("update_silent")) { app.notifier.notificationUpdatesShow( updateVersion, updateUrl, - updateFilename); + updateFilename, + updateDirect); } } else { if (app.appConfig.updateVersion == null || !app.appConfig.updateVersion.equals("")) { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/utils/models/AppConfig.java b/app/src/main/java/pl/szczodrzynski/edziennik/utils/models/AppConfig.java index d9310ccb..fea91380 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/utils/models/AppConfig.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/utils/models/AppConfig.java @@ -95,6 +95,7 @@ public class AppConfig { public String updateUrl = ""; public String updateFilename = ""; public boolean updateMandatory = false; + public boolean updateDirect = false; public boolean webPushEnabled = false;