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
7cff04ec
Commit
7cff04ec
authored
Aug 21, 2019
by
Anon
Browse files
FileTransferFragment: Add error handling.
parent
be9f3535
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/de/ccc/events/badge/card10/filetransfer/FileTransferFragment.kt
View file @
7cff04ec
...
...
@@ -34,11 +34,14 @@ import android.widget.EditText
import
android.widget.ProgressBar
import
android.widget.TextView
import
androidx.annotation.UiThread
import
androidx.appcompat.app.AlertDialog
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.ConnectionException
import
de.ccc.events.badge.card10.common.ConnectionService
import
de.ccc.events.badge.card10.common.GattListener
import
de.ccc.events.badge.card10.main.MainFragment
import
java.lang.Exception
import
java.lang.IllegalStateException
...
...
@@ -76,8 +79,15 @@ class FileTransferFragment : Fragment(), GattListener, FileTransferListener{
buttonStartStop
=
view
.
findViewById
(
R
.
id
.
button_start_stop_transfer
)
initConnection
()
toggleControls
()
try
{
initConnection
()
toggleControls
()
}
catch
(
e
:
ConnectionException
)
{
showError
(
e
.
message
)
}
catch
(
e
:
Exception
)
{
showError
(
getString
(
R
.
string
.
connection_error_generic
))
}
}
private
fun
initConnection
()
{
...
...
@@ -160,4 +170,21 @@ class FileTransferFragment : Fragment(), GattListener, FileTransferListener{
}
toggleControls
()
}
private
fun
showError
(
message
:
String
?)
{
val
ctx
=
context
?:
throw
IllegalStateException
()
val
fm
=
fragmentManager
?:
throw
IllegalStateException
()
val
errorDialog
=
AlertDialog
.
Builder
(
ctx
)
.
setMessage
(
message
?:
getString
(
R
.
string
.
connection_error_generic
))
.
setPositiveButton
(
R
.
string
.
dialog_action_ok
)
{
dialog
,
_
->
dialog
.
dismiss
()
fm
.
beginTransaction
()
.
replace
(
R
.
id
.
fragment_container
,
MainFragment
())
.
addToBackStack
(
null
)
.
commit
()
}
.
show
()
}
}
\ No newline at end of file
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