@@ -19,31 +19,29 @@ import io.snabble.sdk.ui.utils.setOneShotClickListener
1919
2020open class SelfScanningFragment : Fragment () {
2121 private var optionsMenu: Menu ? = null
22- private var _selfScanningView : SelfScanningView ? = null
23- val selfScanningView: SelfScanningView
24- get() = requireNotNull(_selfScanningView )
22+ var selfScanningView: SelfScanningView ? = null
2523 protected lateinit var rootView: ViewGroup
2624 private lateinit var permissionContainer: View
2725 private lateinit var askForPermission: Button
2826 private var canAskAgain = false
2927 private var isStart = false
3028 var allowShowingHints = false
3129 val hasSelfScanningView
32- get() = _selfScanningView != null
30+ get() = selfScanningView != null
3331
3432 override fun onCreateView (
3533 inflater : LayoutInflater ,
3634 container : ViewGroup ? ,
3735 savedInstanceState : Bundle ?
3836 ): View ? {
39- setHasOptionsMenu(true )
37+ setHasOptionsMenu(false )
4038 return inflater.inflate(R .layout.snabble_fragment_selfscanning, container, false )
4139 }
4240
4341 override fun onViewCreated (view : View , savedInstanceState : Bundle ? ) {
4442 super .onViewCreated(view, savedInstanceState)
4543 rootView = view as ViewGroup
46- _selfScanningView = null
44+ selfScanningView = null
4745 permissionContainer = rootView.findViewById(R .id.permission_denied_container)
4846 askForPermission = rootView.findViewById(R .id.open_settings)
4947
@@ -62,8 +60,8 @@ open class SelfScanningFragment : Fragment() {
6260 if (isPermissionGranted) {
6361 createSelfScanningView()
6462 } else {
65- rootView.removeView(_selfScanningView )
66- _selfScanningView = null
63+ rootView.removeView(selfScanningView )
64+ selfScanningView = null
6765 if (isAdded && isStart) {
6866 requestPermissions(arrayOf(Manifest .permission.CAMERA ), 0 )
6967 } else {
@@ -74,11 +72,12 @@ open class SelfScanningFragment : Fragment() {
7472 }
7573
7674 private fun createSelfScanningView () {
77- if (_selfScanningView == null ) {
78- _selfScanningView = SelfScanningView (context).apply {
75+ if (selfScanningView == null ) {
76+ selfScanningView = SelfScanningView (context).apply {
7977 setAllowShowingHints(allowShowingHints)
8078 }
8179 rootView.addView(selfScanningView, 0 )
80+ setHasOptionsMenu(true )
8281 }
8382 permissionContainer.visibility = View .GONE
8483 canAskAgain = true
@@ -88,7 +87,7 @@ open class SelfScanningFragment : Fragment() {
8887 private fun handleBundleArgs () {
8988 arguments?.let { args ->
9089 args.getString(" showProductCode" )?.let { scannableCode ->
91- _selfScanningView ?.lookupAndShowProduct(
90+ selfScanningView ?.lookupAndShowProduct(
9291 ScannedCode .parse(
9392 SnabbleUI .getProject(),
9493 scannableCode
@@ -152,10 +151,10 @@ open class SelfScanningFragment : Fragment() {
152151 override fun onOptionsItemSelected (item : MenuItem ): Boolean {
153152 when (item.itemId) {
154153 R .id.snabble_action_search -> {
155- selfScanningView.searchWithBarcode()
154+ selfScanningView? .searchWithBarcode()
156155 }
157156 R .id.snabble_action_torch -> {
158- selfScanningView.isTorchEnabled = ! selfScanningView.isTorchEnabled
157+ selfScanningView? .isTorchEnabled = ! ( selfScanningView? .isTorchEnabled ? : false )
159158 updateTorchIcon()
160159 }
161160 }
@@ -165,7 +164,7 @@ open class SelfScanningFragment : Fragment() {
165164
166165 private fun updateTorchIcon () {
167166 val menuItem = optionsMenu?.findItem(R .id.snabble_action_torch)
168- if (selfScanningView.isTorchEnabled) {
167+ if (selfScanningView? .isTorchEnabled ? : false ) {
169168 menuItem?.icon = ResourcesCompat .getDrawable(resources, R .drawable.snabble_ic_flashlight_on, null )
170169 } else {
171170 menuItem?.icon = ResourcesCompat .getDrawable(resources, R .drawable.snabble_ic_flashlight_off, null )
0 commit comments