replace lastModified mediaitem checking with latest media date taken

This commit is contained in:
tibbi 2017-09-27 23:58:30 +02:00
parent 373e06c98f
commit 33a4b81279
4 changed files with 11 additions and 27 deletions

View File

@ -37,7 +37,7 @@ android {
} }
dependencies { 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.davemorrissey.labs:subsampling-scale-image-view:3.6.0'
compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0'
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'

View File

@ -56,7 +56,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
private var mStoredCropThumbnails = true private var mStoredCropThumbnails = true
private var mStoredScrollHorizontally = true private var mStoredScrollHorizontally = true
private var mLoadedInitialPhotos = false private var mLoadedInitialPhotos = false
private var mLastMediaModified = 0 private var mLatestMediaId = 0L
private var mLastMediaHandler = Handler() private var mLastMediaHandler = Handler()
private var mCurrAsyncTask: GetDirectoriesAsynctask? = null private var mCurrAsyncTask: GetDirectoriesAsynctask? = null
@ -428,7 +428,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
private fun gotDirectories(newDirs: ArrayList<Directory>, isFromCache: Boolean) { private fun gotDirectories(newDirs: ArrayList<Directory>, isFromCache: Boolean) {
val dirs = getSortedDirectories(newDirs) val dirs = getSortedDirectories(newDirs)
mLastMediaModified = getLastMediaModified() mLatestMediaId = getLatestMediaId()
directories_refresh_layout.isRefreshing = false directories_refresh_layout.isRefreshing = false
mIsGettingDirs = false mIsGettingDirs = false
@ -491,9 +491,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
mLastMediaHandler.removeCallbacksAndMessages(null) mLastMediaHandler.removeCallbacksAndMessages(null)
mLastMediaHandler.postDelayed({ mLastMediaHandler.postDelayed({
Thread({ Thread({
val lastModified = getLastMediaModified() val mediaId = getLatestMediaId()
if (mLastMediaModified != lastModified) { if (mLatestMediaId != mediaId) {
mLastMediaModified = lastModified mLatestMediaId = mediaId
runOnUiThread { runOnUiThread {
getDirectories() getDirectories()
} }

View File

@ -51,7 +51,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
private var mStoredCropThumbnails = true private var mStoredCropThumbnails = true
private var mStoredScrollHorizontally = true private var mStoredScrollHorizontally = true
private var mLastDrawnHashCode = 0 private var mLastDrawnHashCode = 0
private var mLastMediaModified = 0 private var mLatestMediaId = 0L
private var mLastMediaHandler = Handler() private var mLastMediaHandler = Handler()
companion object { companion object {
@ -181,9 +181,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
mLastMediaHandler.removeCallbacksAndMessages(null) mLastMediaHandler.removeCallbacksAndMessages(null)
mLastMediaHandler.postDelayed({ mLastMediaHandler.postDelayed({
Thread({ Thread({
val lastModified = getLastMediaModified() val mediaId = getLatestMediaId()
if (mLastMediaModified != lastModified) { if (mLatestMediaId != mediaId) {
mLastMediaModified = lastModified mLatestMediaId = mediaId
runOnUiThread { runOnUiThread {
getMedia() getMedia()
} }
@ -463,7 +463,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
} }
private fun gotMedia(media: ArrayList<Medium>, isFromCache: Boolean = false) { private fun gotMedia(media: ArrayList<Medium>, isFromCache: Boolean = false) {
mLastMediaModified = getLastMediaModified() mLatestMediaId = getLatestMediaId()
mIsGettingMedia = false mIsGettingMedia = false
media_refresh_layout.isRefreshing = false media_refresh_layout.isRefreshing = false

View File

@ -300,22 +300,6 @@ fun Context.getNoMediaFolders(): ArrayList<String> {
return folders 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<Directory>): ArrayList<Directory> { fun Context.movePinnedDirectoriesToFront(dirs: ArrayList<Directory>): ArrayList<Directory> {
val foundFolders = ArrayList<Directory>() val foundFolders = ArrayList<Directory>()
val pinnedFolders = config.pinnedFolders val pinnedFolders = config.pinnedFolders