Update version and fix issue to show only accounts belonging to the user

This commit is contained in:
wiecktobi 2020-06-02 22:04:38 +02:00
parent b0759a64b7
commit c11d57de2e
5 changed files with 96 additions and 15 deletions

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="BintrayJCenter" />
<option name="name" value="BintrayJCenter" />
<option name="url" value="https://jcenter.bintray.com/" />
</remote-repository>
<remote-repository>
<option name="id" value="Google" />
<option name="name" value="Google" />
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
</remote-repository>
</component>
</project>

View File

@ -1,5 +1,7 @@
package de.hft.geotracker.activities
import android.Manifest
import android.Manifest.permission.ACCESS_COARSE_LOCATION
import android.Manifest.permission.ACCESS_FINE_LOCATION
import android.app.PendingIntent
import android.content.Context
@ -34,6 +36,7 @@ class MainActivity : AppCompatActivity() {
lateinit var actionButton: TextView
var running = false
var accName: String? = null
var username: String? = null
lateinit var accounts: ValuesTimetrackAccounts
lateinit var service: GeofenceService
lateinit var locationRequest: LocationRequest
@ -104,9 +107,9 @@ class MainActivity : AppCompatActivity() {
showUsername()
//Get Timetrack Accounts
val accountNames = mutableListOf<String>()
/*val accountNames = mutableListOf<String>()
// accountNames.add("None")
val call = service.getAccounts()
val call = service.getAccounts(username!!)
call.enqueue(object: Callback<EmbeddedAccounts> {
override fun onResponse(
call: Call<EmbeddedAccounts>,
@ -126,7 +129,7 @@ class MainActivity : AppCompatActivity() {
Toast.makeText(this@MainActivity, "You dont have any Timetrack Accounts ", Toast.LENGTH_LONG)
.show()
}
})
})*/
actionButton = findViewById(R.id.button_start_stop)
actionButton.setOnClickListener {
@ -170,9 +173,10 @@ class MainActivity : AppCompatActivity() {
println("Problem at start tracking: " + t.message)
}
})
} else {
println("Accounts list is emty")
}
println("StartStop pressed: $running")
//ToDO call /track Endpoint
}
private fun showUsername() {
@ -182,13 +186,22 @@ class MainActivity : AppCompatActivity() {
if (response.isSuccessful) {
val firstname = response.body()?.firstname
val location = response.body()?.location
username = response.body()?.username
getTimetrackAccounts(username!!)
/* println("Username response: " + response.body()?.username)
if (!username.equals(null)) {
getTimetrackAccounts(username!!)
println("Your name: $username")
} else {
Toast.makeText(this@MainActivity, "Not able to read your username", Toast.LENGTH_LONG)
.show()
}*/
lbl_username.text = "Hello " + firstname
println("Body: " + firstname)
if (location?.latitude == null) {
Toast.makeText(this@MainActivity, "No geofence set for you", Toast.LENGTH_LONG)
.show()
} else {
initializeGeofence(location?.latitude, location?.longitude, location?.radius)
initializeGeofence(location.latitude, location.longitude, location.radius)
}
} else {
println("Response not successful: ${response.code()}")
@ -199,6 +212,35 @@ class MainActivity : AppCompatActivity() {
println("Response 'whoami' failed. " + t.message)
}
})
}
private fun getTimetrackAccounts(user: String) {
val accountNames = mutableListOf<String>()
// accountNames.add("None")
val call = service.getAccounts(username!!)
call.enqueue(object: Callback<EmbeddedAccounts> {
override fun onResponse(
call: Call<EmbeddedAccounts>,
response: Response<EmbeddedAccounts>
) {
if (response.isSuccessful) {
accounts = response.body()!!.accounts
accounts.entries.forEach {
accountNames.add(it.name + "")
}
initializeDropdown(accountNames)
println("Dropdown initialized")
}
}
override fun onFailure(call: Call<EmbeddedAccounts>, t: Throwable) {
accountNames.add("None")
initializeDropdown(accountNames)
Toast.makeText(this@MainActivity, "You dont have any Timetrack Accounts ", Toast.LENGTH_LONG)
.show()
}
})
}
private fun initializeDropdown(accountNames: MutableList<String>) {
val spinner: Spinner = findViewById(R.id.account_spinner)
@ -237,6 +279,13 @@ class MainActivity : AppCompatActivity() {
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER or Geofence.GEOFENCE_TRANSITION_EXIT)
.build()
if (ActivityCompat.checkSelfPermission(
this,
ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED
) {
requestPermissions(this, arrayOf(ACCESS_FINE_LOCATION), 1000)
}
geofencingClient.addGeofences(getGeofencingRequest(), geofencePendingIntent)?.run {
addOnSuccessListener {
println("Geofence added with: latitude: $lat longitude: $long radius: $rad")
@ -266,6 +315,16 @@ class MainActivity : AppCompatActivity() {
startLocationUpdates()
}
private fun startLocationUpdates() {
if (ActivityCompat.checkSelfPermission(
this,
ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_COARSE_LOCATION
) != PackageManager.PERMISSION_GRANTED
) {
requestPermissions(this, arrayOf(ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION), 1000)
}
fusedLocationClient.requestLocationUpdates(
locationRequest,
locationCallback,

View File

@ -1,10 +1,7 @@
package de.hft.geotracker.retrofit
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Query
import retrofit2.http.*
interface GeofenceService {
@POST("/login")
@ -13,8 +10,8 @@ interface GeofenceService {
@GET("whoami")
fun getUser(): Call<ValuesUser>
@GET("accounts")
fun getAccounts(): Call<EmbeddedAccounts>
@GET("accounts/search/findByUsername")
fun getAccounts(@Query("username") username : String): Call<EmbeddedAccounts>
@GET("track")
fun triggerTracking(@Query("account") account: String): Call<ValuesTracking>

View File

@ -8,7 +8,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.android.tools.build:gradle:4.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong

View File

@ -1,6 +1,6 @@
#Sun Apr 05 19:25:41 CEST 2020
#Tue Jun 02 21:02:45 CEST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip