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,37 +268,36 @@ 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)
R.id.sort -> showSortingDialog() media_toolbar.setOnMenuItemClickListener { menuItem ->
R.id.filter -> showFilterMediaDialog() when (menuItem.itemId) {
R.id.empty_recycle_bin -> emptyRecycleBin() R.id.sort -> showSortingDialog()
R.id.empty_disable_recycle_bin -> emptyAndDisableRecycleBin() R.id.filter -> showFilterMediaDialog()
R.id.restore_all_files -> restoreAllFiles() R.id.empty_recycle_bin -> emptyRecycleBin()
R.id.toggle_filename -> toggleFilenameVisibility() R.id.empty_disable_recycle_bin -> emptyAndDisableRecycleBin()
R.id.open_camera -> launchCamera() R.id.restore_all_files -> restoreAllFiles()
R.id.folder_view -> switchToFolderView() R.id.toggle_filename -> toggleFilenameVisibility()
R.id.change_view_type -> changeViewType() R.id.open_camera -> launchCamera()
R.id.group -> showGroupByDialog() R.id.folder_view -> switchToFolderView()
R.id.create_new_folder -> createNewFolder() R.id.change_view_type -> changeViewType()
R.id.temporarily_show_hidden -> tryToggleTemporarilyShowHidden() R.id.group -> showGroupByDialog()
R.id.stop_showing_hidden -> tryToggleTemporarilyShowHidden() R.id.create_new_folder -> createNewFolder()
R.id.increase_column_count -> increaseColumnCount() R.id.temporarily_show_hidden -> tryToggleTemporarilyShowHidden()
R.id.reduce_column_count -> reduceColumnCount() R.id.stop_showing_hidden -> tryToggleTemporarilyShowHidden()
R.id.set_as_default_folder -> setAsDefaultFolder() R.id.increase_column_count -> increaseColumnCount()
R.id.unset_as_default_folder -> unsetAsDefaultFolder() R.id.reduce_column_count -> reduceColumnCount()
R.id.slideshow -> startSlideshow() R.id.set_as_default_folder -> setAsDefaultFolder()
R.id.settings -> launchSettings() R.id.unset_as_default_folder -> unsetAsDefaultFolder()
R.id.about -> launchAbout() R.id.slideshow -> startSlideshow()
else -> return super.onOptionsItemSelected(item) R.id.settings -> launchSettings()
R.id.about -> launchAbout()
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,56 +1,79 @@
<?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_width="match_parent"
android:layout_height="wrap_content"> 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/media_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.simplemobiletools.commons.views.MyTextView
android:id="@+id/media_empty_text_placeholder_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/media_empty_text_placeholder"
android:layout_centerHorizontal="true"
android:background="@drawable/ripple_all_corners"
android:padding="@dimen/activity_margin"
android:text="@string/change_filters_underlined"
android:textSize="@dimen/bigger_text_size"
android:visibility="gone" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/media_refresh_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller <com.google.android.material.appbar.MaterialToolbar
android:id="@+id/media_fastscroller" 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
android:id="@+id/media_empty_text_placeholder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:supportSwipeToRefresh="true"> 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.simplemobiletools.commons.views.MyRecyclerView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/media_grid" android:id="@+id/media_empty_text_placeholder_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/media_empty_text_placeholder"
android:layout_centerHorizontal="true"
android:background="@drawable/ripple_all_corners"
android:padding="@dimen/activity_margin"
android:text="@string/change_filters_underlined"
android:textSize="@dimen/bigger_text_size"
android:visibility="gone" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/media_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
android:id="@+id/media_fastscroller"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:layoutAnimation="@anim/layout_animation" app:supportSwipeToRefresh="true">
android:scrollbars="none"
app:layoutManager="com.simplemobiletools.commons.views.MyGridLayoutManager"
app:spanCount="@integer/media_columns_vertical_scroll" />
</com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller> <com.simplemobiletools.commons.views.MyRecyclerView
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout> android:id="@+id/media_grid"
</RelativeLayout> android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutAnimation="@anim/layout_animation"
android:scrollbars="none"
app:layoutManager="com.simplemobiletools.commons.views.MyGridLayoutManager"
app:spanCount="@integer/media_columns_vertical_scroll" />
</com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>