diff --git a/android/.idea/misc.xml b/android/.idea/misc.xml index 7bfef59..b6ea2b1 100644 --- a/android/.idea/misc.xml +++ b/android/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/android/app/build.gradle b/android/app/build.gradle index cb3d488..6dbdb6b 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -40,7 +40,7 @@ dependencies { implementation 'androidx.core:core-ktx:1.2.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.legacy:legacy-support-v4:1.0.0' - implementation 'com.google.android.material:material:1.2.0-alpha06' + implementation 'com.google.android.material:material:1.1.0' implementation "com.google.android.gms:play-services-location:17.0.0" implementation 'androidx.preference:preference:1.1.1' testImplementation 'junit:junit:4.13' diff --git a/android/app/src/main/java/de/hft/geotracker/activities/Login.kt b/android/app/src/main/java/de/hft/geotracker/activities/Login.kt index 005cd3e..e1e02a0 100644 --- a/android/app/src/main/java/de/hft/geotracker/activities/Login.kt +++ b/android/app/src/main/java/de/hft/geotracker/activities/Login.kt @@ -19,6 +19,7 @@ import retrofit2.Callback import retrofit2.Response import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory +import kotlinx.android.synthetic.main.activity_login.* /** * A simple [Fragment] subclass. @@ -70,8 +71,8 @@ class Login : AppCompatActivity() { } private fun login() { - val name = findViewById(R.id.setting_input_username).text.toString() - val pswd = findViewById(R.id.input_password).text.toString() + val name = input_username.text.toString() + val pswd = input_password.text.toString() val call = service.login(ValuesUserLogin(name, pswd)) call.enqueue(object : Callback { 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 1315dd7..836d029 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,17 +1,19 @@ package de.hft.geotracker.activities +import android.Manifest.permission.ACCESS_FINE_LOCATION import android.app.PendingIntent import android.content.Context import android.content.Intent +import android.content.pm.PackageManager import android.os.Bundle +import android.os.Looper import android.widget.ArrayAdapter import android.widget.Spinner import android.widget.TextView import androidx.appcompat.app.AppCompatActivity -import com.google.android.gms.location.Geofence -import com.google.android.gms.location.GeofencingClient -import com.google.android.gms.location.GeofencingRequest -import com.google.android.gms.location.LocationServices +import androidx.core.app.ActivityCompat +import androidx.core.app.ActivityCompat.requestPermissions +import com.google.android.gms.location.* import de.hft.geotracker.GeofenceBroadcastReceiver import de.hft.geotracker.R import de.hft.geotracker.retrofit.AuthenticationInterceptor @@ -34,12 +36,29 @@ class MainActivity : AppCompatActivity() { lateinit var actionButton: TextView var running = false lateinit var service: GeofenceService + lateinit var locationRequest: LocationRequest + lateinit var fusedLocationClient: FusedLocationProviderClient + lateinit var locationCallback: LocationCallback override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_home) + //Get location data and permissions + createLocationRequest() + fusedLocationClient = LocationServices.getFusedLocationProviderClient(this) + if (ActivityCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION) != + PackageManager.PERMISSION_GRANTED + ) { + requestPermissions(this, arrayOf(ACCESS_FINE_LOCATION), 1000) + } + locationCallback = object : LocationCallback() { + override fun onLocationResult(locationResult: LocationResult?) { + locationResult ?: return + } + } + + //React on geofence state this.getSharedPreferences("LOCATION", Context.MODE_PRIVATE) ?.edit() ?.putBoolean("ENABLED", false) @@ -124,6 +143,7 @@ class MainActivity : AppCompatActivity() { true } R.id.logout -> { + deleteFile("JWToken") startActivity(Intent(this, Login::class.java)) println("Logout pressed") true @@ -172,6 +192,26 @@ class MainActivity : AppCompatActivity() { PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) } + override fun onResume() { + super.onResume() + startLocationUpdates() + } + private fun startLocationUpdates() { + fusedLocationClient.requestLocationUpdates( + locationRequest, + locationCallback, + Looper.getMainLooper() + ) + } + + private fun createLocationRequest() { + locationRequest = LocationRequest.create().apply { + interval = 10000 + fastestInterval = 5000 + priority = LocationRequest.PRIORITY_HIGH_ACCURACY + } + } + override fun onBackPressed() { } diff --git a/android/app/src/main/res/layout/activity_home.xml b/android/app/src/main/res/layout/activity_home.xml index c9bb8af..61a59bd 100644 --- a/android/app/src/main/res/layout/activity_home.xml +++ b/android/app/src/main/res/layout/activity_home.xml @@ -8,8 +8,6 @@ android:background="@color/background_grey" tools:context=".activities.MainActivity"> - - diff --git a/android/app/src/main/res/layout/activity_login.xml b/android/app/src/main/res/layout/activity_login.xml index 52cfba4..d496f1a 100644 --- a/android/app/src/main/res/layout/activity_login.xml +++ b/android/app/src/main/res/layout/activity_login.xml @@ -22,70 +22,92 @@ app:title="@string/app_name" /> - + app:layout_constraintVertical_chainStyle="packed"> - + + + + app:layout_constraintTop_toBottomOf="@+id/input_username_layout" + app:layout_constraintVertical_bias="0.13"> + + +