Skip to content

Commit

Permalink
Merge pull request #11778 from nextcloud/fix/search-actionbar
Browse files Browse the repository at this point in the history
Hide actionbar title when search input field is opened
  • Loading branch information
AndyScherzinger authored Jul 25, 2023
2 parents f6632ae + e71bcb7 commit 5497775
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,17 @@ private void showHomeSearchToolbar(boolean isShow) {
* Updates title bar and home buttons (state and icon).
*/
public void updateActionBarTitleAndHomeButtonByString(String title) {
String titleToSet = getString(R.string.app_name); // default

if (title != null) {
titleToSet = title;
}

// set & color the chosen title
ActionBar actionBar = getSupportActionBar();

// set home button properties
if (actionBar != null) {
actionBar.setTitle(titleToSet);
actionBar.setDisplayShowTitleEnabled(true);
if (title != null) {
actionBar.setTitle(title);
actionBar.setDisplayShowTitleEnabled(true);
} else {
actionBar.setDisplayShowTitleEnabled(false);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import android.view.Menu
import android.view.MenuInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.annotation.VisibleForTesting
import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuItemCompat
Expand Down Expand Up @@ -65,6 +66,7 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface
private lateinit var adapter: UnifiedSearchListAdapter
private var _binding: ListFragmentBinding? = null
private val binding get() = _binding!!
private var searchView: SearchView? = null
lateinit var vm: IUnifiedSearchViewModel

@Inject
Expand Down Expand Up @@ -137,7 +139,7 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface
vm.query.observe(this) { query ->
if (activity is FileDisplayActivity) {
(activity as FileDisplayActivity)
.updateActionBarTitleAndHomeButtonByString("\"${query}\"")
.updateActionBarTitleAndHomeButtonByString(null)
}
}
vm.browserUri.observe(this) { uri ->
Expand Down Expand Up @@ -169,7 +171,7 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface
if (activity is FileDisplayActivity) {
val fileDisplayActivity = activity as FileDisplayActivity
fileDisplayActivity.setMainFabVisible(false)
fileDisplayActivity.updateActionBarTitleAndHomeButtonByString("\"${vm.query.value!!}\"")
fileDisplayActivity.updateActionBarTitleAndHomeButtonByString(null)
}

val gridLayoutManager = GridLayoutManager(requireContext(), 1)
Expand Down Expand Up @@ -224,14 +226,15 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface
setUpViewModel()
}

@Deprecated("Deprecated in Java")
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
val item = menu.findItem(R.id.action_search)
val searchView = MenuItemCompat.getActionView(item) as SearchView
viewThemeUtils.androidx.themeToolbarSearchView(searchView)
searchView.setQuery(vm.query.value, false)
searchView.setOnQueryTextListener(this)
searchView.isIconified = false
searchView.clearFocus()
searchView = MenuItemCompat.getActionView(item) as SearchView
viewThemeUtils.androidx.themeToolbarSearchView(searchView!!)
searchView?.setQuery(vm.query.value, false)
searchView?.setOnQueryTextListener(this)
searchView?.isIconified = false
searchView?.clearFocus()
}

companion object {
Expand All @@ -257,7 +260,12 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface
}

override fun onQueryTextChange(newText: String?): Boolean {
// noop
val closeButton = searchView?.findViewById<ImageView>(androidx.appcompat.R.id.search_close_btn)
if (newText?.isEmpty() == true) {
closeButton?.visibility = View.INVISIBLE
} else {
closeButton?.visibility = View.VISIBLE
}
return true
}
}

0 comments on commit 5497775

Please sign in to comment.