diff --git a/android/.idea/jarRepositories.xml b/android/.idea/jarRepositories.xml
new file mode 100644
index 0000000..a5f05cd
--- /dev/null
+++ b/android/.idea/jarRepositories.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/app/src/main/java/de/hft/geotracker/activities/MainActivity.kt b/android/app/src/main/java/de/hft/geotracker/activities/MainActivity.kt
index ccaf3bf..49c8a58 100644
--- a/android/app/src/main/java/de/hft/geotracker/activities/MainActivity.kt
+++ b/android/app/src/main/java/de/hft/geotracker/activities/MainActivity.kt
@@ -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()
+ /*val accountNames = mutableListOf()
// accountNames.add("None")
- val call = service.getAccounts()
+ val call = service.getAccounts(username!!)
call.enqueue(object: Callback {
override fun onResponse(
call: Call,
@@ -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()
+// accountNames.add("None")
+ val call = service.getAccounts(username!!)
+ call.enqueue(object: Callback {
+ override fun onResponse(
+ call: Call,
+ response: Response
+ ) {
+ if (response.isSuccessful) {
+ accounts = response.body()!!.accounts
+ accounts.entries.forEach {
+ accountNames.add(it.name + "")
+ }
+ initializeDropdown(accountNames)
+ println("Dropdown initialized")
+ }
+ }
+ override fun onFailure(call: Call, 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) {
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,
diff --git a/android/app/src/main/java/de/hft/geotracker/retrofit/GeofenceService.kt b/android/app/src/main/java/de/hft/geotracker/retrofit/GeofenceService.kt
index d437f99..5a6bfb3 100644
--- a/android/app/src/main/java/de/hft/geotracker/retrofit/GeofenceService.kt
+++ b/android/app/src/main/java/de/hft/geotracker/retrofit/GeofenceService.kt
@@ -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
- @GET("accounts")
- fun getAccounts(): Call
+ @GET("accounts/search/findByUsername")
+ fun getAccounts(@Query("username") username : String): Call
@GET("track")
fun triggerTracking(@Query("account") account: String): Call
diff --git a/android/build.gradle b/android/build.gradle
index 84b783e..2eac75d 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -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
diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties
index 2a990dc..e8f1aee 100644
--- a/android/gradle/wrapper/gradle-wrapper.properties
+++ b/android/gradle/wrapper/gradle-wrapper.properties
@@ -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