-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
1,674 additions
and
833 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
49 changes: 49 additions & 0 deletions
49
commons/src/main/java/fr/geonature/commons/util/JsonReaderHelper.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,49 @@ | ||
package fr.geonature.commons.util | ||
|
||
import android.util.JsonReader | ||
import android.util.JsonToken | ||
import android.util.JsonToken.NAME | ||
import android.util.JsonToken.STRING | ||
import java.io.IOException | ||
|
||
/** | ||
* Utility functions about JsonReader. | ||
* | ||
* @author S. Grimault | ||
*/ | ||
|
||
/** | ||
* Returns the next token, a property name, consumes it and check if its value matches the given `JsonToken`. | ||
*/ | ||
fun JsonReader.nextName(name: String, expected: JsonToken): JsonReader { | ||
return if (peek() == NAME) { | ||
val nextName = nextName() | ||
|
||
if (nextName != name) { | ||
throw IOException("Expected a property name '$name' but was '${peek().name}'") | ||
} | ||
|
||
if (peek() != expected) { | ||
throw IOException("Expected a property name '$name' to be '${expected.name}' but was '${peek().name}'") | ||
} | ||
|
||
this | ||
} else { | ||
throw IOException("Missing '$name' property") | ||
} | ||
} | ||
|
||
/** | ||
* Returns the string value of the next token and consuming it. | ||
* If the next token is not a string returns `null`. | ||
*/ | ||
fun JsonReader.nextStringOrNull(): String? { | ||
return when (peek()) { | ||
STRING -> { | ||
nextString() | ||
} | ||
else -> { | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#Tue Feb 02 20:36:43 CET 2021 | ||
VERSION_CODE=2680 | ||
#Sun Mar 28 16:42:31 CEST 2021 | ||
VERSION_CODE=2820 |
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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#Mon Feb 01 21:59:56 CET 2021 | ||
VERSION_CODE=150 | ||
#Sun Mar 28 16:43:24 CEST 2021 | ||
VERSION_CODE=300 |
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
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
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
Oops, something went wrong.