Start work on collar details.
This commit is contained in:
parent
c6584e4eaa
commit
9983753912
|
@ -13,7 +13,8 @@
|
|||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".CollarListActivity"></activity>
|
||||
<activity android:name=".CollarDetailActivity"></activity>
|
||||
<activity android:name=".CollarListActivity" />
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package com.danilafe.fencelessgrazing
|
||||
|
||||
import com.danilafe.fencelessgrazing.model.CollarSummary
|
||||
|
||||
interface CollarClickListener {
|
||||
fun onCollarClick(collar: CollarSummary?)
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.danilafe.fencelessgrazing
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
|
||||
class CollarDetailActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var token: String
|
||||
private var collarId: Int = -1
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_collar_detail)
|
||||
|
||||
token = intent.getStringExtra("token")!!
|
||||
collarId = intent.getIntExtra("identifier", -1)
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package com.danilafe.fencelessgrazing
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
|
@ -36,7 +37,7 @@ class CollarListActivity : AppCompatActivity() {
|
|||
private val collarOverlays: MutableMap<Int, Marker> = mutableMapOf()
|
||||
|
||||
// Timer used to schedule refresh
|
||||
private val refreshTimer = Timer()
|
||||
private var refreshTimer = Timer()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -57,6 +58,7 @@ class CollarListActivity : AppCompatActivity() {
|
|||
override fun onResume() {
|
||||
super.onResume()
|
||||
map.onResume()
|
||||
refreshTimer = Timer()
|
||||
refreshTimer.schedule(timerTask { triggerRefresh() }, 0L, 5000L)
|
||||
}
|
||||
|
||||
|
@ -86,9 +88,22 @@ class CollarListActivity : AppCompatActivity() {
|
|||
map = findViewById(R.id.map)
|
||||
}
|
||||
|
||||
private fun startCollarDetailActivity(collar: CollarSummary) {
|
||||
val newIntent = Intent(this, CollarDetailActivity::class.java).apply {
|
||||
putExtra("token", token)
|
||||
putExtra("identifier", collar.id)
|
||||
}
|
||||
startActivity(newIntent)
|
||||
}
|
||||
|
||||
private fun setupCollarList() {
|
||||
val layoutManager = LinearLayoutManager(collarList.context)
|
||||
summaryAdapter = CollarSummaryAdapter(summaries)
|
||||
summaryAdapter = CollarSummaryAdapter(summaries, object : CollarClickListener {
|
||||
override fun onCollarClick(collar: CollarSummary?) {
|
||||
if (collar == null) return
|
||||
startCollarDetailActivity(collar)
|
||||
}
|
||||
})
|
||||
collarList.adapter = summaryAdapter
|
||||
collarList.layoutManager = layoutManager
|
||||
collarList.addItemDecoration(DividerItemDecoration(collarList.context, layoutManager.orientation))
|
||||
|
|
|
@ -12,7 +12,8 @@ import com.danilafe.fencelessgrazing.model.CollarSummary
|
|||
import com.danilafe.fencelessgrazing.requests.CollarRequest
|
||||
|
||||
class CollarSummaryAdapter(
|
||||
private val items : List<CollarSummary>
|
||||
private val items: List<CollarSummary>,
|
||||
private val collarClickListener: CollarClickListener
|
||||
) : ListAdapter<CollarSummary, CollarViewHolder>(DiffCallback()) {
|
||||
|
||||
class DiffCallback : DiffUtil.ItemCallback<CollarSummary>() {
|
||||
|
@ -29,7 +30,7 @@ class CollarSummaryAdapter(
|
|||
}
|
||||
|
||||
override fun onBindViewHolder(holder: CollarViewHolder, position: Int) {
|
||||
holder.bindData(getItem(position))
|
||||
holder.bindData(getItem(position), collarClickListener)
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int = R.layout.collar_summary_layout
|
||||
|
|
|
@ -9,9 +9,12 @@ class CollarViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
|||
private val nameView: TextView = itemView.findViewById(R.id.collarSummaryName)
|
||||
private val positionView: TextView = itemView.findViewById(R.id.collarSummaryPos)
|
||||
|
||||
fun bindData(summary: CollarSummary) {
|
||||
fun bindData(summary: CollarSummary, collarClickListener: CollarClickListener) {
|
||||
nameView.text = summary.name
|
||||
// TODO figure out how to get getString here.
|
||||
positionView.text = "Currently at ${summary.pos.longitude}, ${summary.pos.latitude}"
|
||||
itemView.setOnClickListener {
|
||||
collarClickListener.onCollarClick(summary)
|
||||
}
|
||||
}
|
||||
}
|
9
app/src/main/res/layout/activity_collar_detail.xml
Normal file
9
app/src/main/res/layout/activity_collar_detail.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".CollarDetailActivity">
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue
Block a user