updating the viewpager activity style

This commit is contained in:
tibbi 2022-07-27 15:41:24 +02:00
parent aa3a9fdc88
commit 592b8133a6
2 changed files with 138 additions and 100 deletions

View file

@ -21,8 +21,11 @@ import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.provider.MediaStore.Images import android.provider.MediaStore.Images
import android.view.* import android.view.MenuItem
import android.view.View
import android.view.WindowManager
import android.view.animation.DecelerateInterpolator import android.view.animation.DecelerateInterpolator
import android.widget.RelativeLayout
import android.widget.Toast import android.widget.Toast
import androidx.exifinterface.media.ExifInterface import androidx.exifinterface.media.ExifInterface
import androidx.print.PrintHelper import androidx.print.PrintHelper
@ -86,12 +89,17 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
useDynamicTheme = false useDynamicTheme = false
showTransparentTop = true
showTransparentNavigation = true
if (config.isUsingSystemTheme) { if (config.isUsingSystemTheme) {
setTheme(R.style.AppTheme_Material) setTheme(R.style.AppTheme_Material)
} }
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_medium) setContentView(R.layout.activity_medium)
setupOptionsMenu()
refreshMenuItems()
window.decorView.setBackgroundColor(getProperBackgroundColor()) window.decorView.setBackgroundColor(getProperBackgroundColor())
top_shadow.layoutParams.height = statusBarHeight + actionBarHeight top_shadow.layoutParams.height = statusBarHeight + actionBarHeight
@ -108,10 +116,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
initFavorites() initFavorites()
if (isRPlus()) {
window.insetsController?.setSystemBarsAppearance(0, WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS)
}
} }
override fun onResume() { override fun onResume() {
@ -138,10 +142,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
setupOrientation() setupOrientation()
invalidateOptionsMenu() invalidateOptionsMenu()
supportActionBar?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
val filename = getCurrentMedium()?.name ?: mPath.getFilenameFromPath() val filename = getCurrentMedium()?.name ?: mPath.getFilenameFromPath()
supportActionBar?.title = filename medium_viewer_toolbar?.title = filename
window.statusBarColor = Color.TRANSPARENT
} }
override fun onPause() { override fun onPause() {
@ -164,96 +166,102 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
} }
override fun onCreateOptionsMenu(menu: Menu): Boolean { private fun refreshMenuItems() {
menuInflater.inflate(R.menu.menu_viewpager, menu) val currentMedium = getCurrentMedium() ?: return
val currentMedium = getCurrentMedium() ?: return true
currentMedium.isFavorite = mFavoritePaths.contains(currentMedium.path) currentMedium.isFavorite = mFavoritePaths.contains(currentMedium.path)
val visibleBottomActions = if (config.bottomActions) config.visibleBottomActions else 0 val visibleBottomActions = if (config.bottomActions) config.visibleBottomActions else 0
val rotationDegrees = getCurrentPhotoFragment()?.mCurrentRotationDegrees ?: 0 runOnUiThread {
menu.apply { val rotationDegrees = getCurrentPhotoFragment()?.mCurrentRotationDegrees ?: 0
findItem(R.id.menu_show_on_map).isVisible = visibleBottomActions and BOTTOM_ACTION_SHOW_ON_MAP == 0 medium_viewer_toolbar.menu.apply {
findItem(R.id.menu_slideshow).isVisible = visibleBottomActions and BOTTOM_ACTION_SLIDESHOW == 0 findItem(R.id.menu_show_on_map).isVisible = visibleBottomActions and BOTTOM_ACTION_SHOW_ON_MAP == 0
findItem(R.id.menu_properties).isVisible = visibleBottomActions and BOTTOM_ACTION_PROPERTIES == 0 findItem(R.id.menu_slideshow).isVisible = visibleBottomActions and BOTTOM_ACTION_SLIDESHOW == 0
findItem(R.id.menu_delete).isVisible = visibleBottomActions and BOTTOM_ACTION_DELETE == 0 findItem(R.id.menu_properties).isVisible = visibleBottomActions and BOTTOM_ACTION_PROPERTIES == 0
findItem(R.id.menu_share).isVisible = visibleBottomActions and BOTTOM_ACTION_SHARE == 0 findItem(R.id.menu_delete).isVisible = visibleBottomActions and BOTTOM_ACTION_DELETE == 0
findItem(R.id.menu_edit).isVisible = visibleBottomActions and BOTTOM_ACTION_EDIT == 0 && !currentMedium.isSVG() findItem(R.id.menu_share).isVisible = visibleBottomActions and BOTTOM_ACTION_SHARE == 0
findItem(R.id.menu_rename).isVisible = visibleBottomActions and BOTTOM_ACTION_RENAME == 0 && !currentMedium.getIsInRecycleBin() findItem(R.id.menu_edit).isVisible = visibleBottomActions and BOTTOM_ACTION_EDIT == 0 && !currentMedium.isSVG()
findItem(R.id.menu_rotate).isVisible = currentMedium.isImage() && visibleBottomActions and BOTTOM_ACTION_ROTATE == 0 findItem(R.id.menu_rename).isVisible = visibleBottomActions and BOTTOM_ACTION_RENAME == 0 && !currentMedium.getIsInRecycleBin()
findItem(R.id.menu_set_as).isVisible = visibleBottomActions and BOTTOM_ACTION_SET_AS == 0 findItem(R.id.menu_rotate).isVisible = currentMedium.isImage() && visibleBottomActions and BOTTOM_ACTION_ROTATE == 0
findItem(R.id.menu_copy_to).isVisible = visibleBottomActions and BOTTOM_ACTION_COPY == 0 findItem(R.id.menu_set_as).isVisible = visibleBottomActions and BOTTOM_ACTION_SET_AS == 0
findItem(R.id.menu_move_to).isVisible = visibleBottomActions and BOTTOM_ACTION_MOVE == 0 findItem(R.id.menu_copy_to).isVisible = visibleBottomActions and BOTTOM_ACTION_COPY == 0
findItem(R.id.menu_save_as).isVisible = rotationDegrees != 0 findItem(R.id.menu_move_to).isVisible = visibleBottomActions and BOTTOM_ACTION_MOVE == 0
findItem(R.id.menu_print).isVisible = currentMedium.isImage() || currentMedium.isRaw() findItem(R.id.menu_save_as).isVisible = rotationDegrees != 0
findItem(R.id.menu_resize).isVisible = visibleBottomActions and BOTTOM_ACTION_RESIZE == 0 && currentMedium.isImage() findItem(R.id.menu_print).isVisible = currentMedium.isImage() || currentMedium.isRaw()
findItem(R.id.menu_hide).isVisible = findItem(R.id.menu_resize).isVisible = visibleBottomActions and BOTTOM_ACTION_RESIZE == 0 && currentMedium.isImage()
(!isRPlus() || isExternalStorageManager()) && !currentMedium.isHidden() && visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY == 0 && !currentMedium.getIsInRecycleBin() findItem(R.id.menu_hide).isVisible =
(!isRPlus() || isExternalStorageManager()) && !currentMedium.isHidden() && visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY == 0 && !currentMedium.getIsInRecycleBin()
findItem(R.id.menu_unhide).isVisible = findItem(R.id.menu_unhide).isVisible =
(!isRPlus() || isExternalStorageManager()) && currentMedium.isHidden() && visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY == 0 && !currentMedium.getIsInRecycleBin() (!isRPlus() || isExternalStorageManager()) && currentMedium.isHidden() && visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY == 0 && !currentMedium.getIsInRecycleBin()
findItem(R.id.menu_add_to_favorites).isVisible = findItem(R.id.menu_add_to_favorites).isVisible =
!currentMedium.isFavorite && visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE == 0 && !currentMedium.getIsInRecycleBin() !currentMedium.isFavorite && visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE == 0 && !currentMedium.getIsInRecycleBin()
findItem(R.id.menu_remove_from_favorites).isVisible = findItem(R.id.menu_remove_from_favorites).isVisible =
currentMedium.isFavorite && visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE == 0 && !currentMedium.getIsInRecycleBin() currentMedium.isFavorite && visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE == 0 && !currentMedium.getIsInRecycleBin()
findItem(R.id.menu_restore_file).isVisible = currentMedium.path.startsWith(recycleBinPath) findItem(R.id.menu_restore_file).isVisible = currentMedium.path.startsWith(recycleBinPath)
findItem(R.id.menu_create_shortcut).isVisible = isOreoPlus() findItem(R.id.menu_create_shortcut).isVisible = isOreoPlus()
findItem(R.id.menu_change_orientation).isVisible = rotationDegrees == 0 && visibleBottomActions and BOTTOM_ACTION_CHANGE_ORIENTATION == 0 findItem(R.id.menu_change_orientation).isVisible = rotationDegrees == 0 && visibleBottomActions and BOTTOM_ACTION_CHANGE_ORIENTATION == 0
findItem(R.id.menu_change_orientation).icon = resources.getDrawable(getChangeOrientationIcon()) findItem(R.id.menu_change_orientation).icon = resources.getDrawable(getChangeOrientationIcon())
findItem(R.id.menu_rotate).setShowAsAction( findItem(R.id.menu_rotate).setShowAsAction(
if (rotationDegrees != 0) { if (rotationDegrees != 0) {
MenuItem.SHOW_AS_ACTION_ALWAYS MenuItem.SHOW_AS_ACTION_ALWAYS
} else { } else {
MenuItem.SHOW_AS_ACTION_IF_ROOM MenuItem.SHOW_AS_ACTION_IF_ROOM
} }
) )
}
if (visibleBottomActions != 0) {
updateBottomActionIcons(currentMedium)
}
} }
if (visibleBottomActions != 0) {
updateBottomActionIcons(currentMedium)
}
updateMenuItemColors(menu, forceWhiteIcons = true)
return true
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { private fun setupOptionsMenu() {
if (getCurrentMedium() == null) (medium_viewer_appbar.layoutParams as RelativeLayout.LayoutParams).topMargin = statusBarHeight
return true medium_viewer_toolbar.setOnMenuItemClickListener { menuItem ->
if (getCurrentMedium() == null) {
return@setOnMenuItemClickListener true
}
when (item.itemId) { when (menuItem.itemId) {
R.id.menu_set_as -> setAs(getCurrentPath()) R.id.menu_set_as -> setAs(getCurrentPath())
R.id.menu_slideshow -> initSlideshow() R.id.menu_slideshow -> initSlideshow()
R.id.menu_copy_to -> checkMediaManagementAndCopy(true) R.id.menu_copy_to -> checkMediaManagementAndCopy(true)
R.id.menu_move_to -> moveFileTo() R.id.menu_move_to -> moveFileTo()
R.id.menu_open_with -> openPath(getCurrentPath(), true) R.id.menu_open_with -> openPath(getCurrentPath(), true)
R.id.menu_hide -> toggleFileVisibility(true) R.id.menu_hide -> toggleFileVisibility(true)
R.id.menu_unhide -> toggleFileVisibility(false) R.id.menu_unhide -> toggleFileVisibility(false)
R.id.menu_share -> shareMediumPath(getCurrentPath()) R.id.menu_share -> shareMediumPath(getCurrentPath())
R.id.menu_delete -> checkDeleteConfirmation() R.id.menu_delete -> checkDeleteConfirmation()
R.id.menu_rename -> checkMediaManagementAndRename() R.id.menu_rename -> checkMediaManagementAndRename()
R.id.menu_print -> printFile() R.id.menu_print -> printFile()
R.id.menu_edit -> openEditor(getCurrentPath()) R.id.menu_edit -> openEditor(getCurrentPath())
R.id.menu_properties -> showProperties() R.id.menu_properties -> showProperties()
R.id.menu_show_on_map -> showFileOnMap(getCurrentPath()) R.id.menu_show_on_map -> showFileOnMap(getCurrentPath())
R.id.menu_rotate_right -> rotateImage(90) R.id.menu_rotate_right -> rotateImage(90)
R.id.menu_rotate_left -> rotateImage(-90) R.id.menu_rotate_left -> rotateImage(-90)
R.id.menu_rotate_one_eighty -> rotateImage(180) R.id.menu_rotate_one_eighty -> rotateImage(180)
R.id.menu_add_to_favorites -> toggleFavorite() R.id.menu_add_to_favorites -> toggleFavorite()
R.id.menu_remove_from_favorites -> toggleFavorite() R.id.menu_remove_from_favorites -> toggleFavorite()
R.id.menu_restore_file -> restoreFile() R.id.menu_restore_file -> restoreFile()
R.id.menu_force_portrait -> toggleOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) R.id.menu_force_portrait -> toggleOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
R.id.menu_force_landscape -> toggleOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) R.id.menu_force_landscape -> toggleOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
R.id.menu_default_orientation -> toggleOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) R.id.menu_default_orientation -> toggleOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
R.id.menu_save_as -> saveImageAs() R.id.menu_save_as -> saveImageAs()
R.id.menu_create_shortcut -> createShortcut() R.id.menu_create_shortcut -> createShortcut()
R.id.menu_resize -> resizeImage() R.id.menu_resize -> resizeImage()
R.id.menu_settings -> launchSettings() R.id.menu_settings -> launchSettings()
else -> return super.onOptionsItemSelected(item) else -> return@setOnMenuItemClickListener false
}
return@setOnMenuItemClickListener true
}
medium_viewer_toolbar.setNavigationOnClickListener {
finish()
} }
return true
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
@ -685,7 +693,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
getCurrentMedia()[mPos] = this getCurrentMedia()[mPos] = this
} }
invalidateOptionsMenu() refreshMenuItems()
callback?.invoke() callback?.invoke()
} }
} }
@ -705,13 +713,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun rotateBy(degrees: Int) { private fun rotateBy(degrees: Int) {
getCurrentPhotoFragment()?.rotateImageViewBy(degrees) getCurrentPhotoFragment()?.rotateImageViewBy(degrees)
supportInvalidateOptionsMenu() refreshMenuItems()
} }
private fun toggleOrientation(orientation: Int) { private fun toggleOrientation(orientation: Int) {
requestedOrientation = orientation requestedOrientation = orientation
mIsOrientationLocked = orientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED mIsOrientationLocked = orientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
invalidateOptionsMenu() refreshMenuItems()
} }
private fun getChangeOrientationIcon(): Int { private fun getChangeOrientationIcon(): Int {
@ -741,7 +749,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
saveRotatedImageToFile(currPath, newPath, photoFragment.mCurrentRotationDegrees, true) { saveRotatedImageToFile(currPath, newPath, photoFragment.mCurrentRotationDegrees, true) {
toast(R.string.file_saved) toast(R.string.file_saved)
getCurrentPhotoFragment()?.mCurrentRotationDegrees = 0 getCurrentPhotoFragment()?.mCurrentRotationDegrees = 0
invalidateOptionsMenu() refreshMenuItems()
} }
} }
} }
@ -819,6 +827,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} else { } else {
bottom_actions.beGone() bottom_actions.beGone()
} }
if (!portrait && navigationBarRight && navigationBarWidth > 0) {
medium_viewer_toolbar.setPadding(0, 0, navigationBarWidth, 0)
}
} }
private fun initBottomActionButtons() { private fun initBottomActionButtons() {
@ -953,7 +965,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} else { } else {
mFavoritePaths.remove(medium.path) mFavoritePaths.remove(medium.path)
} }
invalidateOptionsMenu()
runOnUiThread {
refreshMenuItems()
}
} }
} }
@ -1268,7 +1283,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
updateActionbarTitle() updateActionbarTitle()
updatePagerItems(mMediaFiles.toMutableList()) updatePagerItems(mMediaFiles.toMutableList())
invalidateOptionsMenu() refreshMenuItems()
checkOrientation() checkOrientation()
initBottomActions() initBottomActions()
} }
@ -1400,13 +1415,19 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}.withEndAction { }.withEndAction {
bottom_actions.beVisibleIf(newAlpha == 1f) bottom_actions.beVisibleIf(newAlpha == 1f)
}.start() }.start()
medium_viewer_appbar.animate().alpha(newAlpha).withStartAction {
medium_viewer_appbar.beVisible()
}.withEndAction {
medium_viewer_appbar.beVisibleIf(newAlpha == 1f)
}.start()
} }
} }
private fun updateActionbarTitle() { private fun updateActionbarTitle() {
runOnUiThread { runOnUiThread {
if (mPos < getCurrentMedia().size) { if (mPos < getCurrentMedia().size) {
supportActionBar?.title = getCurrentMedia()[mPos].path.getFilenameFromPath() medium_viewer_toolbar.title = getCurrentMedia()[mPos].path.getFilenameFromPath()
} }
} }
} }
@ -1429,7 +1450,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
if (mPos != position) { if (mPos != position) {
mPos = position mPos = position
updateActionbarTitle() updateActionbarTitle()
invalidateOptionsMenu() refreshMenuItems()
scheduleSwipe() scheduleSwipe()
} }
} }

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragment_holder" android:id="@+id/fragment_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
@ -8,17 +8,34 @@
<com.simplemobiletools.commons.views.MyViewPager <com.simplemobiletools.commons.views.MyViewPager
android:id="@+id/view_pager" android:id="@+id/view_pager"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"/> android:layout_height="match_parent" />
<include <include
android:id="@+id/bottom_actions" android:id="@+id/bottom_actions"
layout="@layout/bottom_actions"/> layout="@layout/bottom_actions" />
<ImageView <ImageView
android:id="@+id/top_shadow" android:id="@+id/top_shadow"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/default_status_action_height" android:layout_height="@dimen/default_status_action_height"
android:contentDescription="@null" android:background="@drawable/gradient_background_flipped"
android:background="@drawable/gradient_background_flipped"/> android:contentDescription="@null" />
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/medium_viewer_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="@android:color/transparent"
android:elevation="0dp"
app:elevation="0dp">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/medium_viewer_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:menu="@menu/menu_viewpager"
app:navigationIcon="@drawable/ic_arrow_left_vector" />
</com.google.android.material.appbar.AppBarLayout>
</RelativeLayout> </RelativeLayout>