From 60ed21702febefa968678c738eb62184681e0558 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 28 Aug 2017 20:43:39 +0200 Subject: [PATCH] fix #335, properly show hidden files if open through a file manager --- .../gallery/activities/MainActivity.kt | 2 +- .../gallery/activities/ViewPagerActivity.kt | 23 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index 1cba45262..1f8ab2e12 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -72,7 +72,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { mIsGetAnyContentIntent || mIsSetWallpaperIntent directories_refresh_layout.setOnRefreshListener({ getDirectories() }) - mDirs = ArrayList() + mDirs = ArrayList() mStoredAnimateGifs = config.animateGifs mStoredCropThumbnails = config.cropThumbnails mStoredScrollHorizontally = config.scrollHorizontally 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 b88493874..e034a167d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -98,7 +98,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View return } - if (intent.extras?.containsKey(IS_VIEW_INTENT) == true && File(mPath).isHidden) { + if (intent.extras?.containsKey(IS_VIEW_INTENT) == true && isShowHiddenFlagNeeded()) { if (!config.isPasswordProtectionOn) { config.temporarilyShowHidden = true } @@ -443,6 +443,27 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View out.close() } + + private fun isShowHiddenFlagNeeded(): Boolean { + val file = File(mPath) + if (file.isHidden) + return true + + var parent = file.parentFile + while (true) { + if (parent.isHidden || parent.listFiles()?.contains(File(NOMEDIA)) == true) { + return true + } + + if (parent.absolutePath == "/") { + break + } + parent = parent.parentFile + } + + return false + } + private fun getCurrentFragment() = (view_pager.adapter as MyPagerAdapter).getCurrentFragment(view_pager.currentItem) private fun showProperties() {