Catches exception when import fails and show error message

od
Laurent 6 years ago
parent 367dfa7ccb
commit 0003f38f23
  1. 13
      app/src/main/java/net/pokeranalytics/android/ui/fragment/ImportFragment.kt
  2. 1
      app/src/main/res/values/strings.xml

@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.fragment_import.* import kotlinx.android.synthetic.main.fragment_import.*
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
@ -15,6 +16,7 @@ import net.pokeranalytics.android.util.csv.CSVImporter
import net.pokeranalytics.android.util.csv.ImportDelegate import net.pokeranalytics.android.util.csv.ImportDelegate
import net.pokeranalytics.android.util.csv.ImportException import net.pokeranalytics.android.util.csv.ImportException
import timber.log.Timber import timber.log.Timber
import java.io.IOException
import java.io.InputStream import java.io.InputStream
import java.text.NumberFormat import java.text.NumberFormat
import java.util.* import java.util.*
@ -74,6 +76,8 @@ class ImportFragment : RealmFragment(), ImportDelegate {
this.importer = CSVImporter(inputStream) this.importer = CSVImporter(inputStream)
this.importer.delegate = this this.importer.delegate = this
var error = false
GlobalScope.launch(coroutineContext) { GlobalScope.launch(coroutineContext) {
val test = GlobalScope.async { val test = GlobalScope.async {
@ -84,6 +88,9 @@ class ImportFragment : RealmFragment(), ImportDelegate {
importer.start() importer.start()
} catch (e: ImportException) { } catch (e: ImportException) {
// shouldDismissActivity = true // shouldDismissActivity = true
error = true
} catch (e: IOException) {
error = true
} }
val e = Date() val e = Date()
val duration = (e.time - s.time) / 1000.0 val duration = (e.time - s.time) / 1000.0
@ -92,6 +99,12 @@ class ImportFragment : RealmFragment(), ImportDelegate {
} }
test.await() test.await()
if (error && view != null) {
Snackbar.make(view!!, R.string.import_error, Snackbar.LENGTH_INDEFINITE).show()
}
// if (shouldDismissActivity) { // if (shouldDismissActivity) {
// //
// activity?.let { // activity?.let {

@ -41,6 +41,7 @@
<string name="iap_session_message">You\'ve reached the maximum number of free sessions. Please subscribe for unlimited use and don\'t hesitate to tell us how you feel about your current experience!</string> <string name="iap_session_message">You\'ve reached the maximum number of free sessions. Please subscribe for unlimited use and don\'t hesitate to tell us how you feel about your current experience!</string>
<string name="stacking_incoming">Stacking incoming</string> <string name="stacking_incoming">Stacking incoming</string>
<string name="stacking_outgoing">Stacking outgoing</string> <string name="stacking_outgoing">Stacking outgoing</string>
<string name="import_error">There has been an issue with the import. Please check out your file or contact the support!</string>
<string name="address">Address</string> <string name="address">Address</string>
<string name="suggestions">Naming suggestions</string> <string name="suggestions">Naming suggestions</string>

Loading…
Cancel
Save