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 2fe38d0..1667fd0 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 @@ -7,20 +7,15 @@ 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 android.widget.Toast +import android.view.View +import android.widget.* import androidx.appcompat.app.AppCompatActivity 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 -import de.hft.geotracker.retrofit.GeofenceService -import de.hft.geotracker.retrofit.ValuesTimetrackAccounts -import de.hft.geotracker.retrofit.ValuesUser +import de.hft.geotracker.retrofit.* import kotlinx.android.synthetic.main.activity_home.* import okhttp3.OkHttpClient import retrofit2.Call @@ -37,6 +32,7 @@ class MainActivity : AppCompatActivity() { lateinit var geofence: Geofence lateinit var actionButton: TextView var running = false + lateinit var accounts: ValuesTimetrackAccounts lateinit var service: GeofenceService lateinit var locationRequest: LocationRequest lateinit var fusedLocationClient: FusedLocationProviderClient @@ -105,39 +101,30 @@ class MainActivity : AppCompatActivity() { service = retrofit.create(GeofenceService::class.java) showUsername() - //Setup geofence - - //Get Timetrack Accounts - /*val call = service.getAccounts() - call.enqueue(object: Callback> { + val accountNames = mutableListOf() +// accountNames.add("None") + val call = service.getAccounts() + call.enqueue(object: Callback { override fun onResponse( - call: Call>, - response: Response> + call: Call, + response: Response ) { if (response.isSuccessful) { - val responseBody = response.body()!! - responseBody.forEach { - println(it.name) + accounts = response.body()!!.accounts + accounts.entries.forEach { + accountNames.add(it.name + "") } + initializeDropdown(accountNames) } - } - override fun onFailure(call: Call>, t: Throwable) { - println("Get Timetrack Accounts ended with errors. " + t.message) + 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() } - })*/ - val spinner: Spinner = findViewById(R.id.account_spinner) - // Create an ArrayAdapter using the string array and a default spinner layout - ArrayAdapter.createFromResource( - this, - R.array.accounts, android.R.layout.simple_spinner_item - ).also { adapter -> - // Specify the layout to use when the list of choices appears - adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) - // Apply the adapter to the spinner - spinner.adapter = adapter - } + }) actionButton = findViewById(R.id.button_start_stop) actionButton.setOnClickListener { @@ -193,6 +180,35 @@ class MainActivity : AppCompatActivity() { } }) } + private fun initializeDropdown(accountNames: MutableList) { + val spinner: Spinner = findViewById(R.id.account_spinner) + // Create an ArrayAdapter using the string array and a default spinner layout + val arrayAdapter = ArrayAdapter(this, R.layout.spinner_layout, accountNames) + arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) + spinner.adapter = arrayAdapter + spinner.onItemSelectedListener = object: AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, + view: View?, + position: Int, + id: Long + ) { + if (!accountNames.get(0).equals("rich")) { + display_description.setText(accounts.entries.get(position).description) + display_revenue.setText(accounts.entries.get(position).revenue.toString()) + } else { + display_description.visibility = View.GONE + display_description_layout.visibility = View.GONE + display_revenue.visibility = View.GONE + display_revenue_layout.visibility = View.GONE + } + println("Selected: " + accountNames.get(position)) + } + override fun onNothingSelected(parent: AdapterView<*>?) { + println("Nothing selected") + } + } + } private fun initializeGeofence(lat: Double, long: Double, rad: Float) { geofencingClient = LocationServices.getGeofencingClient(this) geofence = Geofence.Builder().setRequestId("Test") diff --git a/android/app/src/main/java/de/hft/geotracker/retrofit/EmbeddedAccounts.kt b/android/app/src/main/java/de/hft/geotracker/retrofit/EmbeddedAccounts.kt new file mode 100644 index 0000000..2ec99bc --- /dev/null +++ b/android/app/src/main/java/de/hft/geotracker/retrofit/EmbeddedAccounts.kt @@ -0,0 +1,8 @@ +package de.hft.geotracker.retrofit + +import com.google.gson.annotations.SerializedName + +class EmbeddedAccounts(accounts: ValuesTimetrackAccounts) { + @SerializedName("_embedded") + var accounts = accounts +} \ No newline at end of file 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 8759a25..65cb132 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 @@ -13,5 +13,5 @@ interface GeofenceService { fun getUser(): Call @GET("accounts") - fun getAccounts(): Call> + fun getAccounts(): Call } \ No newline at end of file diff --git a/android/app/src/main/java/de/hft/geotracker/retrofit/ValuesTimetrackAccounts.kt b/android/app/src/main/java/de/hft/geotracker/retrofit/ValuesTimetrackAccounts.kt index 3f94cd6..e3af65a 100644 --- a/android/app/src/main/java/de/hft/geotracker/retrofit/ValuesTimetrackAccounts.kt +++ b/android/app/src/main/java/de/hft/geotracker/retrofit/ValuesTimetrackAccounts.kt @@ -2,18 +2,7 @@ package de.hft.geotracker.retrofit import com.google.gson.annotations.SerializedName -class ValuesTimetrackAccounts( - revenue: Double, - name: String, - description: String -) { - - @SerializedName("revenue") - var revenue = revenue - - @SerializedName("name") - var name = name - - @SerializedName("description") - var description = description +class ValuesTimetrackAccounts(entries: Array) { + @SerializedName("accounts") + var entries = entries } \ No newline at end of file diff --git a/android/app/src/main/java/de/hft/geotracker/retrofit/ValuesTimetrackAccountsEntries.kt b/android/app/src/main/java/de/hft/geotracker/retrofit/ValuesTimetrackAccountsEntries.kt new file mode 100644 index 0000000..d16f368 --- /dev/null +++ b/android/app/src/main/java/de/hft/geotracker/retrofit/ValuesTimetrackAccountsEntries.kt @@ -0,0 +1,19 @@ +package de.hft.geotracker.retrofit + +import com.google.gson.annotations.SerializedName + +class ValuesTimetrackAccountsEntries( + revenue: Double, + name: String, + description: String +) { + + @SerializedName("revenue") + var revenue = revenue + + @SerializedName("name") + var name = name + + @SerializedName("description") + var description = description +} \ No newline at end of file diff --git a/android/app/src/main/res/layout/activity_home.xml b/android/app/src/main/res/layout/activity_home.xml index 61a59bd..5474830 100644 --- a/android/app/src/main/res/layout/activity_home.xml +++ b/android/app/src/main/res/layout/activity_home.xml @@ -55,16 +55,18 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="16dp" + android:layout_marginTop="@dimen/margin16" + android:layout_marginEnd="16dp" android:fontFamily="@font/montserrat" android:text="@string/timetrack_account" android:textAppearance="@style/text_style" android:textColor="@color/logo_white" app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintEnd_toEndOf="@id/account_spinner" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/appBarLayout" - app:layout_constraintVertical_bias="0.19" /> + app:layout_constraintTop_toBottomOf="@+id/divider2" + app:layout_constraintVertical_bias="0.0" /> + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toEndOf="@+id/selected_acc" /> + + + + + + + + + + + + app:layout_constraintStart_toStartOf="parent" /> + app:layout_constraintTop_toBottomOf="@+id/display_revenue_layout" /> + app:layout_constraintStart_toStartOf="parent" /> \ No newline at end of file diff --git a/android/app/src/main/res/layout/dropdown_menu.xml b/android/app/src/main/res/layout/dropdown_menu.xml index 8413bf4..4dad12b 100644 --- a/android/app/src/main/res/layout/dropdown_menu.xml +++ b/android/app/src/main/res/layout/dropdown_menu.xml @@ -1,12 +1,14 @@ - + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto">