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]
|
val item = data[position]
|
||||||
holder.textFrom.setText("Start: " + item.from)
|
holder.textFrom.setText("Start: " + item.from)
|
||||||
holder.textTo.setText("End: " + item.to)
|
holder.textTo.setText("End: " + item.to)
|
||||||
// item.from.toInt()
|
if (item.duration != -1) {
|
||||||
//ToDo calculate diference to show the amount of working time
|
holder.textTotal.setText("Duration: " + item.duration)
|
||||||
holder.textTotal.setText("Total: 00:42")
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
lateinit var actionButton: TextView
|
lateinit var actionButton: TextView
|
||||||
var running = false
|
var running = false
|
||||||
var accName: String? = null
|
var accName: String? = null
|
||||||
|
var workingSince: String? = null
|
||||||
lateinit var accounts: ValuesTimetrackAccounts
|
lateinit var accounts: ValuesTimetrackAccounts
|
||||||
lateinit var service: GeofenceService
|
lateinit var service: GeofenceService
|
||||||
lateinit var locationRequest: LocationRequest
|
lateinit var locationRequest: LocationRequest
|
||||||
@ -108,6 +109,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val retrofit = builder.build()
|
val retrofit = builder.build()
|
||||||
service = retrofit.create(GeofenceService::class.java)
|
service = retrofit.create(GeofenceService::class.java)
|
||||||
showUsername()
|
showUsername()
|
||||||
|
updateRecyclerView()
|
||||||
|
|
||||||
actionButton = findViewById(R.id.button_start_stop)
|
actionButton = findViewById(R.id.button_start_stop)
|
||||||
actionButton.setBackgroundColor(resources.getColor(R.color.colorPrimaryDark))
|
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
|
val recView: RecyclerView = records_list
|
||||||
recView.setHasFixedSize(true)
|
recView.setHasFixedSize(true)
|
||||||
val layoutManager: RecyclerView.LayoutManager = LinearLayoutManager(this)
|
val layoutManager: RecyclerView.LayoutManager = LinearLayoutManager(this)
|
||||||
val adapter = RecordsAdapter()
|
val adapter = RecordsAdapter()
|
||||||
adapter.data = exampleList
|
val recordList = ArrayList<RecordEntry>()
|
||||||
recView.layoutManager = layoutManager
|
|
||||||
recView.adapter = adapter
|
|
||||||
|
|
||||||
|
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() {
|
private fun callStartStop() {
|
||||||
@ -163,8 +192,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val call = service.triggerTracking(accName!!)
|
val call = service.triggerTracking(accName!!)
|
||||||
call.enqueue(object : Callback<ValuesTracking> {
|
call.enqueue(object : Callback<ValuesTracking> {
|
||||||
override fun onResponse(call: Call<ValuesTracking>, response: Response<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
|
longitude.text = response.body()?.enddate
|
||||||
|
updateRecyclerView()
|
||||||
println("Tracking event successful!")
|
println("Tracking event successful!")
|
||||||
}
|
}
|
||||||
override fun onFailure(call: Call<ValuesTracking>, t: Throwable) {
|
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 from = from
|
||||||
val to = to
|
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")
|
@GET("track")
|
||||||
fun triggerTracking(@Query("account") account: String): Call<ValuesTracking>
|
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:layout_height="wrap_content"
|
||||||
android:paddingStart="16dp"
|
android:paddingStart="16dp"
|
||||||
android:paddingEnd="16dp"
|
android:paddingEnd="16dp"
|
||||||
android:text="Start: test"
|
|
||||||
android:textAlignment="textStart"
|
android:textAlignment="textStart"
|
||||||
android:textAppearance="@style/text_style"
|
android:textAppearance="@style/text_style"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
@ -33,7 +32,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="16dp"
|
android:paddingStart="16dp"
|
||||||
android:paddingEnd="16dp"
|
android:paddingEnd="16dp"
|
||||||
android:text="End: test"
|
|
||||||
android:textAlignment="viewStart"
|
android:textAlignment="viewStart"
|
||||||
android:textAppearance="@style/text_style"
|
android:textAppearance="@style/text_style"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
@ -47,7 +45,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="16dp"
|
android:paddingStart="16dp"
|
||||||
android:paddingEnd="16dp"
|
android:paddingEnd="16dp"
|
||||||
android:text="Total: test"
|
|
||||||
android:textAppearance="@style/text_style"
|
android:textAppearance="@style/text_style"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
Loading…
Reference in New Issue
Block a user