Skip to content

Commit

Permalink
feat: remove scan modes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicola-95 committed Jan 24, 2023
1 parent 2731fd7 commit c48aba0
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import it.ministerodellasalute.verificaC19.BuildConfig
import it.ministerodellasalute.verificaC19.R
import it.ministerodellasalute.verificaC19.WhiteLabelApplication
import it.ministerodellasalute.verificaC19.databinding.ActivityFirstBinding
import it.ministerodellasalute.verificaC19.ui.ScanModeDialogFragment.Companion.DIALOG_TAG
import it.ministerodellasalute.verificaC19.ui.base.doOnDebug
import it.ministerodellasalute.verificaC19.ui.extensions.hide
import it.ministerodellasalute.verificaC19.ui.extensions.show
Expand Down Expand Up @@ -96,12 +97,14 @@ class FirstActivity : AppCompatActivity(), View.OnClickListener,
}

private fun disableUnusedScanModes() {
if (viewModel.getScanMode() == ScanMode.WORK || viewModel.getScanMode() == ScanMode.SCHOOL || viewModel.getScanMode() == ScanMode.ENTRY_ITALY) {
if (isUnusedScanMode()) {
viewModel.setScanModeFlag(false)
shared.edit().remove("scanMode").commit()
shared.edit().remove("scanMode").apply()
}
}

private fun isUnusedScanMode() = viewModel.getScanMode() != ScanMode.STANDARD

private fun observeLiveData() {
observeSyncStatus()
observeRetryCount()
Expand Down Expand Up @@ -256,8 +259,6 @@ class FirstActivity : AppCompatActivity(), View.OnClickListener,
val chosenScanMode =
when (currentScanMode) {
ScanMode.STANDARD -> getString(R.string.scan_mode_3G_header)
ScanMode.STRENGTHENED -> getString(R.string.scan_mode_2G_header)
ScanMode.BOOSTER -> getString(R.string.scan_mode_booster_header)
else -> getString(R.string.scan_mode_3G_header)
}
binding.scanModeButton.text = chosenScanMode
Expand Down Expand Up @@ -348,6 +349,7 @@ class FirstActivity : AppCompatActivity(), View.OnClickListener,
dialog.setCancelable(false)
dialog.show()
} catch (e: Exception) {
Log.i("createDownloadAlert", e.toString())
}
}

Expand Down Expand Up @@ -440,7 +442,10 @@ class FirstActivity : AppCompatActivity(), View.OnClickListener,
R.id.settings -> openSettingsActivity()
R.id.scan_mode_button -> {
viewModel.getRuleSet()?.run {
ScanModeDialogFragment(viewModel.getRuleSet()!!).show(supportFragmentManager, "SCAN_MODE_DIALOG_FRAGMENT")
ScanModeDialogFragment(viewModel.getRuleSet()!!).show(
supportFragmentManager,
DIALOG_TAG
)
} ?: run {
createNoSyncAlertDialog(getString(R.string.noKeyAlertMessage))
}
Expand All @@ -457,7 +462,12 @@ class FirstActivity : AppCompatActivity(), View.OnClickListener,
val builder = AlertDialog.Builder(this)
builder.setTitle(getString(R.string.noKeyAlertTitle))
val string =
SpannableString(Html.fromHtml(viewModel.getRuleSet()?.getErrorScanModePopup(), HtmlCompat.FROM_HTML_MODE_LEGACY)).also {
SpannableString(
Html.fromHtml(
viewModel.getRuleSet()?.getErrorScanModePopup(),
HtmlCompat.FROM_HTML_MODE_LEGACY
)
).also {
Linkify.addLinks(it, Linkify.ALL)
}
builder.setMessage(string)
Expand All @@ -472,7 +482,12 @@ class FirstActivity : AppCompatActivity(), View.OnClickListener,
private fun createScanModeInfoAlert() {
val builder = AlertDialog.Builder(this)
builder.setTitle(getString(R.string.label_scan_mode_types))
val string = SpannableString(Html.fromHtml(viewModel.getRuleSet()?.getInfoScanModePopup(), HtmlCompat.FROM_HTML_MODE_LEGACY)).also {
val string = SpannableString(
Html.fromHtml(
viewModel.getRuleSet()?.getInfoScanModePopup(),
HtmlCompat.FROM_HTML_MODE_LEGACY
)
).also {
Linkify.addLinks(it, Linkify.ALL)
}
builder.setMessage(string)
Expand Down Expand Up @@ -625,8 +640,8 @@ class FirstActivity : AppCompatActivity(), View.OnClickListener,
}

private fun updateDownloadedPackagesCount() {
val lastDownloadedChunk = viewModel.getCurrentChunk().toInt()
val lastChunk = viewModel.getTotalChunk().toInt()
val lastDownloadedChunk: Int = viewModel.getCurrentChunk().toInt()
val lastChunk: Int = viewModel.getTotalChunk().toInt()
val singleChunkSize = viewModel.getSizeSingleChunkInByte()

binding.updateProgressBar.progress = lastDownloadedChunk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ import it.ministerodellasalute.verificaC19sdk.model.ScanMode
import it.ministerodellasalute.verificaC19sdk.model.validation.RuleSet

@AndroidEntryPoint
class ScanModeDialogFragment(private val ruleSet: RuleSet) : DialogFragment(), ScanModeDialogCallback {
class ScanModeDialogFragment(private val ruleSet: RuleSet) : DialogFragment(),
ScanModeDialogCallback {

companion object {
const val DIALOG_TAG = "SCAN_MODE_DIALOG_FRAGMENT"
}

private val viewModel by viewModels<FirstViewModel>()
private lateinit var scanModeAdapter: ScanModeAdapter
Expand All @@ -51,10 +56,17 @@ class ScanModeDialogFragment(private val ruleSet: RuleSet) : DialogFragment(), S

override fun onStart() {
super.onStart()
dialog?.window?.setLayout(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT)
dialog?.window?.setLayout(
ActionBar.LayoutParams.MATCH_PARENT,
ActionBar.LayoutParams.MATCH_PARENT
)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {

val view = inflater.inflate(R.layout.fragment_scan_mode_dialog, container)
setScanModeList()
Expand Down Expand Up @@ -99,26 +111,17 @@ class ScanModeDialogFragment(private val ruleSet: RuleSet) : DialogFragment(), S
private fun setChosenScanMode() {
when (scanModeAdapter.mSelectedItem) {
0 -> viewModel.setScanMode(ScanMode.STANDARD)
1 -> viewModel.setScanMode(ScanMode.STRENGTHENED)
2 -> viewModel.setScanMode(ScanMode.BOOSTER)
}
}

private fun getChosenScanMode(): Int {
val chosenScanMode = when (viewModel.getScanMode()) {
ScanMode.STANDARD -> 0
ScanMode.STRENGTHENED -> 1
ScanMode.BOOSTER -> 2
else -> 0
}
return chosenScanMode
}
private fun getChosenScanMode(): Int = 0

private fun setScanModeList() {
scanModes = mutableListOf(
ScanModeChoice(getString(R.string.scan_mode_3G_header), ruleSet.getBaseScanModeDescription() ?: ""),
ScanModeChoice(getString(R.string.scan_mode_2G_header), ruleSet.getReinforcedScanModeDescription()),
ScanModeChoice(getString(R.string.scan_mode_booster_header), ruleSet.getBoosterScanModeDescription()),
ScanModeChoice(
getString(R.string.scan_mode_3G_header),
ruleSet.getBaseScanModeDescription() ?: ""
)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package it.ministerodellasalute.verificaC19.ui.main.codeReader

import android.content.pm.PackageManager
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -77,6 +78,7 @@ class CodeReaderFragment : Fragment(), NavController.OnDestinationChangedListene
try {
beepManager.playBeepSoundAndVibrate()
} catch (e: Exception) {
Log.i("barcodeResult", e.toString())
}

navigateToVerificationPage(result.text)
Expand All @@ -101,17 +103,16 @@ class CodeReaderFragment : Fragment(), NavController.OnDestinationChangedListene
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

val hintsMap: MutableMap<DecodeHintType, Any> = EnumMap(com.google.zxing.DecodeHintType::class.java)
val hintsMap: MutableMap<DecodeHintType, Any> =
EnumMap(com.google.zxing.DecodeHintType::class.java)
val formats: Collection<BarcodeFormat> = listOf(BarcodeFormat.QR_CODE, BarcodeFormat.AZTEC)
hintsMap[DecodeHintType.TRY_HARDER] = false
binding.barcodeScanner.barcodeView.decoderFactory = DefaultDecoderFactory(formats, hintsMap, null, 0)
binding.barcodeScanner.barcodeView.decoderFactory =
DefaultDecoderFactory(formats, hintsMap, null, 0)
binding.barcodeScanner.cameraSettings.isAutoFocusEnabled = true

val chosenScanMode = when (viewModel.getScanMode()) {
ScanMode.STANDARD -> getString(R.string.scan_mode_3G_header)
ScanMode.STRENGTHENED -> getString(R.string.scan_mode_2G_header)
ScanMode.BOOSTER -> getString(R.string.scan_mode_booster_header)
ScanMode.DOUBLE_SCAN -> getString(R.string.scan_mode_booster_header)
else -> getString(R.string.scan_mode_3G_header)
}
binding.scanModeText.text = chosenScanMode
Expand Down Expand Up @@ -146,11 +147,13 @@ class CodeReaderFragment : Fragment(), NavController.OnDestinationChangedListene

binding.flipCamera.setOnClickListener(this)

activity?.onBackPressedDispatcher?.addCallback(viewLifecycleOwner, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
callOnBack()
}
})
activity?.onBackPressedDispatcher?.addCallback(
viewLifecycleOwner,
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
callOnBack()
}
})
}

override fun onDestroyView() {
Expand Down Expand Up @@ -221,12 +224,7 @@ class CodeReaderFragment : Fragment(), NavController.OnDestinationChangedListene
}

private fun callOnBack() {
if (viewModel.getDoubleScanFlag()) {
viewModel.setDoubleScanFlag(false)
findNavController().popBackStack()
} else {
findNavController().navigate(R.id.action_codeReaderFragment_to_firstActivity)
}
findNavController().navigate(R.id.action_codeReaderFragment_to_firstActivity)
}

private fun hasFlash(): Boolean {
Expand Down
Loading

0 comments on commit c48aba0

Please sign in to comment.