aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorKaeso <24925519+ptlthg@users.noreply.github.com>2023-10-27 18:48:59 -0400
committerGitHub <noreply@github.com>2023-10-28 00:48:59 +0200
commit51fa51d422a83a7cfcc22dfd2e4925b5e66ae205 (patch)
treed0aea2611c165abd7c155e68e2697d49cb8ece8e /src/main/java
parent96d86761b3f0ccf0c1c2290741b67d396e563c1d (diff)
downloadskyhanni-51fa51d422a83a7cfcc22dfd2e4925b5e66ae205.tar.gz
skyhanni-51fa51d422a83a7cfcc22dfd2e4925b5e66ae205.tar.bz2
skyhanni-51fa51d422a83a7cfcc22dfd2e4925b5e66ae205.zip
Prioritize selected profile when fetching weight (#632)
Incorrect Farming Weight from comparing Profile Names instead of ID #632
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt
index e8491ae96..41976bf07 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt
@@ -426,19 +426,31 @@ class FarmingWeightDisplay {
try {
val result = withContext(dispatcher) { APIUtil.getJSONResponse(url) }.asJsonObject
- for (profileEntry in result["profiles"].asJsonArray) {
- val profile = profileEntry.asJsonObject
- val profileName = profile["profileName"].asString.lowercase()
- if (profileName == localProfile) {
- profileId = profile["profileId"].asString
- weight = profile["totalWeight"].asDouble
+ val selectedProfileId = result["selectedProfileId"].asString
+ val profileEntries = result["profiles"].asJsonArray
+
+ var selectedProfileEntry = profileEntries.find {
+ it.asJsonObject["profileId"].asString == selectedProfileId
+ }?.asJsonObject
+
+ // If the selected profile is not found or if the cute name doesn't match look for a different profile
+ // While it's not optimal to loop twice, this shouldn't happen often
+ if (selectedProfileEntry == null || selectedProfileEntry["profileName"].asString.lowercase() != localProfile) {
+ selectedProfileEntry = profileEntries.find {
+ it.asJsonObject["profileName"].asString.lowercase() == localProfile
+ }?.asJsonObject
+ }
- localCounter.clear()
- dirtyCropWeight = true
+ if (selectedProfileEntry != null) {
+ profileId = selectedProfileEntry["profileId"].asString
+ weight = selectedProfileEntry["totalWeight"].asDouble
- return
- }
+ localCounter.clear()
+ dirtyCropWeight = true
+
+ return
}
+
println("localProfile: '$localProfile'")
println("url: '$url'")
println("result: '$result'")
@@ -531,4 +543,4 @@ class FarmingWeightDisplay {
class UpcomingPlayer(val name: String, val weight: Double)
}
-} \ No newline at end of file
+}