diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f381a06a..d124c6b5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -63,6 +63,24 @@ + + + + + + + + + + + + + + + + + + + val destination = File(path) + inputStream.copyStreamToFile(destination) + toast("Please restart app") + } + } + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + + when (requestCode) { + RequestCode.IMPORT.value -> { + if (resultCode == ResultCode.IMPORT_UNRECOGNIZED_FORMAT.value) { + showAlertDialog(context = this, messageResId = R.string.unknown_import_format_popup_message, positiveAction = { + finish() + }) + } + } + } + } + + // Import + + private fun requestImportConfirmation() { + + showAlertDialog(context = this, title = R.string.import_confirmation, showCancelButton = true, positiveAction = { + initUI() + }, negativeAction = { + finish() + }) + + } + +} \ No newline at end of file diff --git a/app/src/main/java/net/pokeranalytics/android/util/FileUtils.kt b/app/src/main/java/net/pokeranalytics/android/util/FileUtils.kt index 3c0f1bf5..92dce53b 100644 --- a/app/src/main/java/net/pokeranalytics/android/util/FileUtils.kt +++ b/app/src/main/java/net/pokeranalytics/android/util/FileUtils.kt @@ -6,6 +6,7 @@ import timber.log.Timber import java.io.File import java.io.FileOutputStream import java.io.IOException +import java.io.InputStream class FileUtils { @@ -54,4 +55,19 @@ class FileUtils { } +} + +fun InputStream.copyStreamToFile(outputFile: File) { + this.use { input -> + val outputStream = FileOutputStream(outputFile) + outputStream.use { output -> + val buffer = ByteArray(4 * 1024) // buffer size + while (true) { + val byteCount = input.read(buffer) + if (byteCount < 0) break + output.write(buffer, 0, byteCount) + } + output.flush() + } + } } \ No newline at end of file