Skip to content

Commit

Permalink
implements idea from issue #2
Browse files Browse the repository at this point in the history
  • Loading branch information
kroegerama committed Sep 13, 2019
1 parent 79bbc6e commit 8517c56
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
implementation 'com.google.android.material:material:1.0.0'

implementation 'com.kroegerama:android-kaiteki:2.8.1'

Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/com/kroegerama/bcode/FragDialogExamples.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.kroegerama.bcode

import android.util.Log
import com.google.android.material.snackbar.Snackbar
import com.google.zxing.BarcodeFormat
import com.google.zxing.Result
import com.kroegerama.kaiteki.baseui.BaseFragment
import com.kroegerama.kaiteki.bcode.BarcodeResultListener
import com.kroegerama.kaiteki.bcode.ui.BarcodeBottomSheet
import com.kroegerama.kaiteki.bcode.ui.BarcodeDialog
import com.kroegerama.kaiteki.bcode.ui.showBarcodeAlertDialog
import com.kroegerama.kaiteki.snackBar
import kotlinx.android.synthetic.main.frag_dialog_examples.*

class FragDialogExamples : BaseFragment(
Expand Down Expand Up @@ -39,11 +41,19 @@ class FragDialogExamples : BaseFragment(
}
}

override fun onBarcodeScanCancelled() {
snackBar("Scanning cancelled", Snackbar.LENGTH_LONG) {
setAction(android.R.string.ok) {
dismiss()
}
}
}

override fun onBarcodeResult(result: Result): Boolean {
Log.d(TAG, "Result: $result")

//return false to not automatically close the dialog
return false
return true
}

companion object {
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0.3"
versionName "1.1.0"
}
compileOptions {
kotlinOptions.freeCompilerArgs += ['-module-name', "barcode.kaiteki"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ interface BarcodeResultListener {
*/
fun onBarcodeResult(result: Result): Boolean

fun onBarcodeScanCancelled()

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ fun Context.showBarcodeAlertDialog(
val dlg = AlertDialog.Builder(this)
.setOnDismissListener { bcode.unbind() }
.setView(view)
.setNegativeButton(android.R.string.cancel, null)
.setOnCancelListener {
listener.onBarcodeScanCancelled()
}
.setNegativeButton(android.R.string.cancel) { _, _ ->
listener.onBarcodeScanCancelled()
}
.show()

bcode.setFormats(formats)
Expand All @@ -50,6 +55,10 @@ fun Context.showBarcodeAlertDialog(
}
return doDismiss
}

override fun onBarcodeScanCancelled() {
//Ignore: BarcodeView will never emit this event
}
})

bcode.bindToLifecycle(owner)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kroegerama.kaiteki.bcode.ui

import android.content.DialogInterface
import android.os.Bundle
import android.os.Handler
import android.view.LayoutInflater
Expand Down Expand Up @@ -74,6 +75,16 @@ class BarcodeBottomSheet : BottomSheetDialogFragment(), BarcodeResultListener {
return false
}

override fun onBarcodeScanCancelled() {
//Ignore: BarcodeView will never emit this event
}

override fun onCancel(dialog: DialogInterface) {
(parentFragment as? BarcodeResultListener)?.onBarcodeScanCancelled()
(activity as? BarcodeResultListener)?.onBarcodeScanCancelled()
super.onCancel(dialog)
}

companion object {

private const val KEY_FORMATS = "formats"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kroegerama.kaiteki.bcode.ui

import android.content.DialogInterface
import android.os.Bundle
import android.os.Handler
import android.view.LayoutInflater
Expand Down Expand Up @@ -60,6 +61,10 @@ open class BarcodeDialog : DialogFragment(), BarcodeResultListener {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
}

override fun onBarcodeScanCancelled() {
//Ignore: BarcodeView will never emit this event
}

override fun onStop() {
super.onStop()
bcode.unbind()
Expand All @@ -85,6 +90,12 @@ open class BarcodeDialog : DialogFragment(), BarcodeResultListener {
return false
}

override fun onCancel(dialog: DialogInterface) {
(parentFragment as? BarcodeResultListener)?.onBarcodeScanCancelled()
(activity as? BarcodeResultListener)?.onBarcodeScanCancelled()
super.onCancel(dialog)
}

companion object {

private const val KEY_FORMATS = "formats"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class BarcodeFragment : Fragment(), BarcodeResultListener {
return false
}

override fun onBarcodeScanCancelled() {
//Ignore: BarcodeView will never emit this event
}

companion object {
private const val KEY_FORMATS = "formats"
private const val KEY_INVERTED = "inverted"
Expand Down

0 comments on commit 8517c56

Please sign in to comment.