-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add additional JSON params for server control of update prompts #26
Changes from all commits
63c0d89
674d749
917c52f
3ab87f8
f092baa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,37 +178,51 @@ private boolean checkVersionName(JSONObject appJson) throws JSONException{ | |
} | ||
getSirenHelper().setLastVerificationDate(mApplicationContext); | ||
|
||
// If no config found, assume version check is enabled | ||
Boolean versionCheckEnabled = appJson.has(Constants.JSON_ENABLE_VERSION_CHECK) ? appJson.getBoolean(Constants.JSON_ENABLE_VERSION_CHECK) : true; | ||
if (!versionCheckEnabled) { | ||
return false; | ||
} | ||
|
||
// If no config found, assume force update = false | ||
Boolean forceUpdateEnabled = appJson.has(Constants.JSON_FORCE_ALERT_TYPE) ? appJson.getBoolean(Constants.JSON_FORCE_ALERT_TYPE) : false; | ||
String minVersionName = appJson.getString(Constants.JSON_MIN_VERSION_NAME); | ||
String currentVersionName = getSirenHelper().getVersionName(mApplicationContext); | ||
|
||
if (getSirenHelper().isEmpty(minVersionName) || getSirenHelper().isEmpty(currentVersionName) || getSirenHelper().isVersionSkippedByUser(mApplicationContext, minVersionName)) { | ||
return false; | ||
} | ||
|
||
SirenAlertType alertType = null; | ||
String[] minVersionNumbers = minVersionName.split("\\."); | ||
String[] currentVersionNumbers = currentVersionName.split("\\."); | ||
//noinspection ConstantConditions | ||
if (minVersionNumbers != null && currentVersionNumbers != null | ||
&& minVersionNumbers.length == currentVersionNumbers.length) { | ||
int digitVerificationCode = checkVersionDigit(minVersionNumbers, currentVersionNumbers, 0); | ||
if (digitVerificationCode == 0) { | ||
digitVerificationCode = checkVersionDigit(minVersionNumbers, currentVersionNumbers, 1); | ||
if (digitVerificationCode == 0) { | ||
digitVerificationCode = checkVersionDigit(minVersionNumbers, currentVersionNumbers, 2); | ||
if (digitVerificationCode == 0) { | ||
if (checkVersionDigit(minVersionNumbers, currentVersionNumbers, 3) == 1) { | ||
alertType = revisionUpdateAlertType; } | ||
} else if (digitVerificationCode == 1) { | ||
alertType = patchUpdateAlertType; | ||
|
||
Boolean versionUpdateDetected = false; | ||
for (Integer index = 0; index < Math.min(minVersionNumbers.length, currentVersionNumbers.length); index++) { | ||
Integer compareResult = checkVersionDigit(minVersionNumbers, currentVersionNumbers, index); | ||
if (compareResult == 1) { | ||
versionUpdateDetected = true; | ||
if (forceUpdateEnabled) { | ||
alertType = SirenAlertType.FORCE; | ||
} else { | ||
switch (index) { | ||
case 0: alertType = majorUpdateAlertType; break; | ||
case 1: alertType = minorUpdateAlertType; break; | ||
case 2: alertType = patchUpdateAlertType; break; | ||
case 3: alertType = revisionUpdateAlertType; break; | ||
default: alertType = SirenAlertType.OPTION; break; | ||
} | ||
} | ||
} else if (digitVerificationCode == 1) { | ||
alertType = minorUpdateAlertType; | ||
break; | ||
} else if (compareResult == -1) { | ||
return false; | ||
} | ||
} else if (digitVerificationCode == 1) { | ||
alertType = majorUpdateAlertType; | ||
} | ||
|
||
if (alertType != null) { | ||
if (versionUpdateDetected) { | ||
showAlert(minVersionName, alertType); | ||
return true; | ||
} | ||
|
@@ -231,13 +245,21 @@ private int checkVersionDigit(String[] minVersionNumbers, String[] currentVersio | |
private boolean checkVersionCode(JSONObject appJson) throws JSONException{ | ||
if (!appJson.isNull(Constants.JSON_MIN_VERSION_CODE)) { | ||
int minAppVersionCode = appJson.getInt(Constants.JSON_MIN_VERSION_CODE); | ||
// If no config found, assume version check is enabled | ||
Boolean versionCheckEnabled = appJson.has(Constants.JSON_ENABLE_VERSION_CHECK) ? appJson.getBoolean(Constants.JSON_ENABLE_VERSION_CHECK) : true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a small improvement, we can move the logic of getting Because we have duplication of the logic in the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created #30 |
||
if (!versionCheckEnabled) { | ||
return false; | ||
} | ||
|
||
// If no config found, assume force update = false | ||
Boolean forceUpdateEnabled = appJson.has(Constants.JSON_FORCE_ALERT_TYPE) ? appJson.getBoolean(Constants.JSON_FORCE_ALERT_TYPE) : false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think here it's possible to do the same as with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created #30 |
||
|
||
//save last successful verification date | ||
getSirenHelper().setLastVerificationDate(mApplicationContext); | ||
|
||
if (getSirenHelper().getVersionCode(mApplicationContext) < minAppVersionCode | ||
&& !getSirenHelper().isVersionSkippedByUser(mApplicationContext, String.valueOf(minAppVersionCode))) { | ||
showAlert(String.valueOf(minAppVersionCode), versionCodeUpdateAlertType); | ||
showAlert(String.valueOf(minAppVersionCode), forceUpdateEnabled ? SirenAlertType.FORCE : versionCodeUpdateAlertType); | ||
return true; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it will add more readability if we will use constants instead of "magic numbers".
ie
INDEX_MAJOR = 0
...INDEX_REVISION = 3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create #30