From 7c7b7d254d694e82901a91e1b9ea7939c8701d76 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 28 Jan 2018 21:30:14 +0100 Subject: [PATCH] disable "Temporarily show hidden" after 10 minutes of app backgrounding --- .../gallery/activities/MainActivity.kt | 31 +++++++++++++++---- .../gallery/activities/MediaActivity.kt | 29 +++++++++++++---- .../gallery/helpers/Constants.kt | 1 + 3 files changed, 49 insertions(+), 12 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 6bb06015e..7f6a7278c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -52,6 +52,14 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private var mAllowPickingMultiple = false private var mIsThirdPartyIntent = false private var mIsGettingDirs = false + private var mLoadedInitialPhotos = false + private var mIsPasswordProtectionPending = false + private var mLatestMediaId = 0L + private var mLastMediaHandler = Handler() + private var mTempShowHiddenHandler = Handler() + private var mCurrAsyncTask: GetDirectoriesAsynctask? = null + private var mZoomListener: MyRecyclerView.MyZoomListener? = null + private var mStoredUseEnglish = false private var mStoredAnimateGifs = true private var mStoredCropThumbnails = true @@ -59,12 +67,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private var mStoredShowMediaCount = true private var mStoredShowInfoBubble = true private var mStoredTextColor = 0 - private var mLoadedInitialPhotos = false - private var mIsPasswordProtectionPending = false - private var mLatestMediaId = 0L - private var mLastMediaHandler = Handler() - private var mCurrAsyncTask: GetDirectoriesAsynctask? = null - private var mZoomListener: MyRecyclerView.MyZoomListener? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -94,6 +96,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { mIsPasswordProtectionPending = config.appPasswordProtectionOn } + override fun onStart() { + super.onStart() + mTempShowHiddenHandler.removeCallbacksAndMessages(null) + } + override fun onResume() { super.onResume() config.isThirdPartyIntent = false @@ -156,9 +163,21 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } } + override fun onStop() { + super.onStop() + if (config.temporarilyShowHidden) { + mTempShowHiddenHandler.postDelayed({ + config.temporarilyShowHidden = false + }, SHOW_TEMP_HIDDEN_DURATION) + } else { + mTempShowHiddenHandler.removeCallbacksAndMessages(null) + } + } + override fun onDestroy() { super.onDestroy() config.temporarilyShowHidden = false + mTempShowHiddenHandler.removeCallbacksAndMessages(null) removeTempFolder() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 0be1d39e6..49c35da3d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -53,17 +53,19 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private var mAllowPickingMultiple = false private var mShowAll = false private var mLoadedInitialPhotos = false + private var mLatestMediaId = 0L + private var mLastMediaHandler = Handler() + private var mTempShowHiddenHandler = Handler() + private var mCurrAsyncTask: GetMediaAsynctask? = null + private var mZoomListener: MyRecyclerView.MyZoomListener? = null + private var mSearchMenuItem: MenuItem? = null + private var mStoredUseEnglish = false private var mStoredAnimateGifs = true private var mStoredCropThumbnails = true private var mStoredScrollHorizontally = true private var mStoredShowInfoBubble = true private var mStoredTextColor = 0 - private var mLatestMediaId = 0L - private var mLastMediaHandler = Handler() - private var mCurrAsyncTask: GetMediaAsynctask? = null - private var mZoomListener: MyRecyclerView.MyZoomListener? = null - private var mSearchMenuItem: MenuItem? = null companion object { var mMedia = ArrayList() @@ -90,6 +92,11 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } } + override fun onStart() { + super.onStart() + mTempShowHiddenHandler.removeCallbacksAndMessages(null) + } + override fun onResume() { super.onResume() if (mStoredUseEnglish != config.useEnglish) { @@ -139,13 +146,23 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { if (mSearchMenuItem != null) { MenuItemCompat.collapseActionView(mSearchMenuItem) } + + if (config.temporarilyShowHidden) { + mTempShowHiddenHandler.postDelayed({ + config.temporarilyShowHidden = false + }, SHOW_TEMP_HIDDEN_DURATION) + } else { + mTempShowHiddenHandler.removeCallbacksAndMessages(null) + } } override fun onDestroy() { super.onDestroy() - if (config.showAll) + if (config.showAll) { config.temporarilyShowHidden = false + } + mTempShowHiddenHandler.removeCallbacksAndMessages(null) mMedia.clear() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index 821d9f1e8..9d0e35873 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -62,6 +62,7 @@ const val SLIDESHOW_SCROLL_DURATION = 500L const val NOMEDIA = ".nomedia" const val MAX_COLUMN_COUNT = 20 +const val SHOW_TEMP_HIDDEN_DURATION = 600000L const val DIRECTORY = "directory" const val MEDIUM = "medium"