Get auto-refresh working.
This commit is contained in:
parent
7b53546126
commit
c6584e4eaa
|
@ -17,12 +17,15 @@ import org.osmdroid.tileprovider.tilesource.TileSourceFactory
|
|||
import org.osmdroid.util.GeoPoint
|
||||
import org.osmdroid.views.MapView
|
||||
import org.osmdroid.views.overlay.Marker
|
||||
import java.util.*
|
||||
import kotlin.concurrent.timerTask
|
||||
|
||||
class CollarListActivity : AppCompatActivity() {
|
||||
|
||||
// The list of collar summaries and its list adapter.
|
||||
private val summaries : MutableList<CollarSummary> = mutableListOf()
|
||||
private lateinit var summaryAdapter: CollarSummaryAdapter
|
||||
private lateinit var collarList: RecyclerView
|
||||
|
||||
// The API token and request queue.
|
||||
private lateinit var token: String
|
||||
|
@ -32,6 +35,9 @@ class CollarListActivity : AppCompatActivity() {
|
|||
private lateinit var map: MapView
|
||||
private val collarOverlays: MutableMap<Int, Marker> = mutableMapOf()
|
||||
|
||||
// Timer used to schedule refresh
|
||||
private val refreshTimer = Timer()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
|
@ -39,29 +45,25 @@ class CollarListActivity : AppCompatActivity() {
|
|||
PreferenceManager.getDefaultSharedPreferences(applicationContext))
|
||||
|
||||
setContentView(R.layout.activity_collar_list)
|
||||
findViews()
|
||||
|
||||
val collarList: RecyclerView = findViewById(R.id.collarSummaryList)
|
||||
val layoutManager = LinearLayoutManager(collarList.context)
|
||||
token = intent.getStringExtra("token")!!
|
||||
summaryAdapter = CollarSummaryAdapter(summaries)
|
||||
map = findViewById(R.id.map)
|
||||
map.setTileSource(TileSourceFactory.MAPNIK)
|
||||
queue = Volley.newRequestQueue(this)
|
||||
|
||||
collarList.adapter = summaryAdapter
|
||||
collarList.layoutManager = layoutManager
|
||||
collarList.addItemDecoration(DividerItemDecoration(collarList.context, layoutManager.orientation))
|
||||
triggerRefresh()
|
||||
setupCollarList()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
map.onResume()
|
||||
refreshTimer.schedule(timerTask { triggerRefresh() }, 0L, 5000L)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
map.onPause()
|
||||
refreshTimer.cancel()
|
||||
}
|
||||
|
||||
private fun triggerRefresh() {
|
||||
|
@ -79,6 +81,20 @@ class CollarListActivity : AppCompatActivity() {
|
|||
queue.add(request)
|
||||
}
|
||||
|
||||
private fun findViews() {
|
||||
collarList = findViewById(R.id.collarSummaryList)
|
||||
map = findViewById(R.id.map)
|
||||
}
|
||||
|
||||
private fun setupCollarList() {
|
||||
val layoutManager = LinearLayoutManager(collarList.context)
|
||||
summaryAdapter = CollarSummaryAdapter(summaries)
|
||||
collarList.adapter = summaryAdapter
|
||||
collarList.layoutManager = layoutManager
|
||||
collarList.addItemDecoration(DividerItemDecoration(collarList.context, layoutManager.orientation))
|
||||
refreshTimer.schedule(timerTask { triggerRefresh() }, 0L, 5000L)
|
||||
}
|
||||
|
||||
private fun updateMapOverlay() {
|
||||
val currentSet = mutableSetOf<Int>()
|
||||
summaries.forEach {
|
||||
|
@ -100,5 +116,6 @@ class CollarListActivity : AppCompatActivity() {
|
|||
collarOverlays.remove(it)
|
||||
}
|
||||
}
|
||||
map.invalidate()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
package com.danilafe.fencelessgrazing.model
|
||||
|
|
@ -3,6 +3,6 @@
|
|||
<string name="username">Username</string>
|
||||
<string name="password">Password</string>
|
||||
<string name="login">Log In</string>
|
||||
<string name="apiUrl">http://danilafe.com:8090</string>
|
||||
<string name="apiUrl">http://dev.danilafe.com:8090</string>
|
||||
<string name="collarSummaryLocation">Currently at %1f, %2f</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue
Block a user