Comparar commits

..

No hay commits en común. "246d43be8051362acd9bd830d66c9231c0cbf591" y "c6584e4eaa4c644536c883322ef367327352dc6d" tienen historias totalmente diferentes.

Se han modificado 8 ficheros con 7 adiciones y 118 borrados

Ver fichero

@ -3,7 +3,7 @@
package="com.danilafe.fencelessgrazing"> package="com.danilafe.fencelessgrazing">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application <application
@ -13,8 +13,7 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity android:name=".CollarDetailActivity"></activity> <activity android:name=".CollarListActivity"></activity>
<activity android:name=".CollarListActivity" />
<activity android:name=".MainActivity"> <activity android:name=".MainActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />

Ver fichero

@ -1,7 +0,0 @@
package com.danilafe.fencelessgrazing
import com.danilafe.fencelessgrazing.model.CollarSummary
interface CollarClickListener {
fun onCollarClick(collar: CollarSummary?)
}

Ver fichero

@ -1,66 +0,0 @@
package com.danilafe.fencelessgrazing
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.danilafe.fencelessgrazing.model.CollarPos
import com.danilafe.fencelessgrazing.model.Polygon
import org.osmdroid.util.GeoPoint
import org.osmdroid.views.MapView
class CollarDetailActivity : AppCompatActivity() {
private lateinit var token: String
private var collarId: Int = -1
private lateinit var map: MapView
private lateinit var mapPolygon: org.osmdroid.views.overlay.Polygon
private var boundingBox: Polygon? = null
set(newValue) {
if(newValue != null) updateBoundingBox(field, newValue)
else clearBoundingBox()
field = newValue
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_collar_detail)
token = intent.getStringExtra("token")!!
collarId = intent.getIntExtra("identifier", -1)
map = findViewById(R.id.detailMap)
mapPolygon = org.osmdroid.views.overlay.Polygon(map)
configureMapPolygon()
}
private fun configureMapPolygon() {
mapPolygon.fillPaint.color = Color.CYAN
mapPolygon.fillPaint.alpha = 127
mapPolygon.outlinePaint.strokeWidth = 0.0f
mapPolygon.title = "Valid Grazing Area"
}
private fun updateBoundingBox(oldValue: Polygon?, polygon: Polygon) {
if(oldValue == null) map.overlays.add(mapPolygon)
val points = polygon.dataPoints.map { GeoPoint(it.longitude.toDouble(), it.latitude.toDouble()) }
val polygonPoints = points.toMutableList()
polygonPoints.add(polygonPoints[0])
mapPolygon.points = polygonPoints
}
private fun clearBoundingBox() {
map.overlays.remove(mapPolygon)
}
override fun onPause() {
super.onPause()
map.onPause()
}
override fun onResume() {
super.onResume()
map.onResume()
}
}

Ver fichero

@ -1,6 +1,5 @@
package com.danilafe.fencelessgrazing package com.danilafe.fencelessgrazing
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.widget.Toast import android.widget.Toast
@ -37,7 +36,7 @@ class CollarListActivity : AppCompatActivity() {
private val collarOverlays: MutableMap<Int, Marker> = mutableMapOf() private val collarOverlays: MutableMap<Int, Marker> = mutableMapOf()
// Timer used to schedule refresh // Timer used to schedule refresh
private var refreshTimer = Timer() private val refreshTimer = Timer()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -58,7 +57,6 @@ class CollarListActivity : AppCompatActivity() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
map.onResume() map.onResume()
refreshTimer = Timer()
refreshTimer.schedule(timerTask { triggerRefresh() }, 0L, 5000L) refreshTimer.schedule(timerTask { triggerRefresh() }, 0L, 5000L)
} }
@ -88,22 +86,9 @@ class CollarListActivity : AppCompatActivity() {
map = findViewById(R.id.map) 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() { private fun setupCollarList() {
val layoutManager = LinearLayoutManager(collarList.context) val layoutManager = LinearLayoutManager(collarList.context)
summaryAdapter = CollarSummaryAdapter(summaries, object : CollarClickListener { summaryAdapter = CollarSummaryAdapter(summaries)
override fun onCollarClick(collar: CollarSummary?) {
if (collar == null) return
startCollarDetailActivity(collar)
}
})
collarList.adapter = summaryAdapter collarList.adapter = summaryAdapter
collarList.layoutManager = layoutManager collarList.layoutManager = layoutManager
collarList.addItemDecoration(DividerItemDecoration(collarList.context, layoutManager.orientation)) collarList.addItemDecoration(DividerItemDecoration(collarList.context, layoutManager.orientation))

Ver fichero

@ -12,8 +12,7 @@ import com.danilafe.fencelessgrazing.model.CollarSummary
import com.danilafe.fencelessgrazing.requests.CollarRequest import com.danilafe.fencelessgrazing.requests.CollarRequest
class CollarSummaryAdapter( class CollarSummaryAdapter(
private val items: List<CollarSummary>, private val items : List<CollarSummary>
private val collarClickListener: CollarClickListener
) : ListAdapter<CollarSummary, CollarViewHolder>(DiffCallback()) { ) : ListAdapter<CollarSummary, CollarViewHolder>(DiffCallback()) {
class DiffCallback : DiffUtil.ItemCallback<CollarSummary>() { class DiffCallback : DiffUtil.ItemCallback<CollarSummary>() {
@ -30,7 +29,7 @@ class CollarSummaryAdapter(
} }
override fun onBindViewHolder(holder: CollarViewHolder, position: Int) { override fun onBindViewHolder(holder: CollarViewHolder, position: Int) {
holder.bindData(getItem(position), collarClickListener) holder.bindData(getItem(position))
} }
override fun getItemViewType(position: Int): Int = R.layout.collar_summary_layout override fun getItemViewType(position: Int): Int = R.layout.collar_summary_layout

Ver fichero

@ -9,12 +9,9 @@ class CollarViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val nameView: TextView = itemView.findViewById(R.id.collarSummaryName) private val nameView: TextView = itemView.findViewById(R.id.collarSummaryName)
private val positionView: TextView = itemView.findViewById(R.id.collarSummaryPos) private val positionView: TextView = itemView.findViewById(R.id.collarSummaryPos)
fun bindData(summary: CollarSummary, collarClickListener: CollarClickListener) { fun bindData(summary: CollarSummary) {
nameView.text = summary.name nameView.text = summary.name
// TODO figure out how to get getString here. // TODO figure out how to get getString here.
positionView.text = "Currently at ${summary.pos.longitude}, ${summary.pos.latitude}" positionView.text = "Currently at ${summary.pos.longitude}, ${summary.pos.latitude}"
itemView.setOnClickListener {
collarClickListener.onCollarClick(summary)
}
} }
} }

Ver fichero

@ -1,3 +1,2 @@
package com.danilafe.fencelessgrazing.model package com.danilafe.fencelessgrazing.model
data class Polygon(val dataPoints : List<CollarPos>)

Ver fichero

@ -1,17 +0,0 @@
<?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">
<org.osmdroid.views.MapView
android:id="@+id/detailMap"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="16:9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>