Skip to content

Commit

Permalink
first implementation of global data mode
Browse files Browse the repository at this point in the history
  • Loading branch information
wuan committed Dec 13, 2019
1 parent 9dfc500 commit 1cd78c0
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- fix notifications for newer devices
- improve location detection
- use Dagger2 for internal dependency injection
- global data mode

### Version 1.5.18

Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "org.blitzortung.android.app"
minSdkVersion 15
targetSdkVersion 29
versionCode 249
versionName "2.0.17"
versionCode 250
versionName "2.0.18"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import org.blitzortung.android.app.view.get
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.data.DataProvider
import org.blitzortung.android.data.provider.data.DataProvider.DataRetriever
import org.blitzortung.android.data.provider.DataProviderType
import org.blitzortung.android.data.provider.result.ResultEvent
import org.blitzortung.android.jsonrpc.JsonRpcClient
import org.blitzortung.android.util.TimeFormat
Expand Down Expand Up @@ -71,7 +71,7 @@ class JsonRpcDataProvider @Inject constructor(
val strikes = ArrayList<Strike>()
val referenceTimestamp = getReferenceTimestamp(response)
val strikesArray = response.get("s") as JSONArray
for (i in 0..strikesArray.length() - 1) {
for (i in 0 until strikesArray.length()) {
strikes.add(dataBuilder.createDefaultStrike(referenceTimestamp, strikesArray.getJSONArray(i)))
}
if (response.has("next")) {
Expand All @@ -86,7 +86,7 @@ class JsonRpcDataProvider @Inject constructor(

val strikesArray = response.get("r") as JSONArray
val strikes = ArrayList<Strike>()
for (i in 0..strikesArray.length() - 1) {
for (i in 0 until strikesArray.length()) {
strikes.add(dataBuilder.createRasterElement(rasterParameters, referenceTimestamp, strikesArray.getJSONArray(i)))
}

Expand All @@ -107,7 +107,7 @@ class JsonRpcDataProvider @Inject constructor(

val histogram = IntArray(histogramArray.length())

for (i in 0..histogramArray.length() - 1) {
for (i in 0 until histogramArray.length()) {
histogram[i] = histogramArray.getInt(i)
}
resultVar = resultVar.copy(histogram = histogram)
Expand All @@ -127,7 +127,7 @@ class JsonRpcDataProvider @Inject constructor(
val response = client.call(serviceUrl, "get_stations")
val stationsArray = response.get("stations") as JSONArray

for (i in 0..stationsArray.length() - 1) {
for (i in 0 until stationsArray.length()) {
stations.add(dataBuilder.createStation(stationsArray.getJSONArray(i)))
}
} catch (e: Exception) {
Expand All @@ -149,7 +149,14 @@ class JsonRpcDataProvider @Inject constructor(
val region = parameters.region

try {
val response = client.call(serviceUrl, "get_strikes_grid", intervalDuration, rasterBaselength, intervalOffset, region, countThreshold)
val response = if (region == 0) {
with(client.call(serviceUrl, "get_global_strikes_grid", intervalDuration, rasterBaselength, intervalOffset, countThreshold)) {
put("y1", 0.0)
put("x0", 0.0)
}
} else {
client.call(serviceUrl, "get_strikes_grid", intervalDuration, rasterBaselength, intervalOffset, region, countThreshold)
}
val minDistance = rasterBaselength / 1000f
resultVar = addRasterData(response, resultVar, minDistance)
resultVar = addStrikesHistogram(response, resultVar)
Expand Down Expand Up @@ -190,18 +197,18 @@ class JsonRpcDataProvider @Inject constructor(
@Suppress("NON_EXHAUSTIVE_WHEN")
when (key) {
PreferenceKey.SERVICE_URL -> {
val serviceUrl : String = sharedPreferences.get(PreferenceKey.SERVICE_URL, DEFAULT_SERVICE_URL.toString())
val serviceUrl: String = sharedPreferences.get(PreferenceKey.SERVICE_URL, DEFAULT_SERVICE_URL.toString())
this.serviceUrl = toCheckedUrl(if (serviceUrl.isNotBlank()) serviceUrl.trim() else DEFAULT_SERVICE_URL.toString())
}
}
}

private fun toCheckedUrl(serviceUrl: String): URL {
try {
return URL(serviceUrl)
return try {
URL(serviceUrl)
} catch (e: Exception) {
Log.e(Main.LOG_TAG, "JsonRpcDataProvider.tocheckedUrl($serviceUrl) invalid")
return DEFAULT_SERVICE_URL
DEFAULT_SERVICE_URL
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class StrikeListOverlay(private val mapFragment: MapFragment, val colorHandler:
}

val paint = Paint()
if (hasRasterParameters()) {
if (hasRasterParameters() && parameters.region > 0) {
paint.color = colorHandler.lineColor
paint.style = Style.STROKE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class VersionComponentTest {
}

companion object {
val CURRENT_VERSION_CODE = 249
val CURRENT_VERSION_NAME = "2.0.17"
val CURRENT_VERSION_CODE = 250
val CURRENT_VERSION_NAME = "2.0.18"
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.4'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.3'
Expand Down

0 comments on commit 1cd78c0

Please sign in to comment.