-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kennyhu/fence 2091 geofence operatinghours not typed or mapped in nat…
…ive sdks (#405) * add operating hours to geofences * add tojson * bump patch version * add test * bump to beta * remove beta tag
- Loading branch information
1 parent
ec4845f
commit aa7e9cb
Showing
5 changed files
with
104 additions
and
4 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
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
67 changes: 67 additions & 0 deletions
67
sdk/src/main/java/io/radar/sdk/model/RadarOperatingHour.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,67 @@ | ||
package io.radar.sdk.model | ||
|
||
import org.json.JSONArray | ||
import org.json.JSONObject | ||
|
||
class RadarOperatingHour( | ||
val hours: MutableMap<String, Any> | ||
) { | ||
|
||
internal companion object { | ||
@JvmStatic | ||
fun fromJson(obj: JSONObject): RadarOperatingHour? { | ||
if (obj == null) { | ||
return null | ||
|
||
} | ||
|
||
val dictionary = mutableMapOf<String, Any>() | ||
|
||
for (key in obj.keys()) { | ||
val value = obj.get(key) | ||
// unwrap day | ||
if (value is JSONArray) { | ||
val list = mutableListOf<Any>() | ||
// unwrap pairs within the day | ||
for (i in 0 until value.length()) { | ||
val item = value.get(i) | ||
|
||
if (item is JSONArray && item.length() == 2) { | ||
val innerList = mutableListOf<Any>() | ||
innerList.add(item.get(0)) | ||
innerList.add(item.get(1)) | ||
list.add(innerList) | ||
} | ||
|
||
} | ||
dictionary[key] = list | ||
} | ||
} | ||
return RadarOperatingHour(dictionary) | ||
} | ||
} | ||
|
||
fun toJson(): JSONObject { | ||
val jsonObject = JSONObject() | ||
|
||
for ((key, value) in hours) { | ||
if (value is List<*>) { | ||
val jsonArray = JSONArray() | ||
|
||
for (innerList in value) { | ||
if (innerList is List<*>) { | ||
val jsonInnerArray = JSONArray() | ||
for (item in innerList) { | ||
jsonInnerArray.put(item) | ||
} | ||
jsonArray.put(jsonInnerArray) | ||
} | ||
} | ||
jsonObject.put(key, jsonArray) | ||
} | ||
} | ||
|
||
return jsonObject | ||
} | ||
|
||
} |
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