Shorten code

This commit is contained in:
ligi 2016-12-24 12:52:09 +01:00
parent 413df5f2ef
commit 480868c699
No known key found for this signature in database
GPG key ID: 8E81894010ABF23D
2 changed files with 7 additions and 10 deletions

View file

@ -93,7 +93,7 @@ class BarcodeEditController(val rootView: View, internal val context: AppCompatA
}
fun refresh() {
val barcodeUIController = BarcodeUIController(rootView, barCode, context, PassViewHelper(context))
val barcodeUIController = BarcodeUIController(rootView, getBarCode(), context, PassViewHelper(context))
val isBarcodeShown = barcodeUIController.getBarcodeView().visibility == View.VISIBLE
if (!isBarcodeShown) {
@ -103,13 +103,10 @@ class BarcodeEditController(val rootView: View, internal val context: AppCompatA
}
}
val barCode: BarCode
get() {
val barCode = BarCode(barcodeFormat, rootView.messageInput.text.toString())
val alternativeText = rootView.alternativeMessageInput.text.toString()
if (!alternativeText.isEmpty()) {
barCode.alternativeText = alternativeText
}
return barCode
fun getBarCode() = BarCode(barcodeFormat, rootView.messageInput.text.toString()).apply {
val newAlternativeText = rootView.alternativeMessageInput.text.toString()
if (!newAlternativeText.isEmpty()) {
alternativeText = newAlternativeText
}
}
}

View file

@ -19,7 +19,7 @@ fun showBarcodeEditDialog(context: AppCompatActivity, bus: EventBus, pass: Pass,
.setTitle(R.string.edit_barcode_dialog_title)
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.ok) { dialog, which ->
pass.barCode = barcodeEditController.barCode
pass.barCode = barcodeEditController.getBarCode()
bus.post(PassRefreshEvent(pass))
}
.show()