Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stefan Zabka
Companion App Android
Commits
3fd6494c
Commit
3fd6494c
authored
Aug 17, 2019
by
Andreas Schildbach
Browse files
MainFragment: Show pairing status in status line.
parent
500e95d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/de/ccc/events/badge/card10/main/MainFragment.kt
View file @
3fd6494c
...
...
@@ -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
())
...
...
app/src/main/res/values/strings.xml
View file @
3fd6494c
<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>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment