Skip to content

Commit

Permalink
add exit button and disable save button until data is acquired
Browse files Browse the repository at this point in the history
  • Loading branch information
bri3d committed Jun 11, 2019
1 parent f684fc2 commit aee5bfd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class MainActivity : FragmentActivity(), AdjustFieldFragment.OnParameterAdjusted
Context.BIND_AUTO_CREATE)

isActive = savedInstanceState?.getBoolean("Active") ?: false
button.isEnabled = isActive
connectionSwitch.isChecked = isActive

connectionSwitch.setOnCheckedChangeListener { _: CompoundButton, isChecked: Boolean ->
if (isChecked && !isActive) {
Expand All @@ -65,9 +67,14 @@ class MainActivity : FragmentActivity(), AdjustFieldFragment.OnParameterAdjusted
}
}

button.setOnClickListener { _ ->
button.setOnClickListener {
saveBoostAndOctane()
}

exitSwitch.setOnClickListener {
stopBluetoothThread()
finish()
}
}

override fun onSaveInstanceState(outState: Bundle?, outPersistentState: PersistableBundle?) {
Expand Down Expand Up @@ -125,6 +132,7 @@ class MainActivity : FragmentActivity(), AdjustFieldFragment.OnParameterAdjusted
ServiceActions.Responses.SOCKET_CLOSED, ServiceActions.Responses.CONNECTION_NOT_ACTIVE -> {
statusLabel.text = resources.getString(R.string.not_connected)
isActive = false
button.isEnabled = false
connectionSwitch.isChecked = false
}
ServiceActions.Responses.CONNECTION_ACTIVE -> {
Expand Down Expand Up @@ -155,6 +163,7 @@ class MainActivity : FragmentActivity(), AdjustFieldFragment.OnParameterAdjusted
serviceMessenger?.send(messageWithIntent(Intent(ServiceActions.Requests.FETCH_TUNE_DATA)))
}
ServiceActions.Responses.TUNE_DATA -> {
button.isEnabled = true
statusLabel.text = resources.getString(R.string.got_data)
val octaneData = intent.getParcelableExtra<EurodyneIO.OctaneInfo>("octaneInfo")
val boostData = intent.getParcelableExtra<EurodyneIO.BoostInfo>("boostInfo")
Expand Down Expand Up @@ -208,6 +217,10 @@ class MainActivity : FragmentActivity(), AdjustFieldFragment.OnParameterAdjusted

override fun onBackPressed() {
super.onBackPressed()
stopBluetoothThread()
}

private fun stopBluetoothThread() {
val serviceIntent = Intent(this, BluetoothService::class.java)
stopService(serviceIntent)
}
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,23 @@
android:saveEnabled="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/fieldThreeFragmentContainer"
app:layout_constraintBottom_toTopOf="@+id/exitSwitch"
app:layout_constraintVertical_weight="1.5" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/exitSwitch"
android:text="@string/exit"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/save"
android:enabled="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
<string name="vinNumber">VIN</string>
<string name="channel_name">Eurodyne Tune Adjuster</string>
<string name="channel_description">Notification used to keep Bluetooth running.</string>
<string name="exit">Exit</string>
</resources>

0 comments on commit aee5bfd

Please sign in to comment.