Commit 3fd6494c authored by Andreas Schildbach's avatar Andreas Schildbach
Browse files

MainFragment: Show pairing status in status line.

parent 500e95d0
......@@ -22,24 +22,36 @@
package de.ccc.events.badge.card10.main
import android.bluetooth.BluetoothAdapter
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
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.scanner.ScannerFragment
import kotlinx.android.synthetic.main.main_fragment.*
class MainFragment : Fragment() {
private val bluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?) =
inflater.inflate(R.layout.main_fragment, container, false)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
val bondedCard10s =
bluetoothAdapter.bondedDevices.filter { it.address.startsWith(CARD10_BLUETOOTH_MAC_PREFIX, true) }
if (bondedCard10s.isNotEmpty()) {
val device = bondedCard10s.get(0)
label_status.text = getString(R.string.main_label_paired, device.name, device.address)
} else {
label_status.text = getString(R.string.main_label_not_connected)
}
if (ConnectionService.isConnected()) {
showConnectedView(view)
} else {
......@@ -51,10 +63,6 @@ class MainFragment : Fragment() {
view.findViewById<ConstraintLayout>(R.id.container_connected).visibility = View.VISIBLE
view.findViewById<ConstraintLayout>(R.id.container_disconnected).visibility = View.GONE
val tvStatus = view.findViewById<TextView>(R.id.label_status)
tvStatus.text =
getString(R.string.main_label_status, ConnectionService.deviceName, ConnectionService.deviceAddress)
val buttonSend = view.findViewById<Button>(R.id.button_send)
buttonSend.setOnClickListener {
// TODO: Open file transfer fragment
......@@ -65,9 +73,6 @@ class MainFragment : Fragment() {
view.findViewById<ConstraintLayout>(R.id.container_connected).visibility = View.GONE
view.findViewById<ConstraintLayout>(R.id.container_disconnected).visibility = View.VISIBLE
val tvStatus = view.findViewById<TextView>(R.id.label_status)
tvStatus.text = getString(R.string.main_label_not_connected)
button_pair.setOnClickListener {
fragmentManager!!.beginTransaction()
.replace(R.id.fragment_container, ScannerFragment())
......
<resources>
<string name="app_name">card10 Companion</string>
<string name="main_label_paired">You are paired to %1$s (%2$s)</string>
<string name="main_label_not_connected">You are currently not connected to your card10.</string>
<string name="main_label_status">You are connected to %1$s (%2$s)</string>
<string name="main_button_connect">Connect</string>
......
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