From 20ab2931f2234360c174b507ae3b2c774a80c73d Mon Sep 17 00:00:00 2001 From: wiecktobi Date: Tue, 2 Jun 2020 22:47:23 +0200 Subject: [PATCH] Change button text --- .../de/hft/geotracker/activities/Login.kt | 2 +- .../hft/geotracker/activities/MainActivity.kt | 55 ++++--------------- .../de/hft/geotracker/activities/Register.kt | 2 +- .../app/src/main/res/layout/activity_home.xml | 9 +-- .../src/main/res/layout/activity_login.xml | 6 +- .../src/main/res/layout/activity_register.xml | 4 +- android/app/src/main/res/values/strings.xml | 2 + 7 files changed, 24 insertions(+), 56 deletions(-) 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 e1e02a0..895ce8f 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 @@ -54,7 +54,7 @@ class Login : AppCompatActivity() { .build() service = retrofit.create(GeofenceService::class.java) - login = findViewById(R.id.button_create_account) + login = findViewById(R.id.button_login) login.setOnClickListener { intent = Intent(this, MainActivity::class.java) login() 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 49c8a58..67dc6d6 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 @@ -19,7 +19,6 @@ import de.hft.geotracker.GeofenceBroadcastReceiver import de.hft.geotracker.R import de.hft.geotracker.retrofit.* import kotlinx.android.synthetic.main.activity_home.* -import kotlinx.android.synthetic.main.dropdown_menu.* import okhttp3.OkHttpClient import retrofit2.Call import retrofit2.Callback @@ -36,7 +35,6 @@ 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 @@ -68,19 +66,20 @@ class MainActivity : AppCompatActivity() { ?.apply() getSharedPreferences("LOCATION", Context.MODE_PRIVATE) .registerOnSharedPreferenceChangeListener { sharedPreferences, key -> - val btnState = sharedPreferences.getBoolean("ENABLED", false) + val isInside = sharedPreferences.getBoolean("ENABLED", false) - println("Buttonstate: $btnState") - if (btnState) { + println("Is inside? -> $isInside") + if (isInside) { + button_start_stop?.text = getString(R.string.start) button_start_stop?.setBackgroundColor(resources.getColor(R.color.logo_blue)) - } else { + } else { button_start_stop?.setBackgroundColor(resources.getColor(R.color.colorPrimaryDark)) if (running) { - button_start_stop.toggle() callStartStop() } + button_start_stop?.text = getString(R.string.outside_place) } - button_start_stop.isEnabled = btnState + button_start_stop.isEnabled = isInside } //JWToken lesen @@ -106,31 +105,6 @@ class MainActivity : AppCompatActivity() { service = retrofit.create(GeofenceService::class.java) showUsername() - //Get Timetrack Accounts - /*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) - } - } - 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() - } - })*/ - actionButton = findViewById(R.id.button_start_stop) actionButton.setOnClickListener { callStartStop() @@ -158,8 +132,10 @@ class MainActivity : AppCompatActivity() { running = !running if (running) { account_spinner.visibility = View.GONE + button_start_stop?.text = getString(R.string.stop) } else { account_spinner.visibility = View.VISIBLE + button_start_stop?.text = getString(R.string.start) } if (!accName.isNullOrEmpty()) { val call = service.triggerTracking(accName!!) @@ -186,16 +162,8 @@ class MainActivity : AppCompatActivity() { if (response.isSuccessful) { val firstname = response.body()?.firstname val location = response.body()?.location - username = response.body()?.username + val 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 if (location?.latitude == null) { Toast.makeText(this@MainActivity, "No geofence set for you", Toast.LENGTH_LONG) @@ -219,7 +187,7 @@ class MainActivity : AppCompatActivity() { private fun getTimetrackAccounts(user: String) { val accountNames = mutableListOf() // accountNames.add("None") - val call = service.getAccounts(username!!) + val call = service.getAccounts(user) call.enqueue(object: Callback { override fun onResponse( call: Call, @@ -237,6 +205,7 @@ class MainActivity : AppCompatActivity() { override fun onFailure(call: Call, t: Throwable) { accountNames.add("None") initializeDropdown(accountNames) + button_start_stop?.text = "No Timetrack Accounts" Toast.makeText(this@MainActivity, "You dont have any Timetrack Accounts ", Toast.LENGTH_LONG) .show() } diff --git a/android/app/src/main/java/de/hft/geotracker/activities/Register.kt b/android/app/src/main/java/de/hft/geotracker/activities/Register.kt index faa0ffd..7645b88 100644 --- a/android/app/src/main/java/de/hft/geotracker/activities/Register.kt +++ b/android/app/src/main/java/de/hft/geotracker/activities/Register.kt @@ -11,7 +11,7 @@ class Register : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_register) - reg = findViewById(R.id.button_create_account) + reg = findViewById(R.id.button_login) reg.setOnClickListener { createAccount() } diff --git a/android/app/src/main/res/layout/activity_home.xml b/android/app/src/main/res/layout/activity_home.xml index f267e14..4f42092 100644 --- a/android/app/src/main/res/layout/activity_home.xml +++ b/android/app/src/main/res/layout/activity_home.xml @@ -68,23 +68,20 @@ app:layout_constraintTop_toBottomOf="@+id/divider2" app:layout_constraintVertical_bias="0.0" /> - diff --git a/android/app/src/main/res/layout/activity_login.xml b/android/app/src/main/res/layout/activity_login.xml index d496f1a..ca2e95f 100644 --- a/android/app/src/main/res/layout/activity_login.xml +++ b/android/app/src/main/res/layout/activity_login.xml @@ -63,7 +63,7 @@ android:textColorHint="@color/logo_white" app:boxBackgroundColor="@color/common_google_signin_btn_text_dark_disabled" app:boxBackgroundMode="outline" - app:layout_constraintBottom_toTopOf="@+id/button_create_account" + app:layout_constraintBottom_toTopOf="@+id/button_login" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" @@ -81,7 +81,7 @@