Add stimulus activation report counter to UI

This commit is contained in:
Danila Fedorin 2020-05-12 18:49:39 -07:00
parent 8bf4f513b7
commit f343b97704
6 changed files with 16 additions and 2 deletions

View File

@ -25,6 +25,7 @@ android {
repositories { repositories {
mavenCentral() mavenCentral()
maven { url 'https://jitpack.io' }
} }
dependencies { dependencies {
@ -41,4 +42,5 @@ dependencies {
implementation 'androidx.recyclerview:recyclerview:1.1.0' implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'org.osmdroid:osmdroid-android:6.1.5' implementation 'org.osmdroid:osmdroid-android:6.1.5'
implementation "androidx.preference:preference-ktx:1.1.0" implementation "androidx.preference:preference-ktx:1.1.0"
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
} }

View File

@ -23,6 +23,7 @@ class CollarDetailActivity : AppCompatActivity() {
private lateinit var collarName: TextView private lateinit var collarName: TextView
private lateinit var collarPos: TextView private lateinit var collarPos: TextView
private lateinit var collarStimulus: TextView
private lateinit var token: String private lateinit var token: String
private lateinit var queue: RequestQueue private lateinit var queue: RequestQueue
@ -56,6 +57,7 @@ class CollarDetailActivity : AppCompatActivity() {
collarName = findViewById(R.id.collarName) collarName = findViewById(R.id.collarName)
collarPos = findViewById(R.id.collarPos) collarPos = findViewById(R.id.collarPos)
collarStimulus = findViewById(R.id.collarStimulus)
token = intent.getStringExtra("token")!! token = intent.getStringExtra("token")!!
collarId = intent.getIntExtra("identifier", -1) collarId = intent.getIntExtra("identifier", -1)
@ -104,6 +106,7 @@ class CollarDetailActivity : AppCompatActivity() {
val detailRequest = CollarDetailRequest(getString(R.string.apiUrl), collarId, token, val detailRequest = CollarDetailRequest(getString(R.string.apiUrl), collarId, token,
Response.Listener { Response.Listener {
collarName.text = it.name collarName.text = it.name
collarStimulus.text = getString(R.string.collarSummaryStimulus, it.stimulus)
}, },
Response.ErrorListener { Response.ErrorListener {
Toast.makeText(this, "Failed to retrieve details of collar", Toast.LENGTH_SHORT).show() Toast.makeText(this, "Failed to retrieve details of collar", Toast.LENGTH_SHORT).show()

View File

@ -1,3 +1,3 @@
package com.danilafe.fencelessgrazing.model package com.danilafe.fencelessgrazing.model
data class CollarDetails(val id: Int, val name: String) data class CollarDetails(val id: Int, val name: String, val stimulus: Int)

View File

@ -10,7 +10,6 @@ class GsonListener<T : Any>(private val targetType : Type, private val stringLis
private val gson = Gson() private val gson = Gson()
override fun onResponse(response: String?) { override fun onResponse(response: String?) {
Log.i("Response", response)
if(response == null) { return stringListener.onResponse(null) } if(response == null) { return stringListener.onResponse(null) }
stringListener.onResponse(gson.fromJson<T>(response, targetType)) stringListener.onResponse(gson.fromJson<T>(response, targetType))
} }

View File

@ -33,4 +33,13 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/collarName" /> app:layout_constraintTop_toBottomOf="@+id/collarName" />
<TextView
android:id="@+id/collarStimulus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/collarPos" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -5,4 +5,5 @@
<string name="login">Log In</string> <string name="login">Log In</string>
<string name="apiUrl">http://dev.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>
<string name="collarSummaryStimulus">Required %1d stimuli in the last 24 hours</string>
</resources> </resources>