-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/add auto-accept capability #9
base: master
Are you sure you want to change the base?
Conversation
f8c17f6
to
7aa691e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small things, and you need to sign the commit. I can help, it's important to prove who wrote the code I think you will find it useful elsewhere too.
internal class Options(val showBarcodeBounds: Boolean, | ||
val autoAcceptResult: Boolean) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kotlin style:
internal class Options(
val showBarcodeBounds: Boolean,
val autoAcceptResult: Boolean
)
For long class headers.
}) | ||
.show() | ||
} else onAccept(it) | ||
Timber.d("Accepted barcode") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This log is now in an incorrect place. Needs to show after onAccept
and for the Snackbar
path, it would actually show immediately now, instead of after.
Suggest: (note also inverting the if
so it doesn't have a !
)
value?.let {
if (options.autoAcceptResult) {
Timber.d("Accepted barcode automatically")
onAccept(it)
} else {
Snackbar.make(cameraSurfaceView, it, Snackbar.LENGTH_INDEFINITE)
.setAction(android.R.string.ok, { _ ->
Timber.d("Accepted barcode")
onAccept(it)
})
.show()
}
}
launch_autoaccept.setOnClickListener { | ||
startActivityForResult(Intent(this, ScanQrActivity::class.java).apply { | ||
putExtra(ScanQrActivity.OPTION_SHOW_BARCODE_BOX, BuildConfig.DEBUG) | ||
putExtra(ScanQrActivity.AUTOACCEPT_RESULT, true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Idea for future syntax:
startActivityForResult(Intent(this, ScanQrActivity::class.java)
.withScannerOptions {
if (BuildConfig.DEBUG) showBox()
autoAccept()
}, REQUEST_SCAN)
Then these ugly CAPITAL options and the room for error in the values passed to them disappears.
fun Intent.withScannerOptions(function: (IntentOptions) -> Unit): Intent {
function(IntentOptions(this))
return this
}
class IntentOptions(private intent: Intent) {
fun autoAccept(){
intent.putExtra(ScanQrActivity.AUTOACCEPT_RESULT, true)
}
//etc
}
You get the idea? Would be separate issue and PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, This is a good use of extension functions.
1d05dff
to
f78ef73
Compare
5edfbc1
to
519130f
Compare
The two things you put 👍 on, still need doing/got lost during the attempt to sign. |
519130f
to
c66601c
Compare
633d316
to
a0dc1c7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 nice to haves
@@ -34,6 +34,7 @@ open class ScanQrActivity : AppCompatActivity() { | |||
companion object { | |||
const val OPTION_SHOW_BARCODE_BOX = "SHOW_BARCODE_BOX" | |||
const val BARCODE_DATA = "BARCODE_DATA" | |||
const val AUTOACCEPT_RESULT = "AUTOACCEPT_RESULT" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be nice if matched the existing option:
const val OPTION_AUTOACCEPT_RESULT = "AUTOACCEPT_RESULT"
And put them side by side.
}, REQUEST_SCAN) | ||
} | ||
|
||
// Custom scanner | ||
launch_xpub.setOnClickListener { | ||
launch_xpub.setOnClickListener { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be nice to revert this extra space.
Options(this?.extras?.getBoolean(OPTION_SHOW_BARCODE_BOX) ?: false) | ||
private fun Intent?.toOptions() = Options( | ||
this?.extras?.getBoolean(OPTION_SHOW_BARCODE_BOX) ?: false, | ||
this?.extras?.getBoolean(AUTOACCEPT_RESULT) ?: false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
be nice to newline before the )
:
private fun Intent?.toOptions() = Options(
Options(this?.extras?.getBoolean(OPTION_SHOW_BARCODE_BOX) ?: false) + this?.extras?.getBoolean(OPTION_SHOW_BARCODE_BOX) ?: false,
this?.extras?.getBoolean(AUTOACCEPT_RESULT) ?: false
)
a0dc1c7
to
f78ef73
Compare
7fb9cc4
to
ad4c2da
Compare
I've added the ability to auto-accept result after the first QR code is scanned.
Closes #10