For #13473 - Addresses nits
parent
18d829750c
commit
61cb052156
|
@ -20,14 +20,13 @@ import androidx.constraintlayout.widget.ConstraintProperties.TOP
|
|||
import androidx.constraintlayout.widget.ConstraintSet
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.navigation.fragment.navArgs
|
||||
import kotlinx.android.synthetic.main.fragment_search.*
|
||||
import kotlinx.android.synthetic.main.fragment_search_dialog.*
|
||||
import kotlinx.android.synthetic.main.fragment_search_dialog.pill_wrapper
|
||||
import kotlinx.android.synthetic.main.fragment_search_dialog.search_scan_button
|
||||
import kotlinx.android.synthetic.main.fragment_search_dialog.qr_scan_button
|
||||
import kotlinx.android.synthetic.main.fragment_search_dialog.toolbar
|
||||
import kotlinx.android.synthetic.main.fragment_search_dialog.view.*
|
||||
import kotlinx.android.synthetic.main.fragment_search_dialog.view.search_engines_shortcut_button
|
||||
import kotlinx.android.synthetic.main.fragment_search_dialog.view.search_scan_button
|
||||
import kotlinx.android.synthetic.main.fragment_search_dialog.view.qr_scan_button
|
||||
import kotlinx.android.synthetic.main.fragment_search_dialog.view.toolbar
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import mozilla.components.feature.qr.QrFeature
|
||||
|
@ -142,9 +141,9 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
|
|||
interactor.onSearchShortcutsButtonClicked()
|
||||
}
|
||||
|
||||
search_scan_button.visibility = if (context?.hasCamera() == true) View.VISIBLE else View.GONE
|
||||
qr_scan_button.visibility = if (context?.hasCamera() == true) View.VISIBLE else View.GONE
|
||||
|
||||
search_scan_button.setOnClickListener {
|
||||
qr_scan_button.setOnClickListener {
|
||||
if (!requireContext().hasCamera()) { return@setOnClickListener }
|
||||
|
||||
toolbarView.view.clearFocus()
|
||||
|
@ -153,14 +152,49 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
|
|||
}
|
||||
|
||||
qrFeature.set(
|
||||
QrFeature(
|
||||
createQrFeature(),
|
||||
owner = this,
|
||||
view = view
|
||||
)
|
||||
|
||||
consumeFrom(store) {
|
||||
val shouldShowAwesomebar =
|
||||
!firstUpdate &&
|
||||
it.query.isNotBlank() ||
|
||||
it.showSearchShortcuts
|
||||
|
||||
awesome_bar?.visibility = if (shouldShowAwesomebar) View.VISIBLE else View.INVISIBLE
|
||||
toolbarView.update(it)
|
||||
awesomeBarView.update(it)
|
||||
firstUpdate = false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBackPressed(): Boolean {
|
||||
return when {
|
||||
qrFeature.onBackPressed() -> {
|
||||
toolbarView.view.edit.focus()
|
||||
view?.qr_scan_button?.isChecked = false
|
||||
toolbarView.view.requestFocus()
|
||||
true
|
||||
}
|
||||
else -> {
|
||||
view?.hideKeyboard()
|
||||
dismissAllowingStateLoss()
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun createQrFeature(): QrFeature {
|
||||
return QrFeature(
|
||||
requireContext(),
|
||||
fragmentManager = childFragmentManager,
|
||||
onNeedToRequestPermissions = { permissions ->
|
||||
requestPermissions(permissions, REQUEST_CODE_CAMERA_PERMISSIONS)
|
||||
},
|
||||
onScanResult = { result ->
|
||||
search_scan_button.isChecked = false
|
||||
qr_scan_button.isChecked = false
|
||||
activity?.let {
|
||||
AlertDialog.Builder(it).apply {
|
||||
val spannable = resources.getSpanned(
|
||||
|
@ -187,38 +221,7 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
|
|||
}.show()
|
||||
requireComponents.analytics.metrics.track(Event.QRScannerPromptDisplayed)
|
||||
}
|
||||
}),
|
||||
owner = this,
|
||||
view = view
|
||||
)
|
||||
|
||||
consumeFrom(store) {
|
||||
val shouldShowAwesomebar =
|
||||
!firstUpdate &&
|
||||
it.query.isNotBlank() ||
|
||||
it.showSearchShortcuts
|
||||
|
||||
awesome_bar?.visibility = if (shouldShowAwesomebar) View.VISIBLE else View.INVISIBLE
|
||||
toolbarView.update(it)
|
||||
awesomeBarView.update(it)
|
||||
firstUpdate = false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBackPressed(): Boolean {
|
||||
return when {
|
||||
qrFeature.onBackPressed() -> {
|
||||
toolbarView.view.edit.focus()
|
||||
view?.search_scan_button?.isChecked = false
|
||||
toolbarView.view.requestFocus()
|
||||
true
|
||||
}
|
||||
else -> {
|
||||
view?.hideKeyboard()
|
||||
dismissAllowingStateLoss()
|
||||
true
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun setupConstraints(view: View) {
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
app:layout_constraintStart_toStartOf="parent">
|
||||
|
||||
<ToggleButton
|
||||
android:id="@+id/search_scan_button"
|
||||
android:id="@+id/qr_scan_button"
|
||||
style="@style/search_pill"
|
||||
android:layout_marginEnd="@dimen/search_fragment_scan_button_margin_end"
|
||||
android:textOff="@string/search_scan_button"
|
||||
|
|
Loading…
Reference in New Issue