store only 80 media files in shared prefs and catch OOMs
This commit is contained in:
parent
efdb646a5e
commit
c3a7068806
2 changed files with 11 additions and 5 deletions
|
@ -239,8 +239,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
}
|
||||
|
||||
private fun getDirectories() {
|
||||
if (mIsGettingDirs)
|
||||
if (mIsGettingDirs) {
|
||||
return
|
||||
}
|
||||
|
||||
mIsGettingDirs = true
|
||||
val dirs = getCachedDirectories()
|
||||
|
|
|
@ -42,7 +42,7 @@ import java.io.File
|
|||
import java.io.IOException
|
||||
|
||||
class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||
private val SAVE_MEDIA_CNT = 100
|
||||
private val SAVE_MEDIA_CNT = 80
|
||||
private val LAST_MEDIA_CHECK_PERIOD = 3000L
|
||||
|
||||
private var mPath = ""
|
||||
|
@ -611,9 +611,14 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
|
||||
private fun storeFolder() {
|
||||
if (!config.temporarilyShowHidden) {
|
||||
Thread {
|
||||
try {
|
||||
val subList = mMedia.subList(0, Math.min(SAVE_MEDIA_CNT, mMedia.size))
|
||||
val json = Gson().toJson(subList)
|
||||
config.saveFolderMedia(mPath, json)
|
||||
} catch (ignored: OutOfMemoryError) {
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue