mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2025-01-17 22:08:00 +01:00
fixing the top Menu at search activity
This commit is contained in:
parent
2f36bb3866
commit
20c93697c9
2 changed files with 81 additions and 55 deletions
|
@ -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
|
R.id.toggle_filename -> toggleFilenameVisibility()
|
||||||
}
|
else -> return@setOnMenuItemClickListener false
|
||||||
|
}
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
return@setOnMenuItemClickListener true
|
||||||
when (item.itemId) {
|
|
||||||
R.id.toggle_filename -> toggleFilenameVisibility()
|
|
||||||
else -> return super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
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() {
|
||||||
|
|
|
@ -1,36 +1,59 @@
|
||||||
<?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.simplemobiletools.commons.views.MyTextView
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:id="@+id/media_empty_text_placeholder"
|
android:id="@+id/search_app_bar_layout"
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:alpha="0.8"
|
|
||||||
android:gravity="center_horizontal"
|
|
||||||
android:paddingStart="@dimen/activity_margin"
|
|
||||||
android:paddingTop="@dimen/activity_margin"
|
|
||||||
android:paddingEnd="@dimen/activity_margin"
|
|
||||||
android:text="@string/no_media_with_filters"
|
|
||||||
android:textSize="@dimen/bigger_text_size"
|
|
||||||
android:textStyle="italic"
|
|
||||||
android:visibility="gone" />
|
|
||||||
|
|
||||||
<com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
|
|
||||||
android:id="@+id/media_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.google.android.material.appbar.MaterialToolbar
|
||||||
android:id="@+id/media_grid"
|
android:id="@+id/search_toolbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="?attr/actionBarSize"
|
||||||
android:scrollbars="none"
|
android:background="@color/color_primary"
|
||||||
app:layoutManager="com.simplemobiletools.commons.views.MyGridLayoutManager"
|
app:menu="@menu/menu_search"
|
||||||
app:spanCount="@integer/media_columns_vertical_scroll" />
|
app:title="@string/search"
|
||||||
|
app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" />
|
||||||
|
|
||||||
</com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
</RelativeLayout>
|
|
||||||
|
<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
|
||||||
|
android:id="@+id/search_empty_text_placeholder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:alpha="0.8"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:paddingStart="@dimen/activity_margin"
|
||||||
|
android:paddingTop="@dimen/activity_margin"
|
||||||
|
android:paddingEnd="@dimen/activity_margin"
|
||||||
|
android:text="@string/no_media_with_filters"
|
||||||
|
android:textSize="@dimen/bigger_text_size"
|
||||||
|
android:textStyle="italic"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
|
||||||
|
android:id="@+id/search_fastscroller"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
|
android:id="@+id/search_grid"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:scrollbars="none"
|
||||||
|
app:layoutManager="com.simplemobiletools.commons.views.MyGridLayoutManager"
|
||||||
|
app:spanCount="@integer/media_columns_vertical_scroll" />
|
||||||
|
|
||||||
|
</com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller>
|
||||||
|
</RelativeLayout>
|
||||||
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
|
|
Loading…
Reference in a new issue