diff --git a/app/build.gradle b/app/build.gradle index 697211b8f..1b8f6288b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -37,7 +37,7 @@ android { } dependencies { - compile 'com.simplemobiletools:commons:2.28.7' + compile 'com.simplemobiletools:commons:2.28.9' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' 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 35deec3c1..b7227be6e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -56,7 +56,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private var mStoredCropThumbnails = true private var mStoredScrollHorizontally = true private var mLoadedInitialPhotos = false - private var mLastMediaModified = 0 + private var mLatestMediaId = 0L private var mLastMediaHandler = Handler() private var mCurrAsyncTask: GetDirectoriesAsynctask? = null @@ -428,7 +428,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private fun gotDirectories(newDirs: ArrayList, isFromCache: Boolean) { val dirs = getSortedDirectories(newDirs) - mLastMediaModified = getLastMediaModified() + mLatestMediaId = getLatestMediaId() directories_refresh_layout.isRefreshing = false mIsGettingDirs = false @@ -491,9 +491,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { mLastMediaHandler.removeCallbacksAndMessages(null) mLastMediaHandler.postDelayed({ Thread({ - val lastModified = getLastMediaModified() - if (mLastMediaModified != lastModified) { - mLastMediaModified = lastModified + val mediaId = getLatestMediaId() + if (mLatestMediaId != mediaId) { + mLatestMediaId = mediaId runOnUiThread { getDirectories() } 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 67765fab8..8be958661 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -51,7 +51,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private var mStoredCropThumbnails = true private var mStoredScrollHorizontally = true private var mLastDrawnHashCode = 0 - private var mLastMediaModified = 0 + private var mLatestMediaId = 0L private var mLastMediaHandler = Handler() companion object { @@ -181,9 +181,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { mLastMediaHandler.removeCallbacksAndMessages(null) mLastMediaHandler.postDelayed({ Thread({ - val lastModified = getLastMediaModified() - if (mLastMediaModified != lastModified) { - mLastMediaModified = lastModified + val mediaId = getLatestMediaId() + if (mLatestMediaId != mediaId) { + mLatestMediaId = mediaId runOnUiThread { getMedia() } @@ -463,7 +463,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } private fun gotMedia(media: ArrayList, isFromCache: Boolean = false) { - mLastMediaModified = getLastMediaModified() + mLatestMediaId = getLatestMediaId() mIsGettingMedia = false media_refresh_layout.isRefreshing = false diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt index e22a90243..ac943fe25 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt @@ -300,22 +300,6 @@ fun Context.getNoMediaFolders(): ArrayList { return folders } -fun Context.getLastMediaModified(): Int { - val max = "max" - val uri = MediaStore.Files.getContentUri("external") - val projection = arrayOf(MediaStore.Images.Media._ID, "MAX(${MediaStore.Images.Media.DATE_MODIFIED}) AS $max") - var cursor: Cursor? = null - try { - cursor = contentResolver.query(uri, projection, null, null, null) - if (cursor?.moveToFirst() == true) { - return cursor.getIntValue(max) - } - } finally { - cursor?.close() - } - return 0 -} - fun Context.movePinnedDirectoriesToFront(dirs: ArrayList): ArrayList { val foundFolders = ArrayList() val pinnedFolders = config.pinnedFolders