diff --git a/app/src/main/java/de/ccc/events/badge/card10/main/MainFragment.kt b/app/src/main/java/de/ccc/events/badge/card10/main/MainFragment.kt index 5874b298c0853e61e7efb94038f4725dff95b3a6..16a22357532dff6ffd7e25c84176083351e62885 100644 --- a/app/src/main/java/de/ccc/events/badge/card10/main/MainFragment.kt +++ b/app/src/main/java/de/ccc/events/badge/card10/main/MainFragment.kt @@ -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 diff --git a/app/src/main/res/layout/main_fragment.xml b/app/src/main/res/layout/main_fragment.xml index 68af2272211c7398e3a0bfb735ead62bccb28093..09e55d4910150e1c3cb65f0196e80dfcc6068e66 100644 --- a/app/src/main/res/layout/main_fragment.xml +++ b/app/src/main/res/layout/main_fragment.xml @@ -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>