Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

EbenezerGH
Copy link
Collaborator

@EbenezerGH EbenezerGH commented May 31, 2018

I've added the ability to auto-accept result after the first QR code is scanned.

Closes #10

@EbenezerGH EbenezerGH force-pushed the add-auto-accept-capability branch from f8c17f6 to 7aa691e Compare May 31, 2018 04:40
EbenezerGH pushed a commit that referenced this pull request May 31, 2018
@EbenezerGH EbenezerGH changed the title Feature/add auto-accept capability(#8) Feature/add auto-accept capability(#9) May 31, 2018
Copy link
Member

@westonal westonal left a 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)
Copy link
Member

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")
Copy link
Member

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)
Copy link
Member

@westonal westonal Jun 2, 2018

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.

Copy link
Collaborator Author

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.

@EbenezerGH EbenezerGH closed this Jun 4, 2018
@EbenezerGH EbenezerGH force-pushed the add-auto-accept-capability branch from 1d05dff to f78ef73 Compare June 4, 2018 01:00
@EbenezerGH EbenezerGH reopened this Jun 6, 2018
@EbenezerGH EbenezerGH force-pushed the add-auto-accept-capability branch 3 times, most recently from 5edfbc1 to 519130f Compare June 6, 2018 23:06
@westonal
Copy link
Member

westonal commented Jun 6, 2018

The two things you put 👍 on, still need doing/got lost during the attempt to sign.

@EbenezerGH EbenezerGH force-pushed the add-auto-accept-capability branch from 519130f to c66601c Compare June 7, 2018 05:26
@westonal westonal changed the title Feature/add auto-accept capability(#9) Feature/add auto-accept capability Jun 7, 2018
@EbenezerGH EbenezerGH force-pushed the add-auto-accept-capability branch 5 times, most recently from 633d316 to a0dc1c7 Compare June 7, 2018 13:30
Copy link
Member

@westonal westonal left a 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"
Copy link
Member

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 {
Copy link
Member

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)
Copy link
Member

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
    )

@EbenezerGH EbenezerGH closed this Jun 7, 2018
@EbenezerGH EbenezerGH force-pushed the add-auto-accept-capability branch from a0dc1c7 to f78ef73 Compare June 7, 2018 19:58
@EbenezerGH EbenezerGH reopened this Jun 7, 2018
@EbenezerGH EbenezerGH force-pushed the add-auto-accept-capability branch from 7fb9cc4 to ad4c2da Compare June 7, 2018 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants