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