Skip to content

Commit

Permalink
extract JsonRpc data call
Browse files Browse the repository at this point in the history
  • Loading branch information
wuan committed Oct 15, 2023
1 parent 8adc1cc commit 1943b93
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 53 deletions.
6 changes: 0 additions & 6 deletions app/src/main/java/org/blitzortung/android/app/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,6 @@ class Main : FragmentActivity(), OnSharedPreferenceChangeListener {
}
}
}

override fun onStartTrackingTouch(p0: SeekBar?) {
}

override fun onStopTrackingTouch(p0: SeekBar?) {
}
})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.blitzortung.android.data.provider.standard

import org.blitzortung.android.data.Parameters
import org.blitzortung.android.data.provider.GLOBAL_REGION
import org.blitzortung.android.data.provider.LOCAL_REGION
import org.blitzortung.android.jsonrpc.JsonRpcClient
import org.json.JSONObject
import java.net.URL

class JsonRpcData(
private val client: JsonRpcClient,
private val serviceUrl: URL,
) {

fun requestData(parameters: Parameters) : JSONObject {
val intervalDuration = parameters.intervalDuration
val intervalOffset = parameters.intervalOffset
val rasterBaselength = parameters.rasterBaselength
val countThreshold = parameters.countThreshold
val region = parameters.region
val localReference = parameters.localReference

return when (region) {
GLOBAL_REGION -> {
with(
client.call(
serviceUrl,
"get_global_strikes_grid",
intervalDuration,
rasterBaselength,
intervalOffset,
countThreshold
)
) {
put("y1", 0.0)
put("x0", 0.0)
}
}
LOCAL_REGION -> {
client.call(
serviceUrl,
"get_local_strikes_grid",
localReference!!.x,
localReference.y,
rasterBaselength,
intervalDuration,
intervalOffset,
countThreshold
)
}
else -> {
client.call(
serviceUrl,
"get_strikes_grid",
intervalDuration,
rasterBaselength,
intervalOffset,
region,
countThreshold
)
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import org.blitzortung.android.data.Parameters
import org.blitzortung.android.data.beans.Station
import org.blitzortung.android.data.beans.Strike
import org.blitzortung.android.data.provider.DataProviderType
import org.blitzortung.android.data.provider.GLOBAL_REGION
import org.blitzortung.android.data.provider.LOCAL_REGION
import org.blitzortung.android.data.provider.data.DataProvider
import org.blitzortung.android.data.provider.data.DataProvider.DataRetriever
import org.blitzortung.android.data.provider.data.initializeResult
Expand Down Expand Up @@ -154,51 +152,9 @@ class JsonRpcDataProvider @Inject constructor(

nextId = 0

val intervalDuration = parameters.intervalDuration
val intervalOffset = parameters.intervalOffset
val rasterBaselength = parameters.rasterBaselength
val countThreshold = parameters.countThreshold
val region = parameters.region

try {
val response = if (region == GLOBAL_REGION) {
with(
client.call(
serviceUrl,
"get_global_strikes_grid",
intervalDuration,
rasterBaselength,
intervalOffset,
countThreshold
)
) {
put("y1", 0.0)
put("x0", 0.0)
}
} else if (region == LOCAL_REGION) {
val localReference = parameters.localReference!!
client.call(
serviceUrl,
"get_local_strikes_grid",
localReference.x,
localReference.y,
rasterBaselength,
intervalDuration,
intervalOffset,
countThreshold
)
} else {
client.call(
serviceUrl,
"get_strikes_grid",
intervalDuration,
rasterBaselength,
intervalOffset,
region,
countThreshold
)
}
result = addRasterData(response, result, rasterBaselength)
val response = JsonRpcData(client, serviceUrl).requestData(parameters)
result = addRasterData(response, result, parameters.rasterBaselength)
result = addStrikesHistogram(response, result)
} catch (e: Exception) {
throw RuntimeException(e)
Expand All @@ -209,7 +165,7 @@ class JsonRpcDataProvider @Inject constructor(
"JsonRpcDataProvider: read %d bytes (%d raster positions, region %d)".format(
client.lastNumberOfTransferredBytes,
result.strikes?.size,
region
parameters.region
)
)
return result
Expand Down

0 comments on commit 1943b93

Please sign in to comment.