mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 13:08:00 +01:00
shorten some switch case code
This commit is contained in:
parent
517f6a5825
commit
dea5d0a721
8 changed files with 81 additions and 214 deletions
|
@ -60,21 +60,13 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
return when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.save_as -> {
|
R.id.save_as -> crop_image_view.getCroppedImageAsync()
|
||||||
crop_image_view.getCroppedImageAsync()
|
R.id.rotate -> crop_image_view.rotateImage(90)
|
||||||
true
|
R.id.resize -> resizeImage()
|
||||||
}
|
else -> return super.onOptionsItemSelected(item)
|
||||||
R.id.rotate -> {
|
|
||||||
crop_image_view.rotateImage(90)
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.resize -> {
|
|
||||||
resizeImage()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
else -> super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resizeImage() {
|
private fun resizeImage() {
|
||||||
|
|
|
@ -76,29 +76,15 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
return when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.sort -> {
|
R.id.sort -> showSortingDialog()
|
||||||
showSortingDialog()
|
R.id.open_camera -> launchCamera()
|
||||||
true
|
R.id.show_all -> showAllMedia()
|
||||||
}
|
R.id.settings -> launchSettings()
|
||||||
R.id.open_camera -> {
|
R.id.about -> launchAbout()
|
||||||
launchCamera()
|
else -> return super.onOptionsItemSelected(item)
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.show_all -> {
|
|
||||||
showAllMedia()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.settings -> {
|
|
||||||
launchSettings()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.about -> {
|
|
||||||
launchAbout()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
else -> super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
|
|
|
@ -111,41 +111,18 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
return when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.sort -> {
|
R.id.sort -> showSortingDialog()
|
||||||
showSortingDialog()
|
R.id.toggle_filename -> toggleFilenameVisibility()
|
||||||
true
|
R.id.open_camera -> launchCamera()
|
||||||
}
|
R.id.folder_view -> switchToFolderView()
|
||||||
R.id.toggle_filename -> {
|
R.id.hide_folder -> hideFolder()
|
||||||
toggleFilenameVisibility()
|
R.id.unhide_folder -> unhideFolder()
|
||||||
true
|
R.id.settings -> launchSettings()
|
||||||
}
|
R.id.about -> launchAbout()
|
||||||
R.id.open_camera -> {
|
else -> return super.onOptionsItemSelected(item)
|
||||||
launchCamera()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.folder_view -> {
|
|
||||||
switchToFolderView()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.hide_folder -> {
|
|
||||||
hideFolder()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.unhide_folder -> {
|
|
||||||
unhideFolder()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.settings -> {
|
|
||||||
launchSettings()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.about -> {
|
|
||||||
launchAbout()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
else -> super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleFilenameVisibility() {
|
private fun toggleFilenameVisibility() {
|
||||||
|
|
|
@ -95,25 +95,14 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentClic
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
return when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.menu_set_as_wallpaper -> {
|
R.id.menu_set_as_wallpaper -> setAsWallpaper(File(mMedium!!.path))
|
||||||
setAsWallpaper(File(mMedium!!.path))
|
R.id.menu_open_with -> openWith(File(mMedium!!.path))
|
||||||
true
|
R.id.menu_share -> shareMedium(mMedium!!)
|
||||||
}
|
R.id.menu_edit -> openEditor(File(mMedium!!.path))
|
||||||
R.id.menu_open_with -> {
|
else -> return super.onOptionsItemSelected(item)
|
||||||
openWith(File(mMedium!!.path))
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.menu_share -> {
|
|
||||||
shareMedium(mMedium!!)
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.menu_edit -> {
|
|
||||||
openEditor(File(mMedium!!.path))
|
|
||||||
true
|
|
||||||
}
|
|
||||||
else -> super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fragmentClicked() {
|
override fun fragmentClicked() {
|
||||||
|
|
|
@ -58,17 +58,12 @@ class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageComplete
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.save -> {
|
R.id.save -> crop_image_view.getCroppedImageAsync()
|
||||||
crop_image_view.getCroppedImageAsync()
|
R.id.rotate -> crop_image_view.rotateImage(90)
|
||||||
|
else -> return super.onOptionsItemSelected(item)
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.rotate -> {
|
|
||||||
crop_image_view.rotateImage(90)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return super.onOptionsItemSelected(item)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCropImageComplete(view: CropImageView?, result: CropImageView.CropResult) {
|
override fun onCropImageComplete(view: CropImageView?, result: CropImageView.CropResult) {
|
||||||
if (result.error == null) {
|
if (result.error == null) {
|
||||||
|
|
|
@ -100,41 +100,18 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
return when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.menu_set_as_wallpaper -> {
|
R.id.menu_set_as_wallpaper -> setAsWallpaper(getCurrentFile())
|
||||||
setAsWallpaper(getCurrentFile())
|
R.id.menu_copy_move -> displayCopyDialog()
|
||||||
true
|
R.id.menu_open_with -> openWith(getCurrentFile())
|
||||||
}
|
R.id.menu_share -> shareMedium(getCurrentMedium()!!)
|
||||||
R.id.menu_copy_move -> {
|
R.id.menu_delete -> askConfirmDelete()
|
||||||
displayCopyDialog()
|
R.id.menu_rename -> renameFile()
|
||||||
true
|
R.id.menu_edit -> openEditor(getCurrentFile())
|
||||||
}
|
R.id.menu_properties -> showProperties()
|
||||||
R.id.menu_open_with -> {
|
else -> return super.onOptionsItemSelected(item)
|
||||||
openWith(getCurrentFile())
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.menu_share -> {
|
|
||||||
shareMedium(getCurrentMedium()!!)
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.menu_delete -> {
|
|
||||||
askConfirmDelete()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.menu_rename -> {
|
|
||||||
renameFile()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.menu_edit -> {
|
|
||||||
openEditor(getCurrentFile())
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.menu_properties -> {
|
|
||||||
showProperties()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
else -> super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||||
|
|
|
@ -59,45 +59,18 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
|
||||||
|
|
||||||
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
|
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
|
||||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||||
return when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.cab_properties -> {
|
R.id.cab_properties -> showProperties()
|
||||||
showProperties()
|
R.id.cab_rename -> renameDir()
|
||||||
true
|
R.id.cab_pin -> pinFolders(true)
|
||||||
}
|
R.id.cab_unpin -> pinFolders(false)
|
||||||
R.id.cab_rename -> {
|
R.id.cab_hide -> toggleFoldersVisibility(true)
|
||||||
renameDir()
|
R.id.cab_unhide -> toggleFoldersVisibility(false)
|
||||||
true
|
R.id.cab_copy_move -> displayCopyDialog()
|
||||||
}
|
R.id.cab_delete -> askConfirmDelete()
|
||||||
R.id.cab_pin -> {
|
else -> return false
|
||||||
pinFolder()
|
|
||||||
mode.finish()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.cab_unpin -> {
|
|
||||||
unpinFolder()
|
|
||||||
mode.finish()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.cab_hide -> {
|
|
||||||
hideFolders()
|
|
||||||
mode.finish()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.cab_unhide -> {
|
|
||||||
unhideFolders()
|
|
||||||
mode.finish()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.cab_copy_move -> {
|
|
||||||
displayCopyDialog()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.cab_delete -> {
|
|
||||||
askConfirmDelete()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
else -> false
|
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateActionMode(actionMode: ActionMode?, menu: Menu?): Boolean {
|
override fun onCreateActionMode(actionMode: ActionMode?, menu: Menu?): Boolean {
|
||||||
|
@ -183,28 +156,26 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun hideFolders() {
|
private fun toggleFoldersVisibility(hide: Boolean) {
|
||||||
|
if (hide)
|
||||||
config.addHiddenFolders(getSelectedPaths())
|
config.addHiddenFolders(getSelectedPaths())
|
||||||
listener?.refreshItems()
|
else
|
||||||
}
|
|
||||||
|
|
||||||
private fun unhideFolders() {
|
|
||||||
config.removeHiddenFolders(getSelectedPaths())
|
config.removeHiddenFolders(getSelectedPaths())
|
||||||
|
|
||||||
listener?.refreshItems()
|
listener?.refreshItems()
|
||||||
|
actMode?.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun pinFolder() {
|
private fun pinFolders(pin: Boolean) {
|
||||||
|
if (pin)
|
||||||
config.addPinnedFolders(getSelectedPaths())
|
config.addPinnedFolders(getSelectedPaths())
|
||||||
pinnedFolders = config.pinnedFolders
|
else
|
||||||
listener?.refreshItems()
|
|
||||||
notifyDataSetChanged()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun unpinFolder() {
|
|
||||||
config.removePinnedFolders(getSelectedPaths())
|
config.removePinnedFolders(getSelectedPaths())
|
||||||
|
|
||||||
pinnedFolders = config.pinnedFolders
|
pinnedFolders = config.pinnedFolders
|
||||||
listener?.refreshItems()
|
listener?.refreshItems()
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
|
actMode?.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun displayCopyDialog() {
|
private fun displayCopyDialog() {
|
||||||
|
|
|
@ -59,37 +59,17 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
||||||
|
|
||||||
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
|
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
|
||||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||||
return when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.cab_properties -> {
|
R.id.cab_properties -> showProperties()
|
||||||
showProperties()
|
R.id.cab_rename -> renameFile()
|
||||||
true
|
R.id.cab_edit -> editFile()
|
||||||
}
|
R.id.cab_share -> shareMedia()
|
||||||
R.id.cab_rename -> {
|
R.id.cab_copy_move -> displayCopyDialog()
|
||||||
renameFile()
|
R.id.cab_select_all -> selectAll()
|
||||||
true
|
R.id.cab_delete -> askConfirmDelete()
|
||||||
}
|
else -> return false
|
||||||
R.id.cab_edit -> {
|
|
||||||
editFile()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.cab_share -> {
|
|
||||||
shareMedia()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.cab_copy_move -> {
|
|
||||||
displayCopyDialog()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.cab_select_all -> {
|
|
||||||
selectAll()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.cab_delete -> {
|
|
||||||
askConfirmDelete()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
else -> false
|
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateActionMode(actionMode: ActionMode?, menu: Menu?): Boolean {
|
override fun onCreateActionMode(actionMode: ActionMode?, menu: Menu?): Boolean {
|
||||||
|
|
Loading…
Reference in a new issue