-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #715 from nightscout/prep2.8.2.1
2.8.2.1
- Loading branch information
Showing
4 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...java/info/nightscout/androidaps/plugins/constraints/versionChecker/AllowedVersionsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package info.nightscout.androidaps.plugins.constraints.versionChecker | ||
|
||
import org.junit.Assert.* | ||
import org.junit.Test | ||
|
||
class AllowedVersionsTest { | ||
|
||
@Test | ||
fun generateSupportedVersionsTest() { | ||
val definition = AllowedVersions().generateSupportedVersions() | ||
assertNull(AllowedVersions().findByApi(definition, 0)) | ||
assertFalse(AllowedVersions().findByApi(definition, 1)?.has("supported") ?: true) | ||
assertFalse(AllowedVersions().findByApi(definition, 23)?.has("supported") ?: true) | ||
assertEquals("2.6.2", AllowedVersions().findByApi(definition, 24)?.getString("supported")) | ||
assertEquals("2.6.2", AllowedVersions().findByApi(definition, 25)?.getString("supported")) | ||
assertEquals("2.8.2", AllowedVersions().findByApi(definition, 26)?.getString("supported")) | ||
assertEquals("2.8.2", AllowedVersions().findByApi(definition, 27)?.getString("supported")) | ||
assertEquals("2.8.2", AllowedVersions().findByApi(definition, 28)?.getString("supported")) | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...ain/java/info/nightscout/androidaps/plugins/constraints/versionChecker/AllowedVersions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package info.nightscout.androidaps.plugins.constraints.versionChecker | ||
|
||
import org.json.JSONArray | ||
import org.json.JSONException | ||
import org.json.JSONObject | ||
|
||
class AllowedVersions { | ||
|
||
fun generateSupportedVersions(): String = | ||
JSONArray() | ||
.put(JSONObject().apply { | ||
put("minAndroid", 1) // 1.0 | ||
put("maxAndroid", 23) // 6.0.1 | ||
}) | ||
.put(JSONObject().apply { | ||
put("minAndroid", 24) // 7.0 | ||
put("maxAndroid", 25) // 7.1.2 | ||
put("supported", "2.6.2") | ||
}) | ||
.put(JSONObject().apply { | ||
put("minAndroid", 26) // 8.0 | ||
put("maxAndroid", 27) // 8.1 | ||
put("supported", "2.8.2") | ||
}) | ||
.put(JSONObject().apply { | ||
put("minAndroid", 28) // 9.0 | ||
put("maxAndroid", 99) | ||
put("supported", "2.8.2") | ||
}) | ||
.toString() | ||
|
||
fun findByApi(definition: String?, api: Int): JSONObject? { | ||
if (definition == null) return null | ||
try { | ||
val array = JSONArray(definition) | ||
for (i in 0 until array.length()) { | ||
val record = array[i] as JSONObject | ||
if (api in record.getInt("minAndroid")..record.getInt("maxAndroid")) return record | ||
} | ||
} catch (e: JSONException) { | ||
} | ||
return null | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters