Commit 8c9058ca authored by Geoffrey Métais's avatar Geoffrey Métais

Fix keyboard not shown on search & code cleaning

Fix #875
parent 5df86c6b
Pipeline #7077 canceled with stage
in 7 minutes and 9 seconds
...@@ -27,7 +27,6 @@ import android.annotation.SuppressLint ...@@ -27,7 +27,6 @@ import android.annotation.SuppressLint
import android.app.SearchManager import android.app.SearchManager
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.text.TextUtils
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
...@@ -57,7 +56,7 @@ import org.videolan.vlc.util.Util ...@@ -57,7 +56,7 @@ import org.videolan.vlc.util.Util
@SuppressLint("Registered") @SuppressLint("Registered")
open class ContentActivity : AudioPlayerContainerActivity(), SearchView.OnQueryTextListener, MenuItem.OnActionExpandListener { open class ContentActivity : AudioPlayerContainerActivity(), SearchView.OnQueryTextListener, MenuItem.OnActionExpandListener {
private var mSearchView: SearchView? = null private lateinit var searchView: SearchView
private var showRenderers = !AndroidDevices.isChromeBook && !Util.isListEmpty(RendererDelegate.renderers.value) private var showRenderers = !AndroidDevices.isChromeBook && !Util.isListEmpty(RendererDelegate.renderers.value)
override fun initAudioPlayerContainerActivity() { override fun initAudioPlayerContainerActivity() {
...@@ -95,16 +94,16 @@ open class ContentActivity : AudioPlayerContainerActivity(), SearchView.OnQueryT ...@@ -95,16 +94,16 @@ open class ContentActivity : AudioPlayerContainerActivity(), SearchView.OnQueryT
if (current is Filterable) { if (current is Filterable) {
val filterable = current as Filterable? val filterable = current as Filterable?
val searchItem = menu.findItem(R.id.ml_menu_filter) val searchItem = menu.findItem(R.id.ml_menu_filter)
mSearchView = searchItem.actionView as SearchView searchView = searchItem.actionView as SearchView
mSearchView!!.queryHint = getString(R.string.search_list_hint) searchView.queryHint = getString(R.string.search_list_hint)
mSearchView!!.setOnQueryTextListener(this) searchView.setOnQueryTextListener(this)
val query = filterable!!.getFilterQuery() val query = filterable?.getFilterQuery()
if (!TextUtils.isEmpty(query)) { if (!query.isNullOrEmpty()) {
activityHandler.post { activityHandler.post {
searchItem.expandActionView() searchItem.expandActionView()
mSearchView!!.clearFocus() searchView.clearFocus()
UiTools.setKeyboardVisibility(mSearchView, false) UiTools.setKeyboardVisibility(searchView, false)
mSearchView!!.setQuery(query, false) searchView.setQuery(query, false)
} }
} }
searchItem.setOnActionExpandListener(this) searchItem.setOnActionExpandListener(this)
...@@ -162,13 +161,11 @@ open class ContentActivity : AudioPlayerContainerActivity(), SearchView.OnQueryT ...@@ -162,13 +161,11 @@ open class ContentActivity : AudioPlayerContainerActivity(), SearchView.OnQueryT
return true return true
} }
override fun onQueryTextSubmit(query: String): Boolean { override fun onQueryTextSubmit(query: String) = false
return false
}
private fun openSearchActivity() { private fun openSearchActivity() {
startActivity(Intent(Intent.ACTION_SEARCH, null, this, SearchActivity::class.java) startActivity(Intent(Intent.ACTION_SEARCH, null, this, SearchActivity::class.java)
.putExtra(SearchManager.QUERY, mSearchView!!.query.toString())) .putExtra(SearchManager.QUERY, searchView.query.toString()))
} }
private fun setSearchVisibility(visible: Boolean) { private fun setSearchVisibility(visible: Boolean) {
...@@ -185,8 +182,7 @@ open class ContentActivity : AudioPlayerContainerActivity(), SearchView.OnQueryT ...@@ -185,8 +182,7 @@ open class ContentActivity : AudioPlayerContainerActivity(), SearchView.OnQueryT
val renderersItem = menu.findItem(R.id.ml_menu_renderers) val renderersItem = menu.findItem(R.id.ml_menu_renderers)
if (renderersItem != null) renderersItem.isVisible = !hide && showRenderers if (renderersItem != null) renderersItem.isVisible = !hide && showRenderers
if (current is MediaBrowserFragment<*>) { if (current is MediaBrowserFragment<*>) {
val sortItem = menu.findItem(R.id.ml_menu_sortby) menu.findItem(R.id.ml_menu_sortby)?.isVisible = !hide && current.viewModel.canSortByName()
if (sortItem != null) sortItem.isVisible = !hide && current.viewModel.canSortByName()
} }
if (current is VideoGridFragment || current is AudioBrowserFragment if (current is VideoGridFragment || current is AudioBrowserFragment
|| current is FoldersFragment) { || current is FoldersFragment) {
...@@ -200,17 +196,11 @@ open class ContentActivity : AudioPlayerContainerActivity(), SearchView.OnQueryT ...@@ -200,17 +196,11 @@ open class ContentActivity : AudioPlayerContainerActivity(), SearchView.OnQueryT
} }
fun closeSearchView() { fun closeSearchView() {
if (toolbar.menu != null) { toolbar.menu?.findItem(R.id.ml_menu_filter)?.collapseActionView()
val item = toolbar.menu.findItem(R.id.ml_menu_filter)
item?.collapseActionView()
}
} }
private fun restoreCurrentList() { private fun restoreCurrentList() {
val current = currentFragment (currentFragment as? Filterable)?.restoreList()
if (current is Filterable) {
(current as Filterable).restoreList()
}
} }
companion object { companion object {
......
...@@ -49,8 +49,6 @@ import org.videolan.vlc.gui.browser.BaseBrowserFragment ...@@ -49,8 +49,6 @@ import org.videolan.vlc.gui.browser.BaseBrowserFragment
import org.videolan.vlc.gui.browser.ExtensionBrowser import org.videolan.vlc.gui.browser.ExtensionBrowser
import org.videolan.vlc.gui.helpers.Navigator import org.videolan.vlc.gui.helpers.Navigator
import org.videolan.vlc.gui.helpers.UiTools import org.videolan.vlc.gui.helpers.UiTools
import org.videolan.vlc.gui.preferences.PreferencesActivity
import org.videolan.vlc.gui.preferences.PreferencesFragment
import org.videolan.vlc.gui.video.VideoGridFragment import org.videolan.vlc.gui.video.VideoGridFragment
import org.videolan.vlc.gui.view.HackyDrawerLayout import org.videolan.vlc.gui.view.HackyDrawerLayout
import org.videolan.vlc.interfaces.Filterable import org.videolan.vlc.interfaces.Filterable
...@@ -62,11 +60,11 @@ import org.videolan.vlc.util.* ...@@ -62,11 +60,11 @@ import org.videolan.vlc.util.*
@ObsoleteCoroutinesApi @ObsoleteCoroutinesApi
class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManagerActivity { class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManagerActivity {
private var mediaLibrary: Medialibrary? = null private lateinit var mediaLibrary: Medialibrary
private var extensionsManager: ExtensionsManager? = null private lateinit var extensionsManager: ExtensionsManager
private var drawerLayout: HackyDrawerLayout? = null private lateinit var drawerLayout: HackyDrawerLayout
private var navigationView: NavigationView? = null private lateinit var navigationView: NavigationView
private var drawerToggle: ActionBarDrawerToggle? = null private lateinit var drawerToggle: ActionBarDrawerToggle
lateinit var navigator: Navigator lateinit var navigator: Navigator
private set private set
...@@ -95,7 +93,7 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager ...@@ -95,7 +93,7 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager
* the info dialog. If (for any reason) the dialog is not shown, * the info dialog. If (for any reason) the dialog is not shown,
* open the menu after a short delay. * open the menu after a short delay.
*/ */
activityHandler.postDelayed({ drawerLayout!!.openDrawer(navigationView!!) }, 500) activityHandler.postDelayed({ drawerLayout.openDrawer(navigationView) }, 500)
} }
Permissions.checkReadStoragePermission(this@MainActivity, false) Permissions.checkReadStoragePermission(this@MainActivity, false)
} }
...@@ -104,24 +102,24 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager ...@@ -104,24 +102,24 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager
prepareActionBar() prepareActionBar()
drawerToggle = ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close) drawerToggle = ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close)
drawerLayout!!.addDrawerListener(drawerToggle!!) drawerLayout.addDrawerListener(drawerToggle)
drawerLayout!!.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START) drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START)
/* Reload the latest preferences */ /* Reload the latest preferences */
scanNeeded = savedInstanceState == null && settings.getBoolean("auto_rescan", true) scanNeeded = savedInstanceState == null && settings.getBoolean("auto_rescan", true)
extensionsManager = ExtensionsManager.getInstance() if (BuildConfig.DEBUG) extensionsManager = ExtensionsManager.getInstance()
mediaLibrary = VLCApplication.mlInstance mediaLibrary = VLCApplication.mlInstance
} }
private fun setupNavigationView() { private fun setupNavigationView() {
navigationView = findViewById(R.id.navigation) navigationView = findViewById(R.id.navigation)
navigationView!!.menu.findItem(R.id.nav_history).isVisible = settings.getBoolean(PLAYBACK_HISTORY, true) navigationView.menu.findItem(R.id.nav_history).isVisible = settings.getBoolean(PLAYBACK_HISTORY, true)
} }
override fun onPostCreate(savedInstanceState: Bundle?) { override fun onPostCreate(savedInstanceState: Bundle?) {
super.onPostCreate(savedInstanceState) super.onPostCreate(savedInstanceState)
// Sync the toggle state after onRestoreInstanceState has occurred. // Sync the toggle state after onRestoreInstanceState has occurred.
drawerToggle!!.syncState() drawerToggle.syncState()
} }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @TargetApi(Build.VERSION_CODES.HONEYCOMB)
...@@ -133,7 +131,7 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager ...@@ -133,7 +131,7 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
if (mediaLibrary!!.isInitiated) { if (mediaLibrary.isInitiated) {
/* Load media items from database and storage */ /* Load media items from database and storage */
if (scanNeeded && Permissions.canReadStorage(this)) this.reloadLibrary() if (scanNeeded && Permissions.canReadStorage(this)) this.reloadLibrary()
} }
...@@ -147,10 +145,10 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager ...@@ -147,10 +145,10 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager
override fun onStop() { override fun onStop() {
super.onStop() super.onStop()
navigationView!!.setNavigationItemSelectedListener(null) navigationView.setNavigationItemSelectedListener(null)
if (changingConfigurations == 0) { if (changingConfigurations == 0) {
/* Check for an ongoing scan that needs to be resumed during onResume */ /* Check for an ongoing scan that needs to be resumed during onResume */
scanNeeded = mediaLibrary!!.isWorking scanNeeded = mediaLibrary.isWorking
} }
if (isExtensionServiceBinded) { if (isExtensionServiceBinded) {
unbindService(extensionServiceConnection) unbindService(extensionServiceConnection)
...@@ -158,41 +156,41 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager ...@@ -158,41 +156,41 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager
} }
if (navigator.currentIdIsExtension()) if (navigator.currentIdIsExtension())
settings.edit() settings.edit()
.putString("current_extension_name", extensionsManager!!.getExtensions(application, false)[navigator.currentFragmentId].componentName().packageName) .putString("current_extension_name", extensionsManager.getExtensions(application, false)[navigator.currentFragmentId].componentName().packageName)
.apply() .apply()
} }
private fun updateNavMenu() { private fun updateNavMenu() {
navigationView!!.setNavigationItemSelectedListener(navigator) navigationView.setNavigationItemSelectedListener(navigator)
} }
private fun loadPlugins() { private fun loadPlugins() {
val plugins = extensionsManager!!.getExtensions(this, true) val plugins = extensionsManager.getExtensions(this, true)
if (plugins.isEmpty()) { if (plugins.isEmpty()) {
unbindService(extensionServiceConnection) unbindService(extensionServiceConnection)
extensionServiceConnection = null extensionServiceConnection = null
extensionManagerService!!.stopSelf() extensionManagerService!!.stopSelf()
return return
} }
val extensionGroup = navigationView!!.menu.findItem(R.id.extensions_group) val extensionGroup = navigationView.menu.findItem(R.id.extensions_group)
extensionGroup.subMenu.clear() extensionGroup.subMenu.clear()
for (id in plugins.indices) { for (id in plugins.indices) {
val extension = plugins[id] val extension = plugins[id]
val key = "extension_" + extension.componentName().packageName val key = "extension_" + extension.componentName().packageName
if (settings.contains(key)) { if (settings.contains(key)) {
extensionsManager!!.displayPlugin(this, id, extension, settings.getBoolean(key, false)) extensionsManager.displayPlugin(this, id, extension, settings.getBoolean(key, false))
} else { } else {
extensionsManager!!.showExtensionPermissionDialog(this, id, extension, key) extensionsManager.showExtensionPermissionDialog(this, id, extension, key)
} }
} }
if (extensionGroup.subMenu.size() == 0) extensionGroup.isVisible = false if (extensionGroup.subMenu.size() == 0) extensionGroup.isVisible = false
onPluginsLoaded() onPluginsLoaded()
navigationView!!.invalidate() navigationView.invalidate()
} }
private fun onPluginsLoaded() { private fun onPluginsLoaded() {
if (navigator.currentFragment == null && navigator.currentIdIsExtension()) if (navigator.currentFragment == null && navigator.currentIdIsExtension())
if (extensionsManager!!.previousExtensionIsEnabled(application)) if (extensionsManager.previousExtensionIsEnabled(application))
extensionManagerService!!.openExtension(navigator.currentFragmentId) extensionManagerService!!.openExtension(navigator.currentFragmentId)
else else
navigator.showFragment(R.id.nav_video) navigator.showFragment(R.id.nav_video)
...@@ -227,9 +225,10 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager ...@@ -227,9 +225,10 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager
navigator.reloadPreferences() navigator.reloadPreferences()
} }
@TargetApi(Build.VERSION_CODES.N)
override fun onBackPressed() { override fun onBackPressed() {
/* Close the menu first */ /* Close the menu first */
if (drawerLayout!!.isDrawerOpen(navigationView!!)) { if (drawerLayout.isDrawerOpen(navigationView)) {
closeDrawer() closeDrawer()
return return
} }
...@@ -255,7 +254,7 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager ...@@ -255,7 +254,7 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager
override fun displayExtensionItems(extensionId: Int, title: String, items: List<VLCExtensionItem>, showParams: Boolean, refresh: Boolean) { override fun displayExtensionItems(extensionId: Int, title: String, items: List<VLCExtensionItem>, showParams: Boolean, refresh: Boolean) {
navigator.displayExtensionItems(extensionId, title, items, showParams, refresh) navigator.displayExtensionItems(extensionId, title, items, showParams, refresh)
navigationView!!.menu.findItem(extensionId).isCheckable = true navigationView.menu.findItem(extensionId).isCheckable = true
updateCheckedItem(extensionId) updateCheckedItem(extensionId)
} }
...@@ -269,19 +268,19 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager ...@@ -269,19 +268,19 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager
*/ */
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
closeDrawer() closeDrawer()
UiTools.setKeyboardVisibility(drawerLayout, false) if (item.itemId != R.id.ml_menu_filter) UiTools.setKeyboardVisibility(drawerLayout, false)
// Handle item selection // Handle item selection
when (item.itemId) { return when (item.itemId) {
// Refresh // Refresh
R.id.ml_menu_refresh -> { R.id.ml_menu_refresh -> {
forceRefresh() forceRefresh()
return true true
} }
android.R.id.home -> android.R.id.home ->
// Slide down the audio player or toggle the sidebar // Slide down the audio player or toggle the sidebar
return slideDownAudioPlayer() || drawerToggle!!.onOptionsItemSelected(item) slideDownAudioPlayer() || drawerToggle.onOptionsItemSelected(item)
else -> return super.onOptionsItemSelected(item) else -> super.onOptionsItemSelected(item)
} }
} }
...@@ -296,7 +295,7 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager ...@@ -296,7 +295,7 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager
} }
private fun forceRefresh(current: Fragment?) { private fun forceRefresh(current: Fragment?) {
if (!mediaLibrary!!.isWorking) { if (!mediaLibrary.isWorking) {
if (current != null && current is IRefreshable) if (current != null && current is IRefreshable)
(current as IRefreshable).refresh() (current as IRefreshable).refresh()
else else
...@@ -358,7 +357,7 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager ...@@ -358,7 +357,7 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager
} }
fun closeDrawer() { fun closeDrawer() {
drawerLayout!!.closeDrawer(navigationView!!) drawerLayout.closeDrawer(navigationView)
} }
fun updateCheckedItem(id: Int) { fun updateCheckedItem(id: Int) {
...@@ -366,9 +365,9 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager ...@@ -366,9 +365,9 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager
R.id.nav_settings, R.id.nav_about -> return R.id.nav_settings, R.id.nav_about -> return
else -> { else -> {
val currentId = navigator.currentFragmentId val currentId = navigator.currentFragmentId
val target = navigationView!!.menu.findItem(id) val target = navigationView.menu.findItem(id)
if (id != currentId && target != null) { if (id != currentId && target != null) {
val current = navigationView!!.menu.findItem(currentId) val current = navigationView.menu.findItem(currentId)
if (current != null) current.isChecked = false if (current != null) current.isChecked = false
target.isChecked = true target.isChecked = true
/* Save the tab status in pref */ /* Save the tab status in pref */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment