From 740a19e594640d8bf78b6c7bcd02fc11e6910f09 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 1 Oct 2019 12:37:38 +0200 Subject: [PATCH] improve portrait file recognizing --- .../pro/activities/ViewPagerActivity.kt | 27 +++++++++++++++++-- .../gallery/pro/helpers/Constants.kt | 1 + 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt index 7a7f98fb0..baab0b9b9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt @@ -266,7 +266,18 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View return } - if (!File(mPath).exists()) { + if (mPath.isPortrait() && getPortraitPath() == "") { + val newIntent = Intent(this, ViewPagerActivity::class.java) + newIntent.putExtras(intent!!.extras!!) + newIntent.putExtra(PORTRAIT_PATH, mPath) + newIntent.putExtra(PATH, "${mPath.getParentPath().getParentPath()}/${mPath.getFilenameFromPath()}") + + startActivity(newIntent) + finish() + return + } + + if (!File(mPath).exists() && getPortraitPath() == "") { finish() return } @@ -671,6 +682,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun getCurrentPhotoFragment() = getCurrentFragment() as? PhotoFragment + private fun getPortraitPath() = intent.getStringExtra(PORTRAIT_PATH) ?: "" + private fun isShowHiddenFlagNeeded(): Boolean { val file = File(mPath) if (file.isHidden) { @@ -1033,7 +1046,17 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun getPositionInList(items: MutableList): Int { mPos = 0 for ((i, medium) in items.withIndex()) { - if (medium.path == mPath) { + val portraitPath = getPortraitPath() + if (portraitPath != "") { + val portraitPaths = File(portraitPath).parentFile?.list() + if (portraitPaths != null) { + for (path in portraitPaths) { + if (medium.name == path) { + return i + } + } + } + } else if (medium.path == mPath) { return i } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt index 7f91dc21b..0697dfe0c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt @@ -127,6 +127,7 @@ const val SET_WALLPAPER_INTENT = "set_wallpaper_intent" const val IS_VIEW_INTENT = "is_view_intent" const val PICKED_PATHS = "picked_paths" const val SHOULD_INIT_FRAGMENT = "should_init_fragment" +const val PORTRAIT_PATH = "portrait_path" // rotations const val ROTATE_BY_SYSTEM_SETTING = 0