Change button text
This commit is contained in:
parent
c11d57de2e
commit
20ab2931f2
@ -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()
|
||||
|
@ -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 {
|
||||
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<String>()
|
||||
// accountNames.add("None")
|
||||
val call = service.getAccounts(username!!)
|
||||
call.enqueue(object: Callback<EmbeddedAccounts> {
|
||||
override fun onResponse(
|
||||
call: Call<EmbeddedAccounts>,
|
||||
response: Response<EmbeddedAccounts>
|
||||
) {
|
||||
if (response.isSuccessful) {
|
||||
accounts = response.body()!!.accounts
|
||||
accounts.entries.forEach {
|
||||
accountNames.add(it.name + "")
|
||||
}
|
||||
initializeDropdown(accountNames)
|
||||
}
|
||||
}
|
||||
override fun onFailure(call: Call<EmbeddedAccounts>, 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<String>()
|
||||
// accountNames.add("None")
|
||||
val call = service.getAccounts(username!!)
|
||||
val call = service.getAccounts(user)
|
||||
call.enqueue(object: Callback<EmbeddedAccounts> {
|
||||
override fun onResponse(
|
||||
call: Call<EmbeddedAccounts>,
|
||||
@ -237,6 +205,7 @@ class MainActivity : AppCompatActivity() {
|
||||
override fun onFailure(call: Call<EmbeddedAccounts>, 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()
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -68,23 +68,20 @@
|
||||
app:layout_constraintTop_toBottomOf="@+id/divider2"
|
||||
app:layout_constraintVertical_bias="0.0" />
|
||||
|
||||
<ToggleButton
|
||||
<Button
|
||||
android:id="@+id/button_start_stop"
|
||||
style="@style/Widget.MaterialComponents.Button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="55dp"
|
||||
android:layout_marginStart="@dimen/margin16"
|
||||
android:layout_marginEnd="@dimen/margin16"
|
||||
android:layout_marginBottom="@dimen/margin16"
|
||||
android:background="@color/colorPrimary"
|
||||
android:checked="true"
|
||||
android:enabled="false"
|
||||
android:text="@string/outside_place"
|
||||
android:textAppearance="@style/text_style"
|
||||
android:textColor="@color/logo_white"
|
||||
android:textOff="@string/stop"
|
||||
android:textOn="@string/btn_start_text"
|
||||
android:textStyle="bold"
|
||||
app:cornerRadius="8dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
@ -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 @@
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_create_account"
|
||||
android:id="@+id/button_login"
|
||||
style="@style/Widget.MaterialComponents.Button"
|
||||
android:layout_width="240dp"
|
||||
android:layout_height="55dp"
|
||||
@ -112,7 +112,7 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.497"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/button_create_account"
|
||||
app:layout_constraintTop_toBottomOf="@+id/button_login"
|
||||
app:layout_constraintVertical_bias="0.0" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -33,7 +33,7 @@
|
||||
android:hint="@string/confirm_password"
|
||||
android:inputType="textPassword"
|
||||
android:textAlignment="center"
|
||||
app:layout_constraintBottom_toTopOf="@+id/button_create_account"
|
||||
app:layout_constraintBottom_toTopOf="@+id/button_login"
|
||||
app:layout_constraintEnd_toEndOf="@+id/input_email_register"
|
||||
app:layout_constraintTop_toBottomOf="@+id/input_password_layout" />
|
||||
|
||||
@ -87,7 +87,7 @@
|
||||
app:layout_constraintTop_toBottomOf="@+id/input_email_register" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_create_account"
|
||||
android:id="@+id/button_login"
|
||||
style="@style/Widget.MaterialComponents.Button"
|
||||
android:layout_width="240dp"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -8,6 +8,7 @@
|
||||
<string name="btn_start_text">START</string>
|
||||
<string name="pause">PAUSE</string>
|
||||
<string name="stop">STOP</string>
|
||||
<string name="start">START</string>
|
||||
<string name="username_email">Your Username or E-Mail</string>
|
||||
<string name="username">Username</string>
|
||||
<string name="choose_username">Choose a Username</string>
|
||||
@ -37,4 +38,5 @@
|
||||
<string name="submit">Submit</string>
|
||||
<string name="logout">Logout</string>
|
||||
<string name="hello">Hello</string>
|
||||
<string name="outside_place">Outside your working place</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user