Skip to content

Commit c436ba3

Browse files
Mugurellplingurar@mozilla.com
authored andcommitted
Bug 1981453 - Handle voice search button interactions in bookmarks and history also r=android-reviewers,harrisono
Differential Revision: https://phabricator.services.mozilla.com/D260246
1 parent 925e98b commit c436ba3

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

mobile/android/fenix/app/src/main/java/org/mozilla/fenix/bookmarks/BookmarkFragment.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44

55
package org.mozilla.fenix.bookmarks
66

7+
import android.content.Intent
78
import android.os.Bundle
89
import android.view.LayoutInflater
910
import android.view.View
1011
import android.view.ViewGroup
12+
import androidx.activity.result.ActivityResultLauncher
13+
import androidx.activity.result.contract.ActivityResultContracts
1114
import androidx.compose.ui.platform.ComposeView
1215
import androidx.compose.ui.platform.ViewCompositionStrategy
1316
import androidx.core.content.getSystemService
@@ -25,17 +28,20 @@ import mozilla.components.compose.browser.toolbar.store.EnvironmentCleared
2528
import mozilla.components.compose.browser.toolbar.store.EnvironmentRehydrated
2629
import mozilla.components.compose.browser.toolbar.store.Mode
2730
import mozilla.components.concept.engine.EngineSession
31+
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
2832
import org.mozilla.fenix.BrowserDirection
2933
import org.mozilla.fenix.HomeActivity
3034
import org.mozilla.fenix.NavGraphDirections
3135
import org.mozilla.fenix.R
3236
import org.mozilla.fenix.components.StoreProvider
37+
import org.mozilla.fenix.components.VoiceSearchFeature
3338
import org.mozilla.fenix.components.accounts.FenixFxAEntryPoint
3439
import org.mozilla.fenix.components.appstate.qrScanner.QrScannerBinding
3540
import org.mozilla.fenix.components.metrics.MetricsUtils
3641
import org.mozilla.fenix.components.search.BOOKMARKS_SEARCH_ENGINE_ID
3742
import org.mozilla.fenix.components.toolbar.BrowserToolbarEnvironment
3843
import org.mozilla.fenix.ext.bookmarkStorage
44+
import org.mozilla.fenix.ext.components
3945
import org.mozilla.fenix.ext.hideToolbar
4046
import org.mozilla.fenix.ext.nav
4147
import org.mozilla.fenix.ext.requireComponents
@@ -54,6 +60,7 @@ import org.mozilla.fenix.search.createInitialSearchFragmentState
5460
import org.mozilla.fenix.tabstray.Page
5561
import org.mozilla.fenix.theme.FirefoxTheme
5662
import org.mozilla.fenix.utils.lastSavedFolderCache
63+
import kotlin.getValue
5764

5865
/**
5966
* The screen that displays the user's bookmark list in their Library.
@@ -63,6 +70,14 @@ class BookmarkFragment : Fragment() {
6370

6471
private val verificationResultLauncher = registerForVerification()
6572

73+
private val voiceSearchFeature by lazy(LazyThreadSafetyMode.NONE) {
74+
ViewBoundFeatureWrapper<VoiceSearchFeature>()
75+
}
76+
private val voiceSearchLauncher: ActivityResultLauncher<Intent> =
77+
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
78+
voiceSearchFeature.get()?.handleVoiceSearchResult(result.resultCode, result.data)
79+
}
80+
6681
@Suppress("LongMethod")
6782
override fun onCreateView(
6883
inflater: LayoutInflater,
@@ -193,6 +208,15 @@ class BookmarkFragment : Fragment() {
193208
super.onViewCreated(view, savedInstanceState)
194209
if (requireContext().settings().shouldUseComposableToolbar) {
195210
QrScannerBinding.register(this)
211+
voiceSearchFeature.set(
212+
feature = VoiceSearchFeature(
213+
context = requireContext(),
214+
appStore = requireContext().components.appStore,
215+
voiceSearchLauncher = voiceSearchLauncher,
216+
),
217+
owner = viewLifecycleOwner,
218+
view = view,
219+
)
196220
}
197221
}
198222

mobile/android/fenix/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragment.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import android.view.View
1717
import android.view.ViewGroup
1818
import android.widget.RadioGroup
1919
import androidx.activity.result.ActivityResultLauncher
20+
import androidx.activity.result.contract.ActivityResultContracts
2021
import androidx.appcompat.app.AlertDialog
2122
import androidx.appcompat.app.AppCompatActivity
2223
import androidx.compose.foundation.background
@@ -92,6 +93,7 @@ import org.mozilla.fenix.R
9293
import org.mozilla.fenix.addons.showSnackBar
9394
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
9495
import org.mozilla.fenix.components.StoreProvider
96+
import org.mozilla.fenix.components.VoiceSearchFeature
9597
import org.mozilla.fenix.components.appstate.AppAction
9698
import org.mozilla.fenix.components.appstate.qrScanner.QrScannerBinding
9799
import org.mozilla.fenix.components.history.DefaultPagedHistoryProvider
@@ -126,6 +128,7 @@ import org.mozilla.fenix.search.SearchFragmentStore
126128
import org.mozilla.fenix.search.createInitialSearchFragmentState
127129
import org.mozilla.fenix.tabstray.Page
128130
import org.mozilla.fenix.theme.FirefoxTheme
131+
import kotlin.getValue
129132
import org.mozilla.fenix.GleanMetrics.History as GleanHistory
130133

131134
private const val MATERIAL_DESIGN_SCRIM = "#52000000"
@@ -161,6 +164,14 @@ class HistoryFragment : LibraryPageFragment<History>(), UserInteractionHandler,
161164
private var verificationResultLauncher: ActivityResultLauncher<Intent> =
162165
registerForVerification(onVerified = ::openHistoryInPrivate)
163166

167+
private val voiceSearchFeature by lazy(LazyThreadSafetyMode.NONE) {
168+
ViewBoundFeatureWrapper<VoiceSearchFeature>()
169+
}
170+
private val voiceSearchLauncher: ActivityResultLauncher<Intent> =
171+
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
172+
voiceSearchFeature.get()?.handleVoiceSearchResult(result.resultCode, result.data)
173+
}
174+
164175
private val menuBinding by lazy {
165176
MenuBinding(
166177
store = historyStore,
@@ -245,6 +256,15 @@ class HistoryFragment : LibraryPageFragment<History>(), UserInteractionHandler,
245256
if (requireContext().settings().shouldUseComposableToolbar) {
246257
toolbarStore = buildToolbarStore()
247258
QrScannerBinding.register(this)
259+
voiceSearchFeature.set(
260+
feature = VoiceSearchFeature(
261+
context = requireContext(),
262+
appStore = requireContext().components.appStore,
263+
voiceSearchLauncher = voiceSearchLauncher,
264+
),
265+
owner = viewLifecycleOwner,
266+
view = view,
267+
)
248268
}
249269

250270
consumeFrom(historyStore) {

0 commit comments

Comments
 (0)