From 49c66427a2165c71b6995e902cead90b0ad4845b Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 26 Apr 2017 21:59:17 +0200 Subject: [PATCH] allow hiding/unhiding files from the fullscreen view too --- .../gallery/activities/ViewPagerActivity.kt | 18 ++++++++++++++++++ .../gallery/adapters/MediaAdapter.kt | 13 +------------ .../gallery/extensions/activity.kt | 15 +++++++++++++++ .../simplemobiletools/gallery/models/Medium.kt | 2 +- app/src/main/res/menu/menu_viewpager.xml | 8 ++++++++ 5 files changed, 43 insertions(+), 13 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 1386bec88..f1e30b263 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -164,6 +164,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View findItem(R.id.menu_edit).isVisible = getCurrentMedium()!!.isImage() == true findItem(R.id.menu_rotate).isVisible = getCurrentMedium()!!.isImage() == true findItem(R.id.menu_save_as).isVisible = mRotationDegrees != 0f + findItem(R.id.menu_hide).isVisible = !getCurrentMedium()!!.name.startsWith('.') + findItem(R.id.menu_unhide).isVisible = getCurrentMedium()!!.name.startsWith('.') findItem(R.id.menu_rotate).subMenu.apply { clearHeader() @@ -185,6 +187,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View R.id.menu_copy_to -> copyTo() R.id.menu_move_to -> moveTo() R.id.menu_open_with -> openWith(getCurrentFile()) + R.id.menu_hide -> toggleFileVisibility(true) + R.id.menu_unhide -> toggleFileVisibility(false) R.id.menu_share -> shareMedium(getCurrentMedium()!!) R.id.menu_delete -> askConfirmDelete() R.id.menu_rename -> renameFile() @@ -229,6 +233,20 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } } + private fun toggleFileVisibility(hide: Boolean) { + toggleFileVisibility(getCurrentFile(), hide) { + val newFileName = it.absolutePath.getFilenameFromPath() + title = newFileName + + getCurrentMedium()!!.apply { + name = newFileName + path = it.absolutePath + mMedia[mPos] = this + } + invalidateOptionsMenu() + } + } + private fun saveImageAs() { val currPath = getCurrentPath() SaveAsDialog(this, currPath) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index 07d47ae94..2ae26a6ec 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -13,7 +13,6 @@ import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.PropertiesDialog import com.simplemobiletools.commons.dialogs.RenameItemDialog import com.simplemobiletools.commons.extensions.beVisibleIf -import com.simplemobiletools.commons.extensions.renameFile import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.extensions.* @@ -153,17 +152,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, Thread({ getSelectedMedia().forEach { val oldFile = File(it.path) - val path = oldFile.parent - var filename = it.name - if (hide) { - filename = ".${filename.trimStart('.')}" - } else { - filename = filename.substring(1, filename.length) - } - val newFile = File(path, filename) - activity.renameFile(oldFile, newFile) { - newFile.setLastModified(System.currentTimeMillis()) - } + activity.toggleFileVisibility(oldFile, hide) {} } activity.runOnUiThread { listener?.refreshItems() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt index 595e629bc..43a80582c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt @@ -237,6 +237,21 @@ fun SimpleActivity.removeNoMedia(path: String, callback: () -> Unit) { } } +fun SimpleActivity.toggleFileVisibility(oldFile: File, hide: Boolean, callback: (newFile: File) -> Unit) { + val path = oldFile.parent + var filename = oldFile.name + if (hide) { + filename = ".${filename.trimStart('.')}" + } else { + filename = filename.substring(1, filename.length) + } + val newFile = File(path, filename) + renameFile(oldFile, newFile) { + newFile.setLastModified(System.currentTimeMillis()) + callback(newFile) + } +} + fun Activity.getFileSignature(path: String) = StringSignature(File(path).lastModified().toString()) fun Activity.loadImage(path: String, target: MySquareImageView) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt index 456d9cc92..c9afe29f0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -10,7 +10,7 @@ import com.simplemobiletools.commons.helpers.SORT_DESCENDING import java.io.File import java.io.Serializable -data class Medium(val name: String, var path: String, val video: Boolean, val modified: Long, val taken: Long, val size: Long) : Serializable, Comparable { +data class Medium(var name: String, var path: String, val video: Boolean, val modified: Long, val taken: Long, val size: Long) : Serializable, Comparable { companion object { private val serialVersionUID = -6553149366975455L var sorting: Int = 0 diff --git a/app/src/main/res/menu/menu_viewpager.xml b/app/src/main/res/menu/menu_viewpager.xml index 807553576..96dd6b3c1 100644 --- a/app/src/main/res/menu/menu_viewpager.xml +++ b/app/src/main/res/menu/menu_viewpager.xml @@ -50,6 +50,14 @@ android:id="@+id/menu_open_with" android:title="@string/open_with" app:showAsAction="never"/> + +