restyling media activity

This commit is contained in:
tibbi 2022-07-27 12:19:56 +02:00
parent 4ed9b0be5c
commit 3a9dc3e28d
2 changed files with 121 additions and 85 deletions

View file

@ -101,6 +101,8 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
return return
} }
setupOptionsMenu()
refreshMenuItems()
storeStateVariables() storeStateVariables()
if (mShowAll) { if (mShowAll) {
@ -158,6 +160,15 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
setupAdapter() setupAdapter()
} }
val navigation = if (mShowAll) {
NavigationIcon.None
} else {
NavigationIcon.Arrow
}
setupToolbar(media_toolbar, navigation, searchMenuItem = mSearchMenuItem)
refreshMenuItems()
media_fastscroller.updateColors(primaryColor) media_fastscroller.updateColors(primaryColor)
media_refresh_layout.isEnabled = config.enablePullToRefresh media_refresh_layout.isEnabled = config.enablePullToRefresh
getMediaAdapter()?.apply { getMediaAdapter()?.apply {
@ -169,10 +180,6 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
media_empty_text_placeholder_2.setTextColor(getProperPrimaryColor()) media_empty_text_placeholder_2.setTextColor(getProperPrimaryColor())
media_empty_text_placeholder_2.bringToFront() media_empty_text_placeholder_2.bringToFront()
if (!mIsSearchOpen) {
invalidateOptionsMenu()
}
// do not refresh Random sorted files after opening a fullscreen image and going Back // do not refresh Random sorted files after opening a fullscreen image and going Back
val isRandomSorting = config.getFolderSorting(mPath) and SORT_BY_RANDOM != 0 val isRandomSorting = config.getFolderSorting(mPath) and SORT_BY_RANDOM != 0
if (mMedia.isEmpty() || !isRandomSorting || (isRandomSorting && !mWasFullscreenViewOpen)) { if (mMedia.isEmpty() || !isRandomSorting || (isRandomSorting && !mWasFullscreenViewOpen)) {
@ -227,12 +234,18 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
mTempShowHiddenHandler.removeCallbacksAndMessages(null) mTempShowHiddenHandler.removeCallbacksAndMessages(null)
} }
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onBackPressed() {
menuInflater.inflate(R.menu.menu_media, menu) if (mIsSearchOpen && mSearchMenuItem != null) {
mSearchMenuItem!!.collapseActionView()
} else {
super.onBackPressed()
}
}
private fun refreshMenuItems() {
val isDefaultFolder = !config.defaultFolder.isEmpty() && File(config.defaultFolder).compareTo(File(mPath)) == 0 val isDefaultFolder = !config.defaultFolder.isEmpty() && File(config.defaultFolder).compareTo(File(mPath)) == 0
menu.apply { media_toolbar.menu.apply {
findItem(R.id.group).isVisible = !config.scrollHorizontally findItem(R.id.group).isVisible = !config.scrollHorizontally
findItem(R.id.empty_recycle_bin).isVisible = mPath == RECYCLE_BIN findItem(R.id.empty_recycle_bin).isVisible = mPath == RECYCLE_BIN
@ -255,14 +268,12 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
findItem(R.id.reduce_column_count).isVisible = viewType == VIEW_TYPE_GRID && config.mediaColumnCnt > 1 findItem(R.id.reduce_column_count).isVisible = viewType == VIEW_TYPE_GRID && config.mediaColumnCnt > 1
findItem(R.id.toggle_filename).isVisible = viewType == VIEW_TYPE_GRID findItem(R.id.toggle_filename).isVisible = viewType == VIEW_TYPE_GRID
} }
setupSearch(menu)
updateMenuItemColors(menu)
return true
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { private fun setupOptionsMenu() {
when (item.itemId) { setupSearch(media_toolbar.menu)
media_toolbar.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
R.id.sort -> showSortingDialog() R.id.sort -> showSortingDialog()
R.id.filter -> showFilterMediaDialog() R.id.filter -> showFilterMediaDialog()
R.id.empty_recycle_bin -> emptyRecycleBin() R.id.empty_recycle_bin -> emptyRecycleBin()
@ -283,9 +294,10 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
R.id.slideshow -> startSlideshow() R.id.slideshow -> startSlideshow()
R.id.settings -> launchSettings() R.id.settings -> launchSettings()
R.id.about -> launchAbout() R.id.about -> launchAbout()
else -> return super.onOptionsItemSelected(item) else -> return@setOnMenuItemClickListener false
}
return@setOnMenuItemClickListener true
} }
return true
} }
private fun startSlideshow() { private fun startSlideshow() {
@ -390,7 +402,8 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
mPath == config.OTGPath -> getString(R.string.usb) mPath == config.OTGPath -> getString(R.string.usb)
else -> getHumanizedFilename(mPath) else -> getHumanizedFilename(mPath)
} }
//updateActionBarTitle(if (mShowAll) resources.getString(R.string.all_folders) else dirName)
media_toolbar.title = if (mShowAll) resources.getString(R.string.all_folders) else dirName
getMedia() getMedia()
setupLayoutManager() setupLayoutManager()
} else { } else {
@ -525,7 +538,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
private fun changeViewType() { private fun changeViewType() {
ChangeViewTypeDialog(this, false, mPath) { ChangeViewTypeDialog(this, false, mPath) {
invalidateOptionsMenu() refreshMenuItems()
setupLayoutManager() setupLayoutManager()
media_grid.adapter = null media_grid.adapter = null
setupAdapter() setupAdapter()
@ -653,7 +666,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
mLoadedInitialPhotos = false mLoadedInitialPhotos = false
config.temporarilyShowHidden = show config.temporarilyShowHidden = show
getMedia() getMedia()
invalidateOptionsMenu() refreshMenuItems()
} }
private fun setupLayoutManager() { private fun setupLayoutManager() {
@ -755,7 +768,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
private fun columnCountChanged() { private fun columnCountChanged() {
handleGridSpacing() handleGridSpacing()
invalidateOptionsMenu() refreshMenuItems()
getMediaAdapter()?.apply { getMediaAdapter()?.apply {
notifyItemRangeChanged(0, media.size) notifyItemRangeChanged(0, media.size)
} }
@ -947,11 +960,11 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
private fun setAsDefaultFolder() { private fun setAsDefaultFolder() {
config.defaultFolder = mPath config.defaultFolder = mPath
invalidateOptionsMenu() refreshMenuItems()
} }
private fun unsetAsDefaultFolder() { private fun unsetAsDefaultFolder() {
config.defaultFolder = "" config.defaultFolder = ""
invalidateOptionsMenu() refreshMenuItems()
} }
} }

View file

@ -1,10 +1,32 @@
<?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/media_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/media_app_bar_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/media_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/color_primary"
app:menu="@menu/menu_media"
app:title="@string/app_launcher_name"
app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" />
</com.google.android.material.appbar.AppBarLayout>
<RelativeLayout
android:id="@+id/media_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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/media_empty_text_placeholder"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -53,4 +75,5 @@
</com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller> </com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout> </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</RelativeLayout> </RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>