fixing the top Menu at search activity

This commit is contained in:
tibbi 2022-08-01 12:38:12 +02:00
parent 2f36bb3866
commit 20c93697c9
2 changed files with 81 additions and 55 deletions

View file

@ -13,6 +13,7 @@ import androidx.core.view.MenuItemCompat
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.NavigationIcon
import com.simplemobiletools.commons.helpers.VIEW_TYPE_GRID import com.simplemobiletools.commons.helpers.VIEW_TYPE_GRID
import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.commons.models.FileDirItem
@ -42,9 +43,15 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_search) setContentView(R.layout.activity_search)
media_empty_text_placeholder.setTextColor(getProperTextColor()) setupOptionsMenu()
search_empty_text_placeholder.setTextColor(getProperTextColor())
getAllMedia() getAllMedia()
media_fastscroller.updateColors(getProperPrimaryColor()) search_fastscroller.updateColors(getProperPrimaryColor())
}
override fun onResume() {
super.onResume()
setupToolbar(search_toolbar, NavigationIcon.Arrow, searchMenuItem = mSearchMenuItem)
} }
override fun onDestroy() { override fun onDestroy() {
@ -52,19 +59,15 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
mCurrAsyncTask?.stopFetching() mCurrAsyncTask?.stopFetching()
} }
override fun onCreateOptionsMenu(menu: Menu): Boolean { private fun setupOptionsMenu() {
menuInflater.inflate(R.menu.menu_search, menu) setupSearch(search_toolbar.menu)
setupSearch(menu) search_toolbar.setOnMenuItemClickListener { menuItem ->
updateMenuItemColors(menu) when (menuItem.itemId) {
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.toggle_filename -> toggleFilenameVisibility() R.id.toggle_filename -> toggleFilenameVisibility()
else -> return super.onOptionsItemSelected(item) else -> return@setOnMenuItemClickListener false
}
return@setOnMenuItemClickListener true
} }
return true
} }
private fun setupSearch(menu: Menu) { private fun setupSearch(menu: Menu) {
@ -112,10 +115,10 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
val grouped = MediaFetcher(applicationContext).groupMedia(filtered as ArrayList<Medium>, "") val grouped = MediaFetcher(applicationContext).groupMedia(filtered as ArrayList<Medium>, "")
runOnUiThread { runOnUiThread {
if (grouped.isEmpty()) { if (grouped.isEmpty()) {
media_empty_text_placeholder.text = getString(R.string.no_items_found) search_empty_text_placeholder.text = getString(R.string.no_items_found)
media_empty_text_placeholder.beVisible() search_empty_text_placeholder.beVisible()
} else { } else {
media_empty_text_placeholder.beGone() search_empty_text_placeholder.beGone()
} }
handleGridSpacing(grouped) handleGridSpacing(grouped)
@ -127,14 +130,14 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
} }
private fun setupAdapter() { private fun setupAdapter() {
val currAdapter = media_grid.adapter val currAdapter = search_grid.adapter
if (currAdapter == null) { if (currAdapter == null) {
MediaAdapter(this, ArrayList(), this, false, false, "", media_grid) { MediaAdapter(this, ArrayList(), this, false, false, "", search_grid) {
if (it is Medium) { if (it is Medium) {
itemClicked(it.path) itemClicked(it.path)
} }
}.apply { }.apply {
media_grid.adapter = this search_grid.adapter = this
} }
setupLayoutManager() setupLayoutManager()
handleGridSpacing(mAllMedia) handleGridSpacing(mAllMedia)
@ -151,18 +154,18 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
private fun handleGridSpacing(media: ArrayList<ThumbnailItem>) { private fun handleGridSpacing(media: ArrayList<ThumbnailItem>) {
val viewType = config.getFolderViewType(SHOW_ALL) val viewType = config.getFolderViewType(SHOW_ALL)
if (viewType == VIEW_TYPE_GRID) { if (viewType == VIEW_TYPE_GRID) {
if (media_grid.itemDecorationCount > 0) { if (search_grid.itemDecorationCount > 0) {
media_grid.removeItemDecorationAt(0) search_grid.removeItemDecorationAt(0)
} }
val spanCount = config.mediaColumnCnt val spanCount = config.mediaColumnCnt
val spacing = config.thumbnailSpacing val spacing = config.thumbnailSpacing
val decoration = GridSpacingItemDecoration(spanCount, spacing, config.scrollHorizontally, config.fileRoundedCorners, media, true) val decoration = GridSpacingItemDecoration(spanCount, spacing, config.scrollHorizontally, config.fileRoundedCorners, media, true)
media_grid.addItemDecoration(decoration) search_grid.addItemDecoration(decoration)
} }
} }
private fun getMediaAdapter() = media_grid.adapter as? MediaAdapter private fun getMediaAdapter() = search_grid.adapter as? MediaAdapter
private fun toggleFilenameVisibility() { private fun toggleFilenameVisibility() {
config.displayFileNames = !config.displayFileNames config.displayFileNames = !config.displayFileNames
@ -192,13 +195,13 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
} }
private fun setupGridLayoutManager() { private fun setupGridLayoutManager() {
val layoutManager = media_grid.layoutManager as MyGridLayoutManager val layoutManager = search_grid.layoutManager as MyGridLayoutManager
if (config.scrollHorizontally) { if (config.scrollHorizontally) {
layoutManager.orientation = RecyclerView.HORIZONTAL layoutManager.orientation = RecyclerView.HORIZONTAL
media_grid.layoutParams = RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT) search_grid.layoutParams = RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)
} else { } else {
layoutManager.orientation = RecyclerView.VERTICAL layoutManager.orientation = RecyclerView.VERTICAL
media_grid.layoutParams = RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) search_grid.layoutParams = RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
} }
layoutManager.spanCount = config.mediaColumnCnt layoutManager.spanCount = config.mediaColumnCnt
@ -215,7 +218,7 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
} }
private fun setupListLayoutManager() { private fun setupListLayoutManager() {
val layoutManager = media_grid.layoutManager as MyGridLayoutManager val layoutManager = search_grid.layoutManager as MyGridLayoutManager
layoutManager.spanCount = 1 layoutManager.spanCount = 1
layoutManager.orientation = RecyclerView.VERTICAL layoutManager.orientation = RecyclerView.VERTICAL
} }
@ -223,7 +226,7 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
private fun setupScrollDirection() { private fun setupScrollDirection() {
val viewType = config.getFolderViewType(SHOW_ALL) val viewType = config.getFolderViewType(SHOW_ALL)
val scrollHorizontally = config.scrollHorizontally && viewType == VIEW_TYPE_GRID val scrollHorizontally = config.scrollHorizontally && viewType == VIEW_TYPE_GRID
media_fastscroller.setScrollVertically(!scrollHorizontally) search_fastscroller.setScrollVertically(!scrollHorizontally)
} }
private fun getAllMedia() { private fun getAllMedia() {

View file

@ -1,12 +1,34 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/media_holder" android:id="@+id/search_coordinator"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/search_app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/search_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/color_primary"
app:menu="@menu/menu_search"
app:title="@string/search"
app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" />
</com.google.android.material.appbar.AppBarLayout>
<RelativeLayout
android:id="@+id/search_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/media_empty_text_placeholder" android:id="@+id/search_empty_text_placeholder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:alpha="0.8" android:alpha="0.8"
@ -20,12 +42,12 @@
android:visibility="gone" /> android:visibility="gone" />
<com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller <com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
android:id="@+id/media_fastscroller" android:id="@+id/search_fastscroller"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<com.simplemobiletools.commons.views.MyRecyclerView <com.simplemobiletools.commons.views.MyRecyclerView
android:id="@+id/media_grid" android:id="@+id/search_grid"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:scrollbars="none" android:scrollbars="none"
@ -34,3 +56,4 @@
</com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller> </com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller>
</RelativeLayout> </RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>