Skip to content

Commit

Permalink
Reduce indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tsudoko committed Apr 13, 2018
1 parent d101ac0 commit 8e6578b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 36 deletions.
52 changes: 24 additions & 28 deletions app/src/main/java/re/flande/xshare/ImportActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 4 additions & 8 deletions app/src/main/java/re/flande/xshare/Uploader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

0 comments on commit 8e6578b

Please sign in to comment.