Skip to content

Commit

Permalink
Update library; Add alternative Nlb API
Browse files Browse the repository at this point in the history
  • Loading branch information
huikaihoo committed Sep 7, 2019
1 parent 99a6b1a commit f592e08
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 9 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ apply plugin: 'kotlin-kapt'
def versionMajor = 0
def versionMinor = 1
def versionPatch = 0
def versionSuffix = "-alpha.4"
def versionSuffix = "-alpha.5"

def versionBuild = 11
def versionBuild = 12

def static getBuildTime() {
def date = new Date()
Expand Down Expand Up @@ -111,7 +111,7 @@ dependencies {
implementation 'com.google.android.gms:play-services-oss-licenses:17.0.0'

// Firebase
implementation 'com.google.firebase:firebase-core:17.1.0'
implementation 'com.google.firebase:firebase-core:17.2.0'
implementation 'com.google.firebase:firebase-config:19.0.0'
implementation 'com.google.firebase:firebase-perf:19.0.0'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
Expand Down Expand Up @@ -166,7 +166,7 @@ dependencies {
// Unit Test
testImplementation 'androidx.arch.core:core-testing:2.1.0-rc01'
testImplementation 'androidx.room:room-testing:2.1.0'
testImplementation 'junit:junit:4.13-beta-3'
testImplementation 'junit:junit:4.12'
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlin_coroutines_version"
testImplementation 'org.robolectric:robolectric:4.3'

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/hoo/etahk/remote/api/NlbApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package hoo.etahk.remote.api

import hoo.etahk.remote.request.NlbEtaReq
import hoo.etahk.remote.response.NlbDatabaseRes
import hoo.etahk.remote.response.NlbEta2Res
import hoo.etahk.remote.response.NlbEtaRes
import okhttp3.ResponseBody
import retrofit2.Call
Expand All @@ -18,6 +19,9 @@ interface NlbApi {
@POST("api/passenger/stop.php?action=estimatedArrivalTime")
fun getEta(@Body request : NlbEtaReq): Call<NlbEtaRes>

@POST("https://rt.data.gov.hk/v1/transport/nlb/stop.php?action=estimatedArrivals")
fun getEta2(@Body request : NlbEtaReq): Call<NlbEta2Res>

@GET("api/passenger/route.php?action=getDetail")
fun getTimetable(@Query("routeId") routeId: String): Call<ResponseBody>
}
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,11 @@ object KmbConnection: BaseConnection {

if (kmbEtaRes?.response != null && kmbEtaRes.response.isNotEmpty()) {
(kmbEtaRes.response).forEach {
etaResults.add(toEtaResult(stop, it))
if (it.t?.isNotBlank() == true) {
etaResults.add(toEtaResult(stop, it))
} else if (etaResults.isEmpty()) {
etaResults.add(toEtaResult(stop, AppHelper.getString(R.string.eta_msg_no_eta_info)))
}
}
//logd(AppHelper.gson.toJson(etaResults))
} else {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/hoo/etahk/remote/response/KmbEtaRes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.google.gson.annotations.SerializedName

data class KmbEtaRes(
@SerializedName("generated") val generated: Long? = 0,
@SerializedName("response") val response: List<Response>? = emptyList(),
@SerializedName("response") val response: List<Response>? = listOf(),
@SerializedName("responsecode") val responsecode: Long? = 0,
@SerializedName("updated") val updated: Long? = 0
) {
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/hoo/etahk/remote/response/NlbEta2Res.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package hoo.etahk.remote.response

import com.google.gson.annotations.SerializedName

data class NlbEta2Res(
@SerializedName("estimatedArrivals") val estimatedArrivals: List<EstimatedArrival?>? = listOf(),
@SerializedName("message") val message: String? = ""
) {
data class EstimatedArrival(
@SerializedName("estimatedArrivalTime") val estimatedArrivalTime: String? = "",
@SerializedName("routeVariantName") val routeVariantName: String? = "",
@SerializedName("departed") val departed: Long? = 0,
@SerializedName("noGPS") val noGPS: Long? = 0,
@SerializedName("wheelChair") val wheelChair: Long? = 0,
@SerializedName("generateTime") val generateTime: String? = ""
)
}
27 changes: 25 additions & 2 deletions app/src/test/java/hoo/etahk/api/NlbApiUnitTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import org.robolectric.annotation.Config
@Config(manifest = Config.NONE)
class NlbApiUnitTest {

private val routeId = "88" // 1 88
private val stopId = "78" // 28 105
private val routeId = "88" // 1 88 3
private val stopId = "78" // 28 105 127

@Test
fun getParentRoutes() {
Expand Down Expand Up @@ -73,4 +73,27 @@ class NlbApiUnitTest {
assert(false)
}
}

@Test
fun getEta2() {
val call = ConnectionHelper.nlb.getEta2(NlbEtaReq(routeId = routeId, stopId = stopId))
println("url = ${call.request().url()}")

try {
val response = call.execute()
println("isSuccessful = ${response.isSuccessful}")

if (response.isSuccessful) {
val result = response.body()
println("result = $result")
assert(result != null && !(result.estimatedArrivals.isNullOrEmpty() && result.message.isNullOrBlank()))
} else {
println("error = ${response.errorBody()?.string()}")
assert(false)
}
} catch (e: Exception) {
e.printStackTrace()
assert(false)
}
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.google.android.gms:oss-licenses-plugin:0.9.5'
classpath 'com.google.firebase:perf-plugin:1.3.1'
classpath 'com.google.gms:google-services:4.3.0'
classpath 'com.google.gms:google-services:4.3.2'
classpath 'de.undercouch:gradle-download-task:3.4.3'
classpath 'io.fabric.tools:gradle:1.29.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Expand Down

0 comments on commit f592e08

Please sign in to comment.