Skip to content

Commit

Permalink
For mozilla-mobile#26329 Implement the search widget Fenix part
Browse files Browse the repository at this point in the history
  • Loading branch information
iorgamgabriel committed Aug 8, 2022
1 parent 1a2b357 commit 1ecfe6d
Show file tree
Hide file tree
Showing 21 changed files with 79 additions and 835 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
android:name=".crashes.CrashListActivity"
android:exported="false" />

<activity android:name=".widget.VoiceSearchActivity"
<activity android:name=".widget.FenixVoiceSearchActivity"
android:theme="@style/Theme.AppCompat.Translucent"
android:taskAffinity=""
android:excludeFromRecents="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import mozilla.components.browser.state.search.SearchEngine
import mozilla.components.browser.state.state.selectedOrDefaultSearchEngine
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.feature.search.ext.waitForSelectedOrDefaultSearchEngine
import mozilla.components.feature.search.widget.VoiceSearchActivity.Companion.SPEECH_PROCESSING
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.components.metrics.MetricsUtils
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.widget.VoiceSearchActivity.Companion.SPEECH_PROCESSING

/**
* The search widget has a microphone button to let users search with their voice.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider
Expand Down Expand Up @@ -88,7 +87,6 @@ import org.mozilla.fenix.search.toolbar.SearchSelectorMenu
import org.mozilla.fenix.search.toolbar.SearchSelectorToolbarAction
import org.mozilla.fenix.search.toolbar.ToolbarView
import org.mozilla.fenix.settings.SupportUtils
import org.mozilla.fenix.widget.VoiceSearchActivity

typealias SearchDialogFragmentStore = SearchFragmentStore

Expand Down Expand Up @@ -549,7 +547,7 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
}

override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
if (requestCode == VoiceSearchActivity.SPEECH_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
if (requestCode == SPEECH_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
intent?.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)?.first()?.also {
toolbarView.view.edit.updateUrl(url = it, shouldHighlight = true)
interactor.onTextChanged(it)
Expand Down Expand Up @@ -790,7 +788,7 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
putExtra(RecognizerIntent.EXTRA_PROMPT, requireContext().getString(R.string.voice_search_explainer))
}
startActivityForResult(speechIntent, VoiceSearchActivity.SPEECH_REQUEST_CODE)
startActivityForResult(speechIntent, SPEECH_REQUEST_CODE)
}

private fun updateQrButton(searchFragmentState: SearchFragmentState) {
Expand Down Expand Up @@ -904,6 +902,7 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {

companion object {
private const val TAP_INCREASE_DPS = 8
const val SPEECH_REQUEST_CODE = 0
private const val QR_FRAGMENT_TAG = "MOZAC_QR_FRAGMENT"
private const val REQUEST_CODE_CAMERA_PERMISSIONS = 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import mozilla.components.support.utils.RunWhenReadyQueue
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.IntentReceiverActivity
import org.mozilla.fenix.settings.account.AuthIntentReceiverActivity
import org.mozilla.fenix.widget.VoiceSearchActivity
import org.mozilla.fenix.widget.FenixVoiceSearchActivity

/**
* These callbacks handle binding performance code to the activity lifecycle.
Expand All @@ -35,7 +35,7 @@ class PerformanceActivityLifecycleCallbacks(
// to ensure these new activities would not crash the application.
return isTransientActivityInMigrationVariant(activity) ||
(activity is IntentReceiverActivity) ||
(activity is VoiceSearchActivity) ||
(activity is FenixVoiceSearchActivity) ||
(activity is AuthIntentReceiverActivity)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.preference.CheckBoxPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
import mozilla.components.feature.search.widget.AppSearchWidgetProvider
import mozilla.components.support.ktx.android.view.hideKeyboard
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.getPreferenceKey
Expand Down Expand Up @@ -90,7 +91,7 @@ class SearchEngineFragment : PreferenceFragmentCompat() {
requireContext().settings().preferences.edit {
putBoolean(preference.key, newBooleanValue)
}
SearchWidgetProvider.updateAllWidgets(requireContext())
AppSearchWidgetProvider.updateAllWidgets(requireContext(), SearchWidgetProvider())
return true
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.fenix.widget

import android.content.Intent
import android.os.StrictMode
import mozilla.components.feature.search.widget.VoiceSearchActivity
import mozilla.components.support.locale.LocaleManager
import mozilla.telemetry.glean.private.NoExtras
import org.mozilla.fenix.GleanMetrics.SearchWidget
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.IntentReceiverActivity
import org.mozilla.fenix.ext.components
import java.util.Locale

/**
* Implementation of voice search that is needed in search widget
*/
class FenixVoiceSearchActivity : VoiceSearchActivity() {

override fun getCurrentLocale(): Locale {
val locale = components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
LocaleManager.getCurrentLocale(this@FenixVoiceSearchActivity)
?: LocaleManager.getSystemDefault()
}
return locale
}

override fun recordVoiceButtonTelemetry() {
SearchWidget.voiceButton.record(NoExtras())
}

override fun startIntentAfterVoiceSearch(spokenText: String?) {
val intent = Intent(this, IntentReceiverActivity::class.java)
intent.putExtra(SPEECH_PROCESSING, spokenText)
intent.putExtra(HomeActivity.OPEN_TO_BROWSER_AND_LOAD, true)
startActivity(intent)
}
}
121 changes: 0 additions & 121 deletions app/src/main/java/org/mozilla/fenix/widget/VoiceSearchActivity.kt

This file was deleted.

Loading

0 comments on commit 1ecfe6d

Please sign in to comment.