Skip to content

adds hints trying to improve read performance #5798

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

Open
wants to merge 3 commits into
base: graphite-base/5798
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -53,4 +53,7 @@ interface SyncFeature {

@Toggle.DefaultValue(true)
fun automaticallyUpdateSyncSettings(): Toggle

@Toggle.DefaultValue(true)
fun qrCodeScannerHints(): Toggle
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,27 @@ import androidx.lifecycle.findViewTreeLifecycleOwner
import androidx.lifecycle.findViewTreeViewModelStoreOwner
import androidx.lifecycle.lifecycleScope
import com.duckduckgo.anvil.annotations.InjectWith
import com.duckduckgo.appbuildconfig.api.AppBuildConfig
import com.duckduckgo.appbuildconfig.api.isInternalBuild
import com.duckduckgo.common.ui.viewbinding.viewBinding
import com.duckduckgo.common.utils.ConflatedJob
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.di.scopes.ViewScope
import com.duckduckgo.sync.impl.R
import com.duckduckgo.sync.impl.SyncFeature
import com.duckduckgo.sync.impl.databinding.ViewSquareDecoratedBarcodeBinding
import com.duckduckgo.sync.impl.ui.qrcode.SquareDecoratedBarcodeViewModel.Command
import com.duckduckgo.sync.impl.ui.qrcode.SquareDecoratedBarcodeViewModel.Command.CheckCameraAvailable
import com.duckduckgo.sync.impl.ui.qrcode.SquareDecoratedBarcodeViewModel.Command.CheckPermissions
import com.duckduckgo.sync.impl.ui.qrcode.SquareDecoratedBarcodeViewModel.Command.OpenSettings
import com.duckduckgo.sync.impl.ui.qrcode.SquareDecoratedBarcodeViewModel.Command.RequestPermissions
import com.duckduckgo.sync.impl.ui.qrcode.SquareDecoratedBarcodeViewModel.ViewState
import com.google.zxing.BarcodeFormat.QR_CODE
import com.google.zxing.client.android.BeepManager
import com.journeyapps.barcodescanner.DefaultDecoderFactory
import com.journeyapps.barcodescanner.camera.CameraSettings
import dagger.android.support.AndroidSupportInjection
import javax.inject.Inject
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

Expand All @@ -72,6 +78,12 @@ constructor(
@Inject
lateinit var dispatchers: DispatcherProvider

@Inject
lateinit var appBuildConfig: AppBuildConfig

@Inject
lateinit var syncFeature: SyncFeature

private val cameraBlockedDrawable by lazy {
ContextCompat.getDrawable(context, R.drawable.camera_blocked)
}
Expand All @@ -86,13 +98,22 @@ constructor(
ViewModelProvider(findViewTreeViewModelStoreOwner()!!, viewModelFactory)[SquareDecoratedBarcodeViewModel::class.java]
}

private var beepManager: BeepManager? = null

private val cameraSettings = CameraSettings().apply {
Copy link
Member

Choose a reason for hiding this comment

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

should this also be kill-switch’d ? (separate from qrCodeScannerHints)

It seems like an innocent no-brainer of a change, but you never know...

isAutoFocusEnabled = true
isContinuousFocusEnabled = true
}

private val conflatedStateJob = ConflatedJob()
private val conflatedCommandJob = ConflatedJob()

override fun onAttachedToWindow() {
AndroidSupportInjection.inject(this)
super.onAttachedToWindow()

initQRScanner()

findViewTreeLifecycleOwner()?.lifecycle?.addObserver(viewModel)

val scope = findViewTreeLifecycleOwner()?.lifecycleScope!!
Expand All @@ -110,6 +131,16 @@ constructor(
}
}

private fun initQRScanner() {
if (syncFeature.qrCodeScannerHints().isEnabled()) {
if (appBuildConfig.isInternalBuild()) {
beepManager = BeepManager(getActivity())
Comment on lines +135 to +137
Copy link
Member

Choose a reason for hiding this comment

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

want to switch the order of these two if statements?

appBuildConfig.isInternalBuild() is cheaper than syncFeature.qrCodeScannerHints().isEnabled() so would be good to check that first

also, can you get syncFeature.qrCodeScannerHints().isEnabled() off of the main thread?

}
binding.barcodeView.cameraSettings = cameraSettings
binding.barcodeView.decoderFactory = DefaultDecoderFactory(listOf(QR_CODE))
}
}

override fun onDetachedFromWindow() {
conflatedStateJob.cancel()
conflatedCommandJob.cancel()
Expand All @@ -135,6 +166,7 @@ constructor(

fun decodeSingle(onQrCodeRead: (String) -> Unit) {
binding.barcodeView.decodeSingle {
beepManager?.playBeepSoundAndVibrate()
onQrCodeRead(it.text)
}
}
Expand Down
Loading