Query /today endpoint an display response
This commit is contained in:
parent
08ffe71433
commit
c304632d6e
@ -29,9 +29,10 @@ class RecordsAdapter : RecyclerView.Adapter<TextItemViewHolder>() {
|
||||
val item = data[position]
|
||||
holder.textFrom.setText("Start: " + item.from)
|
||||
holder.textTo.setText("End: " + item.to)
|
||||
// item.from.toInt()
|
||||
//ToDo calculate diference to show the amount of working time
|
||||
holder.textTotal.setText("Total: 00:42")
|
||||
if (item.duration != -1) {
|
||||
holder.textTotal.setText("Duration: " + item.duration)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ class MainActivity : AppCompatActivity() {
|
||||
lateinit var actionButton: TextView
|
||||
var running = false
|
||||
var accName: String? = null
|
||||
var workingSince: String? = null
|
||||
lateinit var accounts: ValuesTimetrackAccounts
|
||||
lateinit var service: GeofenceService
|
||||
lateinit var locationRequest: LocationRequest
|
||||
@ -108,6 +109,7 @@ class MainActivity : AppCompatActivity() {
|
||||
val retrofit = builder.build()
|
||||
service = retrofit.create(GeofenceService::class.java)
|
||||
showUsername()
|
||||
updateRecyclerView()
|
||||
|
||||
actionButton = findViewById(R.id.button_start_stop)
|
||||
actionButton.setBackgroundColor(resources.getColor(R.color.colorPrimaryDark))
|
||||
@ -133,21 +135,48 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
//Recycler View
|
||||
//ToDo Get data from /records/search/today and fill into recycler view
|
||||
val exampleList = ArrayList<RecordEntry>()
|
||||
exampleList.add(RecordEntry("8:00", "10:00"))
|
||||
exampleList.add(RecordEntry("10:15", "12:00"))
|
||||
exampleList.add(RecordEntry("12:45", "16:00"))
|
||||
|
||||
|
||||
}
|
||||
|
||||
private fun updateRecyclerView() {
|
||||
//Recycler View
|
||||
val recView: RecyclerView = records_list
|
||||
recView.setHasFixedSize(true)
|
||||
val layoutManager: RecyclerView.LayoutManager = LinearLayoutManager(this)
|
||||
val adapter = RecordsAdapter()
|
||||
adapter.data = exampleList
|
||||
val recordList = ArrayList<RecordEntry>()
|
||||
|
||||
val call = service.getTodaysRecords()
|
||||
call.enqueue(object: Callback<EmbeddedRecords> {
|
||||
override fun onResponse(call: Call<EmbeddedRecords>, response: Response<EmbeddedRecords>) {
|
||||
if (response.isSuccessful) {
|
||||
val entries = response.body()!!.records.entries
|
||||
if (!entries.isEmpty()) {
|
||||
entries.forEach {
|
||||
recordList.add(RecordEntry(it.startdate.substring(11, 16)
|
||||
, it.enddate.substring(11, 16)
|
||||
, it.duration))
|
||||
}
|
||||
if (running) {
|
||||
// recordList.add(RecordEntry(workingSince!!, "PENDING", -1))
|
||||
}
|
||||
adapter.data = recordList
|
||||
recView.layoutManager = layoutManager
|
||||
recView.adapter = adapter
|
||||
} else {
|
||||
println("No Records!")
|
||||
}
|
||||
|
||||
} else {
|
||||
println("Response for todays records was not successful")
|
||||
}
|
||||
}
|
||||
override fun onFailure(call: Call<EmbeddedRecords>, t: Throwable) {
|
||||
println("Getting todays records failed")
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
private fun callStartStop() {
|
||||
@ -163,8 +192,10 @@ class MainActivity : AppCompatActivity() {
|
||||
val call = service.triggerTracking(accName!!)
|
||||
call.enqueue(object : Callback<ValuesTracking> {
|
||||
override fun onResponse(call: Call<ValuesTracking>, response: Response<ValuesTracking>) {
|
||||
latitude.text = response.body()?.startdate
|
||||
workingSince = response.body()?.startdate?.substring(11, 16)
|
||||
latitude.text = workingSince
|
||||
longitude.text = response.body()?.enddate
|
||||
updateRecyclerView()
|
||||
println("Tracking event successful!")
|
||||
}
|
||||
override fun onFailure(call: Call<ValuesTracking>, t: Throwable) {
|
||||
@ -341,9 +372,10 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
}
|
||||
|
||||
class RecordEntry(from: String, to: String) {
|
||||
class RecordEntry(from: String, to: String, duration: Int) {
|
||||
val from = from
|
||||
val to = to
|
||||
val duration = duration
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,8 @@
|
||||
package de.hft.geotracker.retrofit
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
class EmbeddedRecords(records: ValuesRecordsArray) {
|
||||
@SerializedName("_embedded")
|
||||
var records = records
|
||||
}
|
@ -15,4 +15,7 @@ interface GeofenceService {
|
||||
|
||||
@GET("track")
|
||||
fun triggerTracking(@Query("account") account: String): Call<ValuesTracking>
|
||||
|
||||
@GET("records/search/today")
|
||||
fun getTodaysRecords(): Call<EmbeddedRecords>
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package de.hft.geotracker.retrofit
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
class ValuesRecordEntry(
|
||||
start: String,
|
||||
end: String,
|
||||
type: String,
|
||||
duration: Int
|
||||
) {
|
||||
@SerializedName("startdate")
|
||||
var startdate = start
|
||||
|
||||
@SerializedName("enddate")
|
||||
var enddate = end
|
||||
|
||||
@SerializedName("type")
|
||||
var type = type
|
||||
|
||||
@SerializedName("duration")
|
||||
var duration = duration
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package de.hft.geotracker.retrofit
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
class ValuesRecordsArray(entries: Array<ValuesRecordEntry>) {
|
||||
@SerializedName("records")
|
||||
var entries = entries
|
||||
}
|
@ -20,7 +20,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:text="Start: test"
|
||||
android:textAlignment="textStart"
|
||||
android:textAppearance="@style/text_style"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
@ -33,7 +32,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:text="End: test"
|
||||
android:textAlignment="viewStart"
|
||||
android:textAppearance="@style/text_style"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
@ -47,7 +45,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:text="Total: test"
|
||||
android:textAppearance="@style/text_style"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
Loading…
Reference in New Issue
Block a user