move the Menu related functions more up on the viewpager activity
This commit is contained in:
parent
2e097c59cb
commit
d821547b3d
|
@ -155,6 +155,78 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_viewpager, menu)
|
||||
val currentMedium = getCurrentMedium() ?: return true
|
||||
currentMedium.isFavorite = mFavoritePaths.contains(currentMedium.path)
|
||||
val visibleBottomActions = if (config.bottomActions) config.visibleBottomActions else 0
|
||||
|
||||
menu.apply {
|
||||
findItem(R.id.menu_show_on_map).isVisible = visibleBottomActions and BOTTOM_ACTION_SHOW_ON_MAP == 0
|
||||
findItem(R.id.menu_slideshow).isVisible = visibleBottomActions and BOTTOM_ACTION_SLIDESHOW == 0
|
||||
findItem(R.id.menu_properties).isVisible = visibleBottomActions and BOTTOM_ACTION_PROPERTIES == 0
|
||||
findItem(R.id.menu_delete).isVisible = visibleBottomActions and BOTTOM_ACTION_DELETE == 0
|
||||
findItem(R.id.menu_share).isVisible = visibleBottomActions and BOTTOM_ACTION_SHARE == 0
|
||||
findItem(R.id.menu_edit).isVisible = visibleBottomActions and BOTTOM_ACTION_EDIT == 0 && !currentMedium.isSVG()
|
||||
findItem(R.id.menu_rename).isVisible = visibleBottomActions and BOTTOM_ACTION_RENAME == 0 && !currentMedium.getIsInRecycleBin()
|
||||
findItem(R.id.menu_rotate).isVisible = currentMedium.isImage() && visibleBottomActions and BOTTOM_ACTION_ROTATE == 0
|
||||
findItem(R.id.menu_set_as).isVisible = visibleBottomActions and BOTTOM_ACTION_SET_AS == 0
|
||||
findItem(R.id.menu_save_as).isVisible = mRotationDegrees != 0
|
||||
findItem(R.id.menu_hide).isVisible = !currentMedium.isHidden() && visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY == 0 && !currentMedium.getIsInRecycleBin()
|
||||
findItem(R.id.menu_unhide).isVisible = currentMedium.isHidden() && visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY == 0 && !currentMedium.getIsInRecycleBin()
|
||||
findItem(R.id.menu_add_to_favorites).isVisible = !currentMedium.isFavorite && visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE == 0
|
||||
findItem(R.id.menu_remove_from_favorites).isVisible = currentMedium.isFavorite && visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE == 0
|
||||
findItem(R.id.menu_restore_file).isVisible = currentMedium.path.startsWith(filesDir.absolutePath)
|
||||
findItem(R.id.menu_change_orientation).isVisible = mRotationDegrees == 0 && visibleBottomActions and BOTTOM_ACTION_CHANGE_ORIENTATION == 0
|
||||
findItem(R.id.menu_change_orientation).icon = resources.getDrawable(getChangeOrientationIcon())
|
||||
findItem(R.id.menu_rotate).setShowAsAction(
|
||||
if (mRotationDegrees != 0) {
|
||||
MenuItem.SHOW_AS_ACTION_ALWAYS
|
||||
} else {
|
||||
MenuItem.SHOW_AS_ACTION_IF_ROOM
|
||||
})
|
||||
}
|
||||
|
||||
if (visibleBottomActions != 0) {
|
||||
updateBottomActionIcons(currentMedium)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (getCurrentMedium() == null)
|
||||
return true
|
||||
|
||||
when (item.itemId) {
|
||||
R.id.menu_set_as -> setAs(getCurrentPath())
|
||||
R.id.menu_slideshow -> initSlideshow()
|
||||
R.id.menu_copy_to -> copyMoveTo(true)
|
||||
R.id.menu_move_to -> copyMoveTo(false)
|
||||
R.id.menu_open_with -> openPath(getCurrentPath(), true)
|
||||
R.id.menu_hide -> toggleFileVisibility(true)
|
||||
R.id.menu_unhide -> toggleFileVisibility(false)
|
||||
R.id.menu_share -> shareMediumPath(getCurrentPath())
|
||||
R.id.menu_delete -> checkDeleteConfirmation()
|
||||
R.id.menu_rename -> renameFile()
|
||||
R.id.menu_edit -> openEditor(getCurrentPath())
|
||||
R.id.menu_properties -> showProperties()
|
||||
R.id.menu_show_on_map -> showOnMap()
|
||||
R.id.menu_rotate_right -> rotateImage(90)
|
||||
R.id.menu_rotate_left -> rotateImage(270)
|
||||
R.id.menu_rotate_one_eighty -> rotateImage(180)
|
||||
R.id.menu_add_to_favorites -> toggleFavorite()
|
||||
R.id.menu_remove_from_favorites -> toggleFavorite()
|
||||
R.id.menu_restore_file -> restoreFile()
|
||||
R.id.menu_force_portrait -> toggleOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
|
||||
R.id.menu_force_landscape -> toggleOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
|
||||
R.id.menu_default_orientation -> toggleOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
|
||||
R.id.menu_save_as -> saveImageAs()
|
||||
R.id.menu_settings -> launchSettings()
|
||||
else -> return super.onOptionsItemSelected(item)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun initViewPager() {
|
||||
measureScreen()
|
||||
val uri = intent.data
|
||||
|
@ -287,78 +359,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_viewpager, menu)
|
||||
val currentMedium = getCurrentMedium() ?: return true
|
||||
currentMedium.isFavorite = mFavoritePaths.contains(currentMedium.path)
|
||||
val visibleBottomActions = if (config.bottomActions) config.visibleBottomActions else 0
|
||||
|
||||
menu.apply {
|
||||
findItem(R.id.menu_show_on_map).isVisible = visibleBottomActions and BOTTOM_ACTION_SHOW_ON_MAP == 0
|
||||
findItem(R.id.menu_slideshow).isVisible = visibleBottomActions and BOTTOM_ACTION_SLIDESHOW == 0
|
||||
findItem(R.id.menu_properties).isVisible = visibleBottomActions and BOTTOM_ACTION_PROPERTIES == 0
|
||||
findItem(R.id.menu_delete).isVisible = visibleBottomActions and BOTTOM_ACTION_DELETE == 0
|
||||
findItem(R.id.menu_share).isVisible = visibleBottomActions and BOTTOM_ACTION_SHARE == 0
|
||||
findItem(R.id.menu_edit).isVisible = visibleBottomActions and BOTTOM_ACTION_EDIT == 0 && !currentMedium.isSVG()
|
||||
findItem(R.id.menu_rename).isVisible = visibleBottomActions and BOTTOM_ACTION_RENAME == 0 && !currentMedium.getIsInRecycleBin()
|
||||
findItem(R.id.menu_rotate).isVisible = currentMedium.isImage() && visibleBottomActions and BOTTOM_ACTION_ROTATE == 0
|
||||
findItem(R.id.menu_set_as).isVisible = visibleBottomActions and BOTTOM_ACTION_SET_AS == 0
|
||||
findItem(R.id.menu_save_as).isVisible = mRotationDegrees != 0
|
||||
findItem(R.id.menu_hide).isVisible = !currentMedium.isHidden() && visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY == 0 && !currentMedium.getIsInRecycleBin()
|
||||
findItem(R.id.menu_unhide).isVisible = currentMedium.isHidden() && visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY == 0 && !currentMedium.getIsInRecycleBin()
|
||||
findItem(R.id.menu_add_to_favorites).isVisible = !currentMedium.isFavorite && visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE == 0
|
||||
findItem(R.id.menu_remove_from_favorites).isVisible = currentMedium.isFavorite && visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE == 0
|
||||
findItem(R.id.menu_restore_file).isVisible = currentMedium.path.startsWith(filesDir.absolutePath)
|
||||
findItem(R.id.menu_change_orientation).isVisible = mRotationDegrees == 0 && visibleBottomActions and BOTTOM_ACTION_CHANGE_ORIENTATION == 0
|
||||
findItem(R.id.menu_change_orientation).icon = resources.getDrawable(getChangeOrientationIcon())
|
||||
findItem(R.id.menu_rotate).setShowAsAction(
|
||||
if (mRotationDegrees != 0) {
|
||||
MenuItem.SHOW_AS_ACTION_ALWAYS
|
||||
} else {
|
||||
MenuItem.SHOW_AS_ACTION_IF_ROOM
|
||||
})
|
||||
}
|
||||
|
||||
if (visibleBottomActions != 0) {
|
||||
updateBottomActionIcons(currentMedium)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (getCurrentMedium() == null)
|
||||
return true
|
||||
|
||||
when (item.itemId) {
|
||||
R.id.menu_set_as -> setAs(getCurrentPath())
|
||||
R.id.menu_slideshow -> initSlideshow()
|
||||
R.id.menu_copy_to -> copyMoveTo(true)
|
||||
R.id.menu_move_to -> copyMoveTo(false)
|
||||
R.id.menu_open_with -> openPath(getCurrentPath(), true)
|
||||
R.id.menu_hide -> toggleFileVisibility(true)
|
||||
R.id.menu_unhide -> toggleFileVisibility(false)
|
||||
R.id.menu_share -> shareMediumPath(getCurrentPath())
|
||||
R.id.menu_delete -> checkDeleteConfirmation()
|
||||
R.id.menu_rename -> renameFile()
|
||||
R.id.menu_edit -> openEditor(getCurrentPath())
|
||||
R.id.menu_properties -> showProperties()
|
||||
R.id.menu_show_on_map -> showOnMap()
|
||||
R.id.menu_rotate_right -> rotateImage(90)
|
||||
R.id.menu_rotate_left -> rotateImage(270)
|
||||
R.id.menu_rotate_one_eighty -> rotateImage(180)
|
||||
R.id.menu_add_to_favorites -> toggleFavorite()
|
||||
R.id.menu_remove_from_favorites -> toggleFavorite()
|
||||
R.id.menu_restore_file -> restoreFile()
|
||||
R.id.menu_force_portrait -> toggleOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
|
||||
R.id.menu_force_landscape -> toggleOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
|
||||
R.id.menu_default_orientation -> toggleOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
|
||||
R.id.menu_save_as -> saveImageAs()
|
||||
R.id.menu_settings -> launchSettings()
|
||||
else -> return super.onOptionsItemSelected(item)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun updatePagerItems(media: MutableList<Medium>) {
|
||||
val pagerAdapter = MyPagerAdapter(this, supportFragmentManager, media)
|
||||
if (!isDestroyed) {
|
||||
|
|
Loading…
Reference in New Issue