Skip to content
This repository has been archived by the owner on Oct 10, 2020. It is now read-only.

App crash on orientation change #208 #209

Merged
merged 3 commits into from
Apr 14, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class BarcodeScannerActivity : Activity(), ZXingScannerView.ResultHandler {

private lateinit var config: Protos.Configuration
lateinit var scannerView: ZXingScannerView
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to change the scannerView to a nullable private var (just to prevent further problems like this one):

private var scannerView: ZXingScannerView? = null

private var scannerViewInitialized: Boolean = false

companion object {
const val TOGGLE_FLASH = 200
Expand Down Expand Up @@ -49,7 +48,7 @@ class BarcodeScannerActivity : Activity(), ZXingScannerView.ResultHandler {
}

private fun setupScannerView() {
if (scannerViewInitialized) {
if (this::scannerView.isInitialized) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (scannerView != null) {
    return
}

return
}

Expand All @@ -69,13 +68,12 @@ class BarcodeScannerActivity : Activity(), ZXingScannerView.ResultHandler {
}

setContentView(scannerView)
scannerViewInitialized = true
}

// region AppBar menu
override fun onCreateOptionsMenu(menu: Menu): Boolean {
var buttonText = config.stringsMap["flash_on"]
if (scannerView.flash) {
if (this::scannerView.isInitialized && scannerView.flash) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (scannerView?.flash == true) {
    buttonText = config.stringsMap["flash_off"]
}

buttonText = config.stringsMap["flash_off"]
}
val item = menu.add(0, TOGGLE_FLASH, 0, buttonText)
Expand Down