diff --git a/app/src/main/java/re/flande/xshare/ImportActivity.kt b/app/src/main/java/re/flande/xshare/ImportActivity.kt index 663d0e9..3c4085b 100644 --- a/app/src/main/java/re/flande/xshare/ImportActivity.kt +++ b/app/src/main/java/re/flande/xshare/ImportActivity.kt @@ -53,38 +53,34 @@ class ImportActivity : Activity() { } } - private fun import(up: Uploader) { - try { - val name = (up.Name + ".sxcu").replace("/", "⁄") - val f = File(getExternalFilesDir(null), name) - - if (f.exists()) { - val d = getFatalDialogBuilder(this) - .setMessage(resources.getString(R.string.thing_already_exists, up.Name)) - .setPositiveButton(R.string.overwrite, { _, _ -> uploaderToFile(up, f) }) - .setNeutralButton(R.string.rename, null) - .setNegativeButton(android.R.string.cancel, { _, _ -> }) - .create() - - d.setOnShowListener { - d.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener { rename(up); d.hide() } - } - d.show() - } else { - uploaderToFile(up, f) + private fun import(up: Uploader) = try { + val name = (up.Name + ".sxcu").replace("/", "⁄") + val f = File(getExternalFilesDir(null), name) + + if (f.exists()) { + val d = getFatalDialogBuilder(this) + .setMessage(resources.getString(R.string.thing_already_exists, up.Name)) + .setPositiveButton(R.string.overwrite, { _, _ -> uploaderToFile(up, f) }) + .setNeutralButton(R.string.rename, null) + .setNegativeButton(android.R.string.cancel, { _, _ -> }) + .create() + + d.setOnShowListener { + d.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener { rename(up); d.hide() } } - } catch (e: Exception) { - fail(e) + d.show() + } else { + uploaderToFile(up, f) } + } catch (e: Exception) { + fail(e) } - private fun importStream(inStream: InputStream) { - try { - val up = Uploader.fromInputStream(inStream) - import(up) - } catch (e: Exception) { - fail(e) - } + private fun importStream(inStream: InputStream) = try { + val up = Uploader.fromInputStream(inStream) + import(up) + } catch (e: Exception) { + fail(e) } private fun fail(e: Exception) { diff --git a/app/src/main/java/re/flande/xshare/Uploader.kt b/app/src/main/java/re/flande/xshare/Uploader.kt index 61ba2a6..de4ed4e 100644 --- a/app/src/main/java/re/flande/xshare/Uploader.kt +++ b/app/src/main/java/re/flande/xshare/Uploader.kt @@ -139,14 +139,10 @@ class Uploader(var Name: String?, } companion object { - fun fromInputStream(stream: InputStream): Uploader { - stream.use { - it.reader().use { - val uploader = Gson().fromJson(it, Uploader::class.java) - uploader.validate() - return uploader - } - } + fun fromInputStream(stream: InputStream): Uploader = stream.reader().use { + val uploader = Gson().fromJson(it, Uploader::class.java) + uploader.validate() + return uploader } } }