Read, save and display account name, description and revenue
This commit is contained in:
parent
dad0594854
commit
c52daee815
@ -7,20 +7,15 @@ import android.content.Intent
|
|||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.widget.ArrayAdapter
|
import android.view.View
|
||||||
import android.widget.Spinner
|
import android.widget.*
|
||||||
import android.widget.TextView
|
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.app.ActivityCompat
|
import androidx.core.app.ActivityCompat
|
||||||
import androidx.core.app.ActivityCompat.requestPermissions
|
import androidx.core.app.ActivityCompat.requestPermissions
|
||||||
import com.google.android.gms.location.*
|
import com.google.android.gms.location.*
|
||||||
import de.hft.geotracker.GeofenceBroadcastReceiver
|
import de.hft.geotracker.GeofenceBroadcastReceiver
|
||||||
import de.hft.geotracker.R
|
import de.hft.geotracker.R
|
||||||
import de.hft.geotracker.retrofit.AuthenticationInterceptor
|
import de.hft.geotracker.retrofit.*
|
||||||
import de.hft.geotracker.retrofit.GeofenceService
|
|
||||||
import de.hft.geotracker.retrofit.ValuesTimetrackAccounts
|
|
||||||
import de.hft.geotracker.retrofit.ValuesUser
|
|
||||||
import kotlinx.android.synthetic.main.activity_home.*
|
import kotlinx.android.synthetic.main.activity_home.*
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import retrofit2.Call
|
import retrofit2.Call
|
||||||
@ -37,6 +32,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
lateinit var geofence: Geofence
|
lateinit var geofence: Geofence
|
||||||
lateinit var actionButton: TextView
|
lateinit var actionButton: TextView
|
||||||
var running = false
|
var running = false
|
||||||
|
lateinit var accounts: ValuesTimetrackAccounts
|
||||||
lateinit var service: GeofenceService
|
lateinit var service: GeofenceService
|
||||||
lateinit var locationRequest: LocationRequest
|
lateinit var locationRequest: LocationRequest
|
||||||
lateinit var fusedLocationClient: FusedLocationProviderClient
|
lateinit var fusedLocationClient: FusedLocationProviderClient
|
||||||
@ -105,39 +101,30 @@ class MainActivity : AppCompatActivity() {
|
|||||||
service = retrofit.create(GeofenceService::class.java)
|
service = retrofit.create(GeofenceService::class.java)
|
||||||
showUsername()
|
showUsername()
|
||||||
|
|
||||||
//Setup geofence
|
|
||||||
|
|
||||||
|
|
||||||
//Get Timetrack Accounts
|
//Get Timetrack Accounts
|
||||||
/*val call = service.getAccounts()
|
val accountNames = mutableListOf<String>()
|
||||||
call.enqueue(object: Callback<List<ValuesTimetrackAccounts>> {
|
// accountNames.add("None")
|
||||||
|
val call = service.getAccounts()
|
||||||
|
call.enqueue(object: Callback<EmbeddedAccounts> {
|
||||||
override fun onResponse(
|
override fun onResponse(
|
||||||
call: Call<List<ValuesTimetrackAccounts>>,
|
call: Call<EmbeddedAccounts>,
|
||||||
response: Response<List<ValuesTimetrackAccounts>>
|
response: Response<EmbeddedAccounts>
|
||||||
) {
|
) {
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
val responseBody = response.body()!!
|
accounts = response.body()!!.accounts
|
||||||
responseBody.forEach {
|
accounts.entries.forEach {
|
||||||
println(it.name)
|
accountNames.add(it.name + "")
|
||||||
}
|
}
|
||||||
|
initializeDropdown(accountNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
override fun onFailure(call: Call<List<ValuesTimetrackAccounts>>, t: Throwable) {
|
override fun onFailure(call: Call<EmbeddedAccounts>, t: Throwable) {
|
||||||
println("Get Timetrack Accounts ended with errors. " + t.message)
|
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 = findViewById(R.id.button_start_stop)
|
||||||
actionButton.setOnClickListener {
|
actionButton.setOnClickListener {
|
||||||
@ -193,6 +180,35 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
private fun initializeDropdown(accountNames: MutableList<String>) {
|
||||||
|
val spinner: Spinner = findViewById(R.id.account_spinner)
|
||||||
|
// Create an ArrayAdapter using the string array and a default spinner layout
|
||||||
|
val arrayAdapter = ArrayAdapter<String>(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) {
|
private fun initializeGeofence(lat: Double, long: Double, rad: Float) {
|
||||||
geofencingClient = LocationServices.getGeofencingClient(this)
|
geofencingClient = LocationServices.getGeofencingClient(this)
|
||||||
geofence = Geofence.Builder().setRequestId("Test")
|
geofence = Geofence.Builder().setRequestId("Test")
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package de.hft.geotracker.retrofit
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
|
class EmbeddedAccounts(accounts: ValuesTimetrackAccounts) {
|
||||||
|
@SerializedName("_embedded")
|
||||||
|
var accounts = accounts
|
||||||
|
}
|
@ -13,5 +13,5 @@ interface GeofenceService {
|
|||||||
fun getUser(): Call<ValuesUser>
|
fun getUser(): Call<ValuesUser>
|
||||||
|
|
||||||
@GET("accounts")
|
@GET("accounts")
|
||||||
fun getAccounts(): Call<List<ValuesTimetrackAccounts>>
|
fun getAccounts(): Call<EmbeddedAccounts>
|
||||||
}
|
}
|
@ -2,18 +2,7 @@ package de.hft.geotracker.retrofit
|
|||||||
|
|
||||||
import com.google.gson.annotations.SerializedName
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
class ValuesTimetrackAccounts(
|
class ValuesTimetrackAccounts(entries: Array<ValuesTimetrackAccountsEntries>) {
|
||||||
revenue: Double,
|
@SerializedName("accounts")
|
||||||
name: String,
|
var entries = entries
|
||||||
description: String
|
|
||||||
) {
|
|
||||||
|
|
||||||
@SerializedName("revenue")
|
|
||||||
var revenue = revenue
|
|
||||||
|
|
||||||
@SerializedName("name")
|
|
||||||
var name = name
|
|
||||||
|
|
||||||
@SerializedName("description")
|
|
||||||
var description = description
|
|
||||||
}
|
}
|
@ -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
|
||||||
|
}
|
@ -55,16 +55,18 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginTop="@dimen/margin16"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
android:fontFamily="@font/montserrat"
|
android:fontFamily="@font/montserrat"
|
||||||
android:text="@string/timetrack_account"
|
android:text="@string/timetrack_account"
|
||||||
android:textAppearance="@style/text_style"
|
android:textAppearance="@style/text_style"
|
||||||
android:textColor="@color/logo_white"
|
android:textColor="@color/logo_white"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
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_constraintHorizontal_bias="0.0"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/appBarLayout"
|
app:layout_constraintTop_toBottomOf="@+id/divider2"
|
||||||
app:layout_constraintVertical_bias="0.19" />
|
app:layout_constraintVertical_bias="0.0" />
|
||||||
|
|
||||||
<ToggleButton
|
<ToggleButton
|
||||||
android:id="@+id/button_start_stop"
|
android:id="@+id/button_start_stop"
|
||||||
@ -91,49 +93,121 @@
|
|||||||
android:id="@+id/account_spinner"
|
android:id="@+id/account_spinner"
|
||||||
android:layout_width="180dp"
|
android:layout_width="180dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginEnd="@dimen/margin16"
|
android:layout_marginEnd="16dp"
|
||||||
android:background="@color/logo_white"
|
android:background="@color/colorPrimary"
|
||||||
|
android:foreground="@android:drawable/arrow_down_float"
|
||||||
|
android:foregroundGravity="right|center_horizontal"
|
||||||
android:textAlignment="textEnd"
|
android:textAlignment="textEnd"
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/selected_acc"
|
app:layout_constraintBottom_toBottomOf="@+id/selected_acc"
|
||||||
app:layout_constraintEnd_toEndOf="parent" />
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/selected_acc" />
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:id="@+id/display_description_layout"
|
||||||
|
style="@style/LoginTextInputLayoutStyle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="@dimen/margin16"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginEnd="@dimen/margin16"
|
||||||
|
android:colorControlNormal="@color/logo_blue"
|
||||||
|
android:hint="Description"
|
||||||
|
android:textColorHint="@color/logo_white"
|
||||||
|
app:boxBackgroundColor="@color/common_google_signin_btn_text_dark_disabled"
|
||||||
|
app:boxBackgroundMode="outline"
|
||||||
|
app:boxCornerRadiusBottomEnd="0dp"
|
||||||
|
app:boxCornerRadiusBottomStart="0dp"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/display_revenue_layout"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/selected_acc"
|
||||||
|
app:layout_constraintVertical_bias="0.0"
|
||||||
|
app:layout_constraintVertical_chainStyle="packed">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/display_description"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:enabled="false"
|
||||||
|
android:inputType="textPersonName"
|
||||||
|
android:lineSpacingExtra="8sp"
|
||||||
|
android:textAppearance="@style/text_style"
|
||||||
|
android:textColor="@color/logo_white"
|
||||||
|
android:textColorHint="@color/logo_white"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:id="@+id/display_revenue_layout"
|
||||||
|
style="@style/LoginTextInputLayoutStyle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="@dimen/margin16"
|
||||||
|
android:layout_marginEnd="@dimen/margin16"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
|
android:colorControlNormal="@color/logo_blue"
|
||||||
|
android:hint="Revenue"
|
||||||
|
android:textColorHint="@color/logo_white"
|
||||||
|
app:boxBackgroundColor="@color/common_google_signin_btn_text_dark_disabled"
|
||||||
|
app:boxBackgroundMode="outline"
|
||||||
|
app:boxCornerRadiusTopEnd="0dp"
|
||||||
|
app:boxCornerRadiusTopStart="0dp"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/latitude"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/display_description_layout"
|
||||||
|
app:layout_constraintVertical_bias="0.0"
|
||||||
|
app:layout_constraintVertical_chainStyle="packed">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/display_revenue"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:enabled="false"
|
||||||
|
android:inputType="textPersonName"
|
||||||
|
android:lineSpacingExtra="8sp"
|
||||||
|
android:textAppearance="@style/text_style"
|
||||||
|
android:textColor="@color/logo_white"
|
||||||
|
android:textColorHint="@color/logo_white"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/altitude"
|
android:id="@+id/altitude"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
android:text="dummy"
|
android:text="dummy"
|
||||||
android:textAppearance="@style/text_style"
|
android:textAppearance="@style/text_style"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/button_start_stop"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
app:layout_constraintTop_toBottomOf="@+id/longitude" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/latitude"
|
android:id="@+id/latitude"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="16dp"
|
||||||
android:layout_marginTop="32dp"
|
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
android:text="dummy"
|
android:text="dummy"
|
||||||
android:textAppearance="@style/text_style"
|
android:textAppearance="@style/text_style"
|
||||||
android:textColor="@color/logo_white"
|
android:textColor="@color/logo_white"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/longitude"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/selected_acc" />
|
app:layout_constraintTop_toBottomOf="@+id/display_revenue_layout" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/longitude"
|
android:id="@+id/longitude"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="16dp"
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
android:text="dummy"
|
android:text="dummy"
|
||||||
android:textAppearance="@style/text_style"
|
android:textAppearance="@style/text_style"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/altitude"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
app:layout_constraintTop_toBottomOf="@+id/latitude" />
|
|
||||||
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -1,12 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<com.google.android.material.textfield.TextInputLayout style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="42dp"
|
android:layout_height="42dp"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="16dp"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
android:layout_marginBottom="100dp"
|
android:layout_marginBottom="100dp"
|
||||||
android:hint="@string/no_account"
|
android:hint="@string/no_account"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
<AutoCompleteTextView
|
<AutoCompleteTextView
|
||||||
android:id="@+id/filled_exposed_dropdown"
|
android:id="@+id/filled_exposed_dropdown"
|
||||||
|
Loading…
Reference in New Issue
Block a user