use the new redesigned Search
This commit is contained in:
parent
16408f2c51
commit
36539e4bba
9 changed files with 29 additions and 100 deletions
|
@ -1,22 +1,16 @@
|
|||
package com.simplemobiletools.musicplayer.activities
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.SearchManager
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.media.AudioManager
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.core.view.MenuItemCompat
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
|
@ -53,8 +47,6 @@ import java.io.FileOutputStream
|
|||
class MainActivity : SimpleActivity() {
|
||||
private val PICK_IMPORT_SOURCE_INTENT = 1
|
||||
|
||||
private var isSearchOpen = false
|
||||
private var searchMenuItem: MenuItem? = null
|
||||
private var bus: EventBus? = null
|
||||
private var storedShowTabs = 0
|
||||
private var storedExcludedFolders = 0
|
||||
|
@ -66,7 +58,7 @@ class MainActivity : SimpleActivity() {
|
|||
appLaunched(BuildConfig.APPLICATION_ID)
|
||||
setupOptionsMenu()
|
||||
refreshMenuItems()
|
||||
updateMaterialActivityViews(main_coordinator, main_holder, useTransparentNavigation = false, useTopSearchMenu = false)
|
||||
updateMaterialActivityViews(main_coordinator, main_holder, useTransparentNavigation = false, useTopSearchMenu = true)
|
||||
storeStateVariables()
|
||||
setupTabs()
|
||||
|
||||
|
@ -93,19 +85,13 @@ class MainActivity : SimpleActivity() {
|
|||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
val statusBarColor = if (getCurrentFragment()?.getScrollingView() == null) {
|
||||
getProperBackgroundColor()
|
||||
} else {
|
||||
window.statusBarColor
|
||||
}
|
||||
|
||||
setupToolbar(main_toolbar, statusBarColor = statusBarColor, searchMenuItem = searchMenuItem)
|
||||
if (storedShowTabs != config.showTabs) {
|
||||
config.lastUsedViewPagerPage = 0
|
||||
System.exit(0)
|
||||
return
|
||||
}
|
||||
|
||||
updateMenuColors()
|
||||
updateTextColors(main_holder)
|
||||
setupTabColors()
|
||||
sleep_timer_holder.background = ColorDrawable(getProperBackgroundColor())
|
||||
|
@ -133,15 +119,15 @@ class MainActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (isSearchOpen && searchMenuItem != null) {
|
||||
searchMenuItem!!.collapseActionView()
|
||||
if (main_menu.isSearchOpen) {
|
||||
main_menu.closeSearch()
|
||||
} else {
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
|
||||
private fun refreshMenuItems() {
|
||||
main_toolbar.menu.apply {
|
||||
main_menu.getToolbar().menu.apply {
|
||||
findItem(R.id.create_new_playlist).isVisible = getCurrentFragment() == playlists_fragment_holder
|
||||
findItem(R.id.create_playlist_from_folder).isVisible = getCurrentFragment() == playlists_fragment_holder
|
||||
findItem(R.id.import_playlist).isVisible = getCurrentFragment() == playlists_fragment_holder && isOreoPlus()
|
||||
|
@ -150,8 +136,21 @@ class MainActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
private fun setupOptionsMenu() {
|
||||
setupSearch(main_toolbar.menu)
|
||||
main_toolbar.setOnMenuItemClickListener { menuItem ->
|
||||
main_menu.getToolbar().inflateMenu(R.menu.menu_main)
|
||||
main_menu.toggleHideOnScroll(false)
|
||||
main_menu.setupMenu()
|
||||
|
||||
main_menu.onSearchClosedListener = {
|
||||
getAllFragments().forEach {
|
||||
it?.onSearchClosed()
|
||||
}
|
||||
}
|
||||
|
||||
main_menu.onSearchTextChangedListener = { text ->
|
||||
getCurrentFragment()?.onSearchQueryChanged(text)
|
||||
}
|
||||
|
||||
main_menu.getToolbar().setOnMenuItemClickListener { menuItem ->
|
||||
when (menuItem.itemId) {
|
||||
R.id.sort -> showSortingDialog()
|
||||
R.id.sleep_timer -> showSleepTimer()
|
||||
|
@ -168,6 +167,11 @@ class MainActivity : SimpleActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun updateMenuColors() {
|
||||
updateStatusbarColor(getProperBackgroundColor())
|
||||
main_menu.updateColors()
|
||||
}
|
||||
|
||||
private fun storeStateVariables() {
|
||||
config.apply {
|
||||
storedShowTabs = showTabs
|
||||
|
@ -175,39 +179,6 @@ class MainActivity : SimpleActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun setupSearch(menu: Menu) {
|
||||
val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager
|
||||
searchMenuItem = menu.findItem(R.id.search)
|
||||
(searchMenuItem!!.actionView as SearchView).apply {
|
||||
setSearchableInfo(searchManager.getSearchableInfo(componentName))
|
||||
isSubmitButtonEnabled = false
|
||||
setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||
override fun onQueryTextSubmit(query: String) = false
|
||||
|
||||
override fun onQueryTextChange(newText: String): Boolean {
|
||||
if (isSearchOpen) {
|
||||
getCurrentFragment()?.onSearchQueryChanged(newText)
|
||||
}
|
||||
return true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
MenuItemCompat.setOnActionExpandListener(searchMenuItem, object : MenuItemCompat.OnActionExpandListener {
|
||||
override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
|
||||
getCurrentFragment()?.onSearchOpened()
|
||||
isSearchOpen = true
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
|
||||
getCurrentFragment()?.onSearchClosed()
|
||||
isSearchOpen = false
|
||||
return true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun initActivity() {
|
||||
bus = EventBus.getDefault()
|
||||
bus!!.register(this)
|
||||
|
@ -284,7 +255,7 @@ class MainActivity : SimpleActivity() {
|
|||
updateBottomTabItemColors(it.customView, false)
|
||||
},
|
||||
tabSelectedAction = {
|
||||
closeSearch()
|
||||
main_menu.closeSearch()
|
||||
view_pager.currentItem = it.position
|
||||
updateBottomTabItemColors(it.customView, true)
|
||||
}
|
||||
|
@ -580,23 +551,12 @@ class MainActivity : SimpleActivity() {
|
|||
refreshAllFragments()
|
||||
}
|
||||
|
||||
private fun closeSearch() {
|
||||
if (isSearchOpen) {
|
||||
getAllFragments().forEach {
|
||||
it?.onSearchClosed()
|
||||
}
|
||||
searchMenuItem?.collapseActionView()
|
||||
}
|
||||
}
|
||||
|
||||
private fun launchEqualizer() {
|
||||
closeSearch()
|
||||
hideKeyboard()
|
||||
startActivity(Intent(applicationContext, EqualizerActivity::class.java))
|
||||
}
|
||||
|
||||
private fun launchSettings() {
|
||||
closeSearch()
|
||||
hideKeyboard()
|
||||
startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
||||
}
|
||||
|
|
|
@ -79,10 +79,6 @@ class AlbumsFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
|
|||
albums_placeholder.beVisibleIf(filtered.isEmpty())
|
||||
}
|
||||
|
||||
override fun onSearchOpened() {
|
||||
albumsIgnoringSearch = (albums_list?.adapter as? AlbumsAdapter)?.albums ?: ArrayList()
|
||||
}
|
||||
|
||||
override fun onSearchClosed() {
|
||||
(albums_list.adapter as? AlbumsAdapter)?.updateItems(albumsIgnoringSearch)
|
||||
albums_placeholder.beGoneIf(albumsIgnoringSearch.isNotEmpty())
|
||||
|
|
|
@ -79,10 +79,6 @@ class ArtistsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
|
|||
artists_placeholder.beVisibleIf(filtered.isEmpty())
|
||||
}
|
||||
|
||||
override fun onSearchOpened() {
|
||||
artistsIgnoringSearch = (artists_list?.adapter as? ArtistsAdapter)?.artists ?: ArrayList()
|
||||
}
|
||||
|
||||
override fun onSearchClosed() {
|
||||
(artists_list.adapter as? ArtistsAdapter)?.updateItems(artistsIgnoringSearch)
|
||||
artists_placeholder.beGoneIf(artistsIgnoringSearch.isNotEmpty())
|
||||
|
|
|
@ -113,10 +113,6 @@ class FoldersFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
|
|||
folders_placeholder.beVisibleIf(filtered.isEmpty())
|
||||
}
|
||||
|
||||
override fun onSearchOpened() {
|
||||
foldersIgnoringSearch = (folders_list?.adapter as? FoldersAdapter)?.folders ?: ArrayList()
|
||||
}
|
||||
|
||||
override fun onSearchClosed() {
|
||||
(folders_list.adapter as? FoldersAdapter)?.updateItems(foldersIgnoringSearch)
|
||||
folders_placeholder.beGoneIf(foldersIgnoringSearch.isNotEmpty())
|
||||
|
|
|
@ -13,8 +13,6 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||
|
||||
abstract fun onSearchQueryChanged(text: String)
|
||||
|
||||
abstract fun onSearchOpened()
|
||||
|
||||
abstract fun onSearchClosed()
|
||||
|
||||
abstract fun onSortOpen(activity: SimpleActivity)
|
||||
|
|
|
@ -82,10 +82,6 @@ class PlaylistsFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
|
|||
playlists_placeholder_2.beVisibleIf(filtered.isEmpty())
|
||||
}
|
||||
|
||||
override fun onSearchOpened() {
|
||||
playlistsIgnoringSearch = (playlists_list?.adapter as? PlaylistsAdapter)?.playlists ?: ArrayList()
|
||||
}
|
||||
|
||||
override fun onSearchClosed() {
|
||||
(playlists_list.adapter as? PlaylistsAdapter)?.updateItems(playlistsIgnoringSearch)
|
||||
playlists_placeholder.beGoneIf(playlistsIgnoringSearch.isNotEmpty())
|
||||
|
|
|
@ -93,10 +93,6 @@ class TracksFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
|
|||
tracks_placeholder.beVisibleIf(filtered.isEmpty())
|
||||
}
|
||||
|
||||
override fun onSearchOpened() {
|
||||
tracksIgnoringSearch = (tracks_list?.adapter as? TracksAdapter)?.tracks ?: ArrayList()
|
||||
}
|
||||
|
||||
override fun onSearchClosed() {
|
||||
(tracks_list.adapter as? TracksAdapter)?.updateItems(tracksIgnoringSearch)
|
||||
tracks_placeholder.beGoneIf(tracksIgnoringSearch.isNotEmpty())
|
||||
|
|
|
@ -6,13 +6,10 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
android:id="@+id/main_toolbar"
|
||||
<com.simplemobiletools.commons.views.MySearchMenu
|
||||
android:id="@+id/main_menu"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="@color/color_primary"
|
||||
app:menu="@menu/menu_main"
|
||||
app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" />
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/main_nested_scrollview"
|
||||
|
|
|
@ -3,12 +3,6 @@
|
|||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:ignore="AppCompatResource">
|
||||
<item
|
||||
android:id="@+id/search"
|
||||
android:icon="@drawable/ic_search_vector"
|
||||
android:title="@string/search"
|
||||
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
||||
app:showAsAction="collapseActionView|always" />
|
||||
<item
|
||||
android:id="@+id/sort"
|
||||
android:icon="@drawable/ic_sort_vector"
|
||||
|
|
Loading…
Reference in a new issue