mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-30 00:17:58 +01:00
make sure we close the cursor
This commit is contained in:
parent
02297cc33d
commit
4d8b494c68
1 changed files with 13 additions and 6 deletions
|
@ -1,10 +1,15 @@
|
||||||
package com.simplemobiletools.gallery.asynctasks
|
package com.simplemobiletools.gallery.asynctasks
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.database.Cursor
|
||||||
import android.os.AsyncTask
|
import android.os.AsyncTask
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import com.simplemobiletools.filepicker.extensions.scanFiles
|
import com.simplemobiletools.filepicker.extensions.scanFiles
|
||||||
import com.simplemobiletools.gallery.*
|
import com.simplemobiletools.gallery.Config
|
||||||
|
import com.simplemobiletools.gallery.R
|
||||||
|
import com.simplemobiletools.gallery.SORT_BY_NAME
|
||||||
|
import com.simplemobiletools.gallery.SORT_DESCENDING
|
||||||
|
import com.simplemobiletools.gallery.extensions.getHumanizedFilename
|
||||||
import com.simplemobiletools.gallery.models.Directory
|
import com.simplemobiletools.gallery.models.Directory
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
|
@ -37,10 +42,11 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
||||||
}
|
}
|
||||||
val columns = arrayOf(MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_MODIFIED)
|
val columns = arrayOf(MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_MODIFIED)
|
||||||
val order = getSortOrder()
|
val order = getSortOrder()
|
||||||
val cursor = context.contentResolver.query(uri, columns, null, null, order)
|
var cursor: Cursor? = null
|
||||||
|
|
||||||
if (cursor != null) {
|
try {
|
||||||
if (cursor.moveToFirst()) {
|
cursor = context.contentResolver.query(uri, columns, null, null, order)
|
||||||
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
val pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA)
|
val pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA)
|
||||||
do {
|
do {
|
||||||
val fullPath: String = cursor.getString(pathIndex) ?: continue
|
val fullPath: String = cursor.getString(pathIndex) ?: continue
|
||||||
|
@ -60,7 +66,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
||||||
directory.mediaCnt = newImageCnt
|
directory.mediaCnt = newImageCnt
|
||||||
directory.addSize(file.length())
|
directory.addSize(file.length())
|
||||||
} else if (!mToBeDeleted.contains(parentDir.toLowerCase())) {
|
} else if (!mToBeDeleted.contains(parentDir.toLowerCase())) {
|
||||||
var dirName = Utils.getFilename(context, parentDir)
|
var dirName = context.getHumanizedFilename(parentDir)
|
||||||
if (mConfig.getIsFolderHidden(parentDir)) {
|
if (mConfig.getIsFolderHidden(parentDir)) {
|
||||||
dirName += " ${context.resources.getString(R.string.hidden)}"
|
dirName += " ${context.resources.getString(R.string.hidden)}"
|
||||||
}
|
}
|
||||||
|
@ -69,7 +75,8 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
||||||
}
|
}
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
cursor.close()
|
} finally {
|
||||||
|
cursor?.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue