[Update] Update update code to allow update from direct download.

This commit is contained in:
Kuba Szczodrzyński 2019-11-20 17:11:08 +01:00
parent fdb5f7ec02
commit 67f98b08c6
4 changed files with 15 additions and 6 deletions

View File

@ -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) if (!app.appConfig.notifyAboutUpdates)
return; return;
Intent notificationIntent = new Intent(app.getContext(), BootReceiver.NotificationActionService.class) Intent notificationIntent = new Intent(app.getContext(), BootReceiver.NotificationActionService.class)
.putExtra("update_version", updateVersion) .putExtra("update_version", updateVersion)
.putExtra("update_url", updateUrl) .putExtra("update_url", updateUrl)
.putExtra("update_filename", updateFilename); .putExtra("update_filename", updateFilename)
.putExtra("update_direct", updateDirect);
PendingIntent pendingIntent = PendingIntent.getService(app.getContext(), 0, PendingIntent pendingIntent = PendingIntent.getService(app.getContext(), 0,
notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

View File

@ -125,19 +125,22 @@ public class BootReceiver extends BroadcastReceiver {
String updateUrl = result.get("update_url").getAsString(); String updateUrl = result.get("update_url").getAsString();
String updateFilename = result.get("update_filename").getAsString(); String updateFilename = result.get("update_filename").getAsString();
boolean updateMandatory = result.get("update_mandatory").getAsBoolean(); boolean updateMandatory = result.get("update_mandatory").getAsBoolean();
boolean updateDirect = result.get("update_direct").getAsBoolean();
if (app.appConfig.updateVersion == null || !app.appConfig.updateVersion.equals(updateVersion)) { if (app.appConfig.updateVersion == null || !app.appConfig.updateVersion.equals(updateVersion)) {
app.appConfig.updateVersion = updateVersion; app.appConfig.updateVersion = updateVersion;
app.appConfig.updateUrl = updateUrl; app.appConfig.updateUrl = updateUrl;
app.appConfig.updateFilename = updateFilename; app.appConfig.updateFilename = updateFilename;
app.appConfig.updateMandatory = updateMandatory; app.appConfig.updateMandatory = updateMandatory;
app.appConfig.updateDirect = updateDirect;
app.saveConfig(); app.saveConfig();
} }
if (!UPDATES_ON_PLAY_STORE || intent.getBooleanExtra("UserChecked", false)) { if (!UPDATES_ON_PLAY_STORE || intent.getBooleanExtra("UserChecked", false)) {
app.notifier.notificationUpdatesShow( app.notifier.notificationUpdatesShow(
updateVersion, updateVersion,
updateUrl, updateUrl,
updateFilename); updateFilename,
updateDirect);
} }
} else { } else {
if (app.appConfig.updateVersion == null || !app.appConfig.updateVersion.equals("")) { if (app.appConfig.updateVersion == null || !app.appConfig.updateVersion.equals("")) {
@ -259,7 +262,7 @@ public class BootReceiver extends BroadcastReceiver {
@Override @Override
protected void onHandleIntent(Intent intent) { 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"); Utils.openGooglePlay(this, "pl.szczodrzynski.edziennik");
return; return;
} }
@ -270,7 +273,8 @@ public class BootReceiver extends BroadcastReceiver {
app.notifier.notificationUpdatesShow( app.notifier.notificationUpdatesShow(
intent.getStringExtra("update_version"), intent.getStringExtra("update_version"),
intent.getStringExtra("update_url"), intent.getStringExtra("update_url"),
intent.getStringExtra("update_filename")); intent.getStringExtra("update_filename"),
intent.getBooleanExtra("update_direct", false));
return; return;
} }
} }

View File

@ -154,19 +154,22 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
String updateUrl = remoteMessage.getData().get("update_url"); String updateUrl = remoteMessage.getData().get("update_url");
String updateFilename = remoteMessage.getData().get("update_filename"); String updateFilename = remoteMessage.getData().get("update_filename");
boolean updateMandatory = Boolean.parseBoolean(remoteMessage.getData().get("update_mandatory")); 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)) { if (app.appConfig.updateVersion == null || !app.appConfig.updateVersion.equals(updateVersion)) {
app.appConfig.updateVersion = updateVersion; app.appConfig.updateVersion = updateVersion;
app.appConfig.updateUrl = updateUrl; app.appConfig.updateUrl = updateUrl;
app.appConfig.updateFilename = updateFilename; app.appConfig.updateFilename = updateFilename;
app.appConfig.updateMandatory = updateMandatory; app.appConfig.updateMandatory = updateMandatory;
app.appConfig.updateDirect = updateDirect;
app.saveConfig("updateVersion", "updateUrl", "updateFilename", "updateMandatory"); app.saveConfig("updateVersion", "updateUrl", "updateFilename", "updateMandatory");
} }
if (!remoteMessage.getData().containsKey("update_silent")) { if (!remoteMessage.getData().containsKey("update_silent")) {
app.notifier.notificationUpdatesShow( app.notifier.notificationUpdatesShow(
updateVersion, updateVersion,
updateUrl, updateUrl,
updateFilename); updateFilename,
updateDirect);
} }
} else { } else {
if (app.appConfig.updateVersion == null || !app.appConfig.updateVersion.equals("")) { if (app.appConfig.updateVersion == null || !app.appConfig.updateVersion.equals("")) {

View File

@ -95,6 +95,7 @@ public class AppConfig {
public String updateUrl = ""; public String updateUrl = "";
public String updateFilename = ""; public String updateFilename = "";
public boolean updateMandatory = false; public boolean updateMandatory = false;
public boolean updateDirect = false;
public boolean webPushEnabled = false; public boolean webPushEnabled = false;