Commit 31166e45 authored by Andreas Schildbach's avatar Andreas Schildbach
Browse files

MainFragment: Add third group for paired buttons.

That way, mood selection is available if a card10 is paired but not connected yet. The MoodFragment will deal with connecting to gatt.
parent 9c5fc5e9
......@@ -33,6 +33,7 @@ import androidx.fragment.app.Fragment
import de.ccc.events.badge.card10.CARD10_BLUETOOTH_MAC_PREFIX
import de.ccc.events.badge.card10.R
import de.ccc.events.badge.card10.common.ConnectionService
import de.ccc.events.badge.card10.mood.MoodFragment
import de.ccc.events.badge.card10.scanner.ScannerFragment
import kotlinx.android.synthetic.main.main_fragment.*
......@@ -48,8 +49,10 @@ class MainFragment : Fragment() {
if (bondedCard10s.isNotEmpty()) {
val device = bondedCard10s.get(0)
label_status.text = getString(R.string.main_label_paired, device.name, device.address)
container_paired.visibility = View.VISIBLE
} else {
label_status.text = getString(R.string.main_label_not_connected)
container_paired.visibility = View.GONE
}
if (ConnectionService.isConnected()) {
......@@ -57,6 +60,19 @@ class MainFragment : Fragment() {
} else {
showDisconnectedView(view)
}
button_pair.setOnClickListener {
fragmentManager!!.beginTransaction()
.replace(R.id.fragment_container, ScannerFragment())
.addToBackStack(null)
.commit()
}
button_mood.setOnClickListener {
fragmentManager!!.beginTransaction()
.replace(R.id.fragment_container, MoodFragment())
.addToBackStack(null)
.commit()
}
}
private fun showConnectedView(view: View) {
......@@ -72,14 +88,6 @@ class MainFragment : Fragment() {
private fun showDisconnectedView(view: View) {
view.findViewById<ConstraintLayout>(R.id.container_connected).visibility = View.GONE
view.findViewById<ConstraintLayout>(R.id.container_disconnected).visibility = View.VISIBLE
button_pair.setOnClickListener {
fragmentManager!!.beginTransaction()
.replace(R.id.fragment_container, ScannerFragment())
.addToBackStack(null)
.commit()
}
val buttonConnect = view.findViewById<Button>(R.id.button_connect)
buttonConnect.setOnClickListener {
// TODO: Open scan fragment
......
......@@ -26,56 +26,64 @@
<androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/label_status"
android:id="@+id/container_connected">
<Button android:layout_width="wrap_content"
android:id="@+id/container_disconnected">
<Button android:id="@+id/button_pair"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/main_label_margin"
android:id="@+id/button_hatchery"
android:text="@string/main_button_browse_apps"
android:text="pair"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
app:layout_constraintRight_toRightOf="parent"/>
<Button android:layout_width="wrap_content"
<Button android:id="@+id/button_connect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/main_label_margin"
android:id="@+id/button_send"
android:text="@string/main_button_send_file"
android:text="@string/main_button_connect"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@id/button_pair"/>
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_hatchery"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/container_disconnected"
android:id="@+id/container_paired">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/main_label_margin"
android:id="@+id/button_mood"
android:text="@string/main_button_mood"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_send"/>
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/label_status"
android:id="@+id/container_disconnected">
<Button android:id="@+id/button_pair"
android:layout_width="wrap_content"
android:id="@+id/container_connected">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="pair"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginTop="@dimen/main_label_margin"
android:id="@+id/button_hatchery"
android:text="@string/main_button_browse_apps"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<Button android:id="@+id/button_connect"
android:layout_width="wrap_content"
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/main_button_connect"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@id/button_pair"/>
android:layout_marginTop="@dimen/main_label_margin"
android:id="@+id/button_send"
android:text="@string/main_button_send_file"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_hatchery"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment