Query track endpoint and show start/enddate
This commit is contained in:
parent
c52daee815
commit
8521832315
@ -17,6 +17,7 @@ import de.hft.geotracker.GeofenceBroadcastReceiver
|
||||
import de.hft.geotracker.R
|
||||
import de.hft.geotracker.retrofit.*
|
||||
import kotlinx.android.synthetic.main.activity_home.*
|
||||
import kotlinx.android.synthetic.main.dropdown_menu.*
|
||||
import okhttp3.OkHttpClient
|
||||
import retrofit2.Call
|
||||
import retrofit2.Callback
|
||||
@ -32,6 +33,7 @@ class MainActivity : AppCompatActivity() {
|
||||
lateinit var geofence: Geofence
|
||||
lateinit var actionButton: TextView
|
||||
var running = false
|
||||
var accName: String? = null
|
||||
lateinit var accounts: ValuesTimetrackAccounts
|
||||
lateinit var service: GeofenceService
|
||||
lateinit var locationRequest: LocationRequest
|
||||
@ -151,6 +153,24 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
private fun callStartStop() {
|
||||
running = !running
|
||||
if (running) {
|
||||
account_spinner.visibility = View.GONE
|
||||
} else {
|
||||
account_spinner.visibility = View.VISIBLE
|
||||
}
|
||||
if (!accName.isNullOrEmpty()) {
|
||||
val call = service.triggerTracking(accName!!)
|
||||
call.enqueue(object : Callback<ValuesTracking> {
|
||||
override fun onResponse(call: Call<ValuesTracking>, response: Response<ValuesTracking>) {
|
||||
latitude.text = response.body()?.startdate
|
||||
longitude.text = response.body()?.enddate
|
||||
println("Tracking event successful!")
|
||||
}
|
||||
override fun onFailure(call: Call<ValuesTracking>, t: Throwable) {
|
||||
println("Problem at start tracking: " + t.message)
|
||||
}
|
||||
})
|
||||
}
|
||||
println("StartStop pressed: $running")
|
||||
//ToDO call /track Endpoint
|
||||
}
|
||||
@ -193,7 +213,8 @@ class MainActivity : AppCompatActivity() {
|
||||
position: Int,
|
||||
id: Long
|
||||
) {
|
||||
if (!accountNames.get(0).equals("rich")) {
|
||||
if (!accountNames.get(0).equals("None")) {
|
||||
accName = accounts.entries.get(position).name
|
||||
display_description.setText(accounts.entries.get(position).description)
|
||||
display_revenue.setText(accounts.entries.get(position).revenue.toString())
|
||||
} else {
|
||||
|
@ -4,6 +4,7 @@ import retrofit2.Call
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.POST
|
||||
import retrofit2.http.Query
|
||||
|
||||
interface GeofenceService {
|
||||
@POST("/login")
|
||||
@ -14,4 +15,7 @@ interface GeofenceService {
|
||||
|
||||
@GET("accounts")
|
||||
fun getAccounts(): Call<EmbeddedAccounts>
|
||||
|
||||
@GET("track")
|
||||
fun triggerTracking(@Query("account") account: String): Call<ValuesTracking>
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package de.hft.geotracker.retrofit
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
class ValuesTracking(
|
||||
duration: Int,
|
||||
start: String,
|
||||
end: String,
|
||||
account: String,
|
||||
user: String,
|
||||
type: String
|
||||
) {
|
||||
@SerializedName("duration")
|
||||
var duration = duration
|
||||
|
||||
@SerializedName("startdate")
|
||||
var startdate = start
|
||||
|
||||
@SerializedName("enddate")
|
||||
var enddate = end
|
||||
|
||||
@SerializedName("account")
|
||||
var account = account
|
||||
|
||||
@SerializedName("username")
|
||||
var username = user
|
||||
|
||||
@SerializedName("type")
|
||||
var type = type
|
||||
}
|
@ -188,11 +188,11 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:text="dummy"
|
||||
android:textAppearance="@style/text_style"
|
||||
android:textColor="@color/logo_white"
|
||||
app:layout_constraintBottom_toTopOf="@+id/longitude"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/display_revenue_layout" />
|
||||
@ -202,12 +202,13 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:text="dummy"
|
||||
android:textAppearance="@style/text_style"
|
||||
app:layout_constraintBottom_toTopOf="@+id/altitude"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/latitude" />
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue
Block a user