41 lines
1.4 KiB
Kotlin
41 lines
1.4 KiB
Kotlin
package com.danilafe.fencelessgrazing
|
|
|
|
import android.content.Intent
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
import android.os.Bundle
|
|
import android.view.View
|
|
import android.widget.TextView
|
|
import android.widget.Toast
|
|
import com.android.volley.Response
|
|
import com.android.volley.toolbox.Volley
|
|
import com.danilafe.fencelessgrazing.requests.LoginRequest
|
|
|
|
class MainActivity : AppCompatActivity() {
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
setContentView(R.layout.activity_main)
|
|
startActivity(Intent(this, StatisticsActivity::class.java))
|
|
}
|
|
|
|
fun attemptLogin(view: View) {
|
|
val usernameField: TextView = findViewById(R.id.username)
|
|
val passwordField: TextView = findViewById(R.id.password)
|
|
val requestQueue = Volley.newRequestQueue(this)
|
|
|
|
val loginRequest =
|
|
LoginRequest(getString(R.string.apiUrl),
|
|
usernameField.text.toString(), passwordField.text.toString(),
|
|
Response.Listener {
|
|
val newIntent = Intent(this, CollarListActivity::class.java).apply {
|
|
putExtra("token", it?.token)
|
|
}
|
|
startActivity(newIntent)
|
|
},
|
|
Response.ErrorListener {
|
|
Toast.makeText(this, "Failed to log in! $it", Toast.LENGTH_LONG).show()
|
|
})
|
|
requestQueue.add(loginRequest)
|
|
}
|
|
}
|