shorten some switch case code

This commit is contained in:
tibbi 2016-12-25 16:19:28 +01:00
parent 517f6a5825
commit dea5d0a721
8 changed files with 81 additions and 214 deletions

View file

@ -60,21 +60,13 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.save_as -> {
crop_image_view.getCroppedImageAsync()
true
}
R.id.rotate -> {
crop_image_view.rotateImage(90)
true
}
R.id.resize -> {
resizeImage()
true
}
else -> super.onOptionsItemSelected(item)
when (item.itemId) {
R.id.save_as -> crop_image_view.getCroppedImageAsync()
R.id.rotate -> crop_image_view.rotateImage(90)
R.id.resize -> resizeImage()
else -> return super.onOptionsItemSelected(item)
}
return true
}
private fun resizeImage() {

View file

@ -76,29 +76,15 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.sort -> {
showSortingDialog()
true
}
R.id.open_camera -> {
launchCamera()
true
}
R.id.show_all -> {
showAllMedia()
true
}
R.id.settings -> {
launchSettings()
true
}
R.id.about -> {
launchAbout()
true
}
else -> super.onOptionsItemSelected(item)
when (item.itemId) {
R.id.sort -> showSortingDialog()
R.id.open_camera -> launchCamera()
R.id.show_all -> showAllMedia()
R.id.settings -> launchSettings()
R.id.about -> launchAbout()
else -> return super.onOptionsItemSelected(item)
}
return true
}
override fun onResume() {

View file

@ -111,41 +111,18 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.sort -> {
showSortingDialog()
true
}
R.id.toggle_filename -> {
toggleFilenameVisibility()
true
}
R.id.open_camera -> {
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)
when (item.itemId) {
R.id.sort -> showSortingDialog()
R.id.toggle_filename -> toggleFilenameVisibility()
R.id.open_camera -> launchCamera()
R.id.folder_view -> switchToFolderView()
R.id.hide_folder -> hideFolder()
R.id.unhide_folder -> unhideFolder()
R.id.settings -> launchSettings()
R.id.about -> launchAbout()
else -> return super.onOptionsItemSelected(item)
}
return true
}
private fun toggleFilenameVisibility() {

View file

@ -95,25 +95,14 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentClic
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.menu_set_as_wallpaper -> {
setAsWallpaper(File(mMedium!!.path))
true
}
R.id.menu_open_with -> {
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)
when (item.itemId) {
R.id.menu_set_as_wallpaper -> setAsWallpaper(File(mMedium!!.path))
R.id.menu_open_with -> openWith(File(mMedium!!.path))
R.id.menu_share -> shareMedium(mMedium!!)
R.id.menu_edit -> openEditor(File(mMedium!!.path))
else -> return super.onOptionsItemSelected(item)
}
return true
}
override fun fragmentClicked() {

View file

@ -58,17 +58,12 @@ class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageComplete
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.save -> {
crop_image_view.getCroppedImageAsync()
R.id.save -> crop_image_view.getCroppedImageAsync()
R.id.rotate -> crop_image_view.rotateImage(90)
else -> return super.onOptionsItemSelected(item)
}
return true
}
R.id.rotate -> {
crop_image_view.rotateImage(90)
return true
}
}
return super.onOptionsItemSelected(item)
}
override fun onCropImageComplete(view: CropImageView?, result: CropImageView.CropResult) {
if (result.error == null) {

View file

@ -100,41 +100,18 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.menu_set_as_wallpaper -> {
setAsWallpaper(getCurrentFile())
true
}
R.id.menu_copy_move -> {
displayCopyDialog()
true
}
R.id.menu_open_with -> {
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)
when (item.itemId) {
R.id.menu_set_as_wallpaper -> setAsWallpaper(getCurrentFile())
R.id.menu_copy_move -> displayCopyDialog()
R.id.menu_open_with -> openWith(getCurrentFile())
R.id.menu_share -> shareMedium(getCurrentMedium()!!)
R.id.menu_delete -> askConfirmDelete()
R.id.menu_rename -> renameFile()
R.id.menu_edit -> openEditor(getCurrentFile())
R.id.menu_properties -> showProperties()
else -> return super.onOptionsItemSelected(item)
}
return true
}
override fun onConfigurationChanged(newConfig: Configuration) {

View file

@ -59,45 +59,18 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
return when (item.itemId) {
R.id.cab_properties -> {
showProperties()
true
}
R.id.cab_rename -> {
renameDir()
true
}
R.id.cab_pin -> {
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
when (item.itemId) {
R.id.cab_properties -> showProperties()
R.id.cab_rename -> renameDir()
R.id.cab_pin -> pinFolders(true)
R.id.cab_unpin -> pinFolders(false)
R.id.cab_hide -> toggleFoldersVisibility(true)
R.id.cab_unhide -> toggleFoldersVisibility(false)
R.id.cab_copy_move -> displayCopyDialog()
R.id.cab_delete -> askConfirmDelete()
else -> return false
}
return true
}
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())
listener?.refreshItems()
}
private fun unhideFolders() {
else
config.removeHiddenFolders(getSelectedPaths())
listener?.refreshItems()
actMode?.finish()
}
private fun pinFolder() {
private fun pinFolders(pin: Boolean) {
if (pin)
config.addPinnedFolders(getSelectedPaths())
pinnedFolders = config.pinnedFolders
listener?.refreshItems()
notifyDataSetChanged()
}
private fun unpinFolder() {
else
config.removePinnedFolders(getSelectedPaths())
pinnedFolders = config.pinnedFolders
listener?.refreshItems()
notifyDataSetChanged()
actMode?.finish()
}
private fun displayCopyDialog() {

View file

@ -59,37 +59,17 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
return when (item.itemId) {
R.id.cab_properties -> {
showProperties()
true
}
R.id.cab_rename -> {
renameFile()
true
}
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
when (item.itemId) {
R.id.cab_properties -> showProperties()
R.id.cab_rename -> renameFile()
R.id.cab_edit -> editFile()
R.id.cab_share -> shareMedia()
R.id.cab_copy_move -> displayCopyDialog()
R.id.cab_select_all -> selectAll()
R.id.cab_delete -> askConfirmDelete()
else -> return false
}
return true
}
override fun onCreateActionMode(actionMode: ActionMode?, menu: Menu?): Boolean {