check last media change at media too, but in a background thread
This commit is contained in:
parent
2cc9d1051c
commit
448fa72017
2 changed files with 37 additions and 9 deletions
|
@ -362,13 +362,17 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
private fun checkLastMediaChanged() {
|
||||
mLastMediaHandler.removeCallbacksAndMessages(null)
|
||||
mLastMediaHandler.postDelayed({
|
||||
val lastModified = getLastMediaModified()
|
||||
if (mLastMediaModified != lastModified) {
|
||||
getDirectories()
|
||||
mLastMediaModified = lastModified
|
||||
} else {
|
||||
checkLastMediaChanged()
|
||||
}
|
||||
Thread({
|
||||
val lastModified = getLastMediaModified()
|
||||
if (mLastMediaModified != lastModified) {
|
||||
mLastMediaModified = lastModified
|
||||
runOnUiThread {
|
||||
getDirectories()
|
||||
}
|
||||
} else {
|
||||
checkLastMediaChanged()
|
||||
}
|
||||
}).start()
|
||||
}, LAST_MEDIA_CHECK_PERIOD)
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.content.Intent
|
|||
import android.graphics.Bitmap
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.support.v7.widget.GridLayoutManager
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
|
@ -33,6 +34,7 @@ import java.io.IOException
|
|||
class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||
private val TAG = MediaActivity::class.java.simpleName
|
||||
private val SAVE_MEDIA_CNT = 40
|
||||
private val LAST_MEDIA_CHECK_PERIOD = 3000L
|
||||
|
||||
private var mMedia = ArrayList<Medium>()
|
||||
|
||||
|
@ -45,6 +47,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
private var mLoadedInitialPhotos = false
|
||||
private var mStoredAnimateGifs = true
|
||||
private var mStoredCropThumbnails = true
|
||||
private var mLastMediaModified = 0
|
||||
private var mLastMediaHandler = Handler()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -84,6 +88,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
mStoredAnimateGifs = config.animateGifs
|
||||
mStoredCropThumbnails = config.cropThumbnails
|
||||
MyScalableRecyclerView.mListener = null
|
||||
mLastMediaHandler.removeCallbacksAndMessages(null)
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
|
@ -110,7 +115,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
}
|
||||
}
|
||||
|
||||
private fun initializeGallery() {
|
||||
private fun setupAdapter() {
|
||||
if (isDirEmpty())
|
||||
return
|
||||
|
||||
|
@ -127,6 +132,23 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
media_fastscroller.setViews(media_grid, media_refresh_layout)
|
||||
}
|
||||
|
||||
private fun checkLastMediaChanged() {
|
||||
mLastMediaHandler.removeCallbacksAndMessages(null)
|
||||
mLastMediaHandler.postDelayed({
|
||||
Thread({
|
||||
val lastModified = getLastMediaModified()
|
||||
if (mLastMediaModified != lastModified) {
|
||||
mLastMediaModified = lastModified
|
||||
runOnUiThread {
|
||||
getMedia()
|
||||
}
|
||||
} else {
|
||||
checkLastMediaChanged()
|
||||
}
|
||||
}).start()
|
||||
}, LAST_MEDIA_CHECK_PERIOD)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_media, menu)
|
||||
|
||||
|
@ -359,14 +381,16 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
}
|
||||
|
||||
private fun gotMedia(media: ArrayList<Medium>) {
|
||||
mLastMediaModified = getLastMediaModified()
|
||||
mIsGettingMedia = false
|
||||
media_refresh_layout.isRefreshing = false
|
||||
|
||||
checkLastMediaChanged()
|
||||
if (media.hashCode() == mMedia.hashCode())
|
||||
return
|
||||
|
||||
mMedia = media
|
||||
initializeGallery()
|
||||
setupAdapter()
|
||||
storeFolder()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue