For #9728: Add actionbar search for language list.
parent
80f74ac611
commit
4006501d41
|
@ -6,8 +6,12 @@ package org.mozilla.fenix.settings.advanced
|
|||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.fragment.app.Fragment
|
||||
import kotlinx.android.synthetic.main.fragment_locale_settings.view.*
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
|
@ -24,6 +28,11 @@ class LocaleSettingsFragment : Fragment() {
|
|||
private lateinit var interactor: LocaleSettingsInteractor
|
||||
private lateinit var localeView: LocaleSettingsView
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setHasOptionsMenu(true)
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
|
@ -42,6 +51,25 @@ class LocaleSettingsFragment : Fragment() {
|
|||
return view
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
inflater.inflate(R.menu.languages_list, menu)
|
||||
val searchItem = menu.findItem(R.id.search)
|
||||
val searchView: SearchView = searchItem.actionView as SearchView
|
||||
searchView.imeOptions = EditorInfo.IME_ACTION_DONE
|
||||
searchView.queryHint = getString(R.string.locale_search_hint)
|
||||
|
||||
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||
override fun onQueryTextSubmit(query: String): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onQueryTextChange(newText: String): Boolean {
|
||||
interactor.onSearchQueryTyped(newText)
|
||||
return false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
localeView.onResume()
|
||||
|
|
|
@ -7,7 +7,6 @@ package org.mozilla.fenix.settings.advanced
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.SearchView
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import kotlinx.android.synthetic.main.component_locale_settings.view.*
|
||||
import org.mozilla.fenix.R
|
||||
|
@ -38,17 +37,6 @@ class LocaleSettingsView(
|
|||
adapter = localeAdapter
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
}
|
||||
val searchView: SearchView = view.toolbar_container
|
||||
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||
override fun onQueryTextSubmit(query: String): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onQueryTextChange(newText: String): Boolean {
|
||||
interactor.onSearchQueryTyped(newText)
|
||||
return false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun update(state: LocaleSettingsState) {
|
||||
|
|
|
@ -6,23 +6,6 @@
|
|||
android:focusable="true"
|
||||
android:focusableInTouchMode="true">
|
||||
|
||||
<SearchView
|
||||
android:id="@+id/toolbar_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/locale_search_bar_margin"
|
||||
android:background="@drawable/search_url_background"
|
||||
android:closeIcon="@drawable/ic_close"
|
||||
android:iconifiedByDefault="false"
|
||||
android:paddingStart="@dimen/locale_search_bar_padding_start"
|
||||
android:paddingEnd="0dp"
|
||||
android:queryBackground="@android:color/transparent"
|
||||
android:queryHint="@string/locale_search_hint"
|
||||
android:searchIcon="@drawable/ic_search"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/locale_list"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -31,6 +14,6 @@
|
|||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/toolbar_container" />
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!-- 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/. -->
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/search"
|
||||
android:icon="@drawable/ic_search"
|
||||
android:title="@string/locale_search_hint"
|
||||
app:iconTint="?primaryText"
|
||||
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
||||
android:contentDescription="@string/locale_search_hint"
|
||||
app:showAsAction="ifRoom|collapseActionView" />
|
||||
</menu>
|
Loading…
Reference in New Issue