|
|
|
@ -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 android.widget.TextView |
|
|
|
import com.google.android.material.snackbar.Snackbar |
|
|
|
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 |
|
|
|
@ -14,9 +15,7 @@ import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.RealmFragment |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.RealmFragment |
|
|
|
import net.pokeranalytics.android.util.csv.CSVImporter |
|
|
|
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 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.* |
|
|
|
@ -76,7 +75,7 @@ class ImportFragment : RealmFragment(), ImportDelegate { |
|
|
|
this.importer = CSVImporter(inputStream) |
|
|
|
this.importer = CSVImporter(inputStream) |
|
|
|
this.importer.delegate = this |
|
|
|
this.importer.delegate = this |
|
|
|
|
|
|
|
|
|
|
|
var error = false |
|
|
|
var exception: Exception? = null |
|
|
|
|
|
|
|
|
|
|
|
GlobalScope.launch(coroutineContext) { |
|
|
|
GlobalScope.launch(coroutineContext) { |
|
|
|
|
|
|
|
|
|
|
|
@ -86,11 +85,8 @@ class ImportFragment : RealmFragment(), ImportDelegate { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
importer.start() |
|
|
|
importer.start() |
|
|
|
} catch (e: ImportException) { |
|
|
|
} catch (e: Exception) { |
|
|
|
// shouldDismissActivity = true |
|
|
|
exception = e |
|
|
|
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 |
|
|
|
@ -99,12 +95,15 @@ class ImportFragment : RealmFragment(), ImportDelegate { |
|
|
|
} |
|
|
|
} |
|
|
|
test.await() |
|
|
|
test.await() |
|
|
|
|
|
|
|
|
|
|
|
if (error && view != null) { |
|
|
|
val exceptionMessage = exception?.message |
|
|
|
Snackbar.make(view!!, R.string.import_error, Snackbar.LENGTH_INDEFINITE).show() |
|
|
|
if (exceptionMessage != null && view != null) { |
|
|
|
|
|
|
|
val message = exceptionMessage + ". " + requireContext().getString(R.string.import_error) |
|
|
|
|
|
|
|
val snackBar = Snackbar.make(view!!, message, Snackbar.LENGTH_INDEFINITE) |
|
|
|
|
|
|
|
val textView = snackBar.view.findViewById<TextView>(com.google.android.material.R.id.snackbar_text) |
|
|
|
|
|
|
|
textView.maxLines = 4 |
|
|
|
|
|
|
|
snackBar.show() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (shouldDismissActivity) { |
|
|
|
// if (shouldDismissActivity) { |
|
|
|
// |
|
|
|
// |
|
|
|
// activity?.let { |
|
|
|
// activity?.let { |
|
|
|
|