remove some empty callbacks to avoid memory leaks

This commit is contained in:
tibbi 2017-11-09 14:50:05 +01:00
parent aa5b5b3081
commit 0bb48601f4
9 changed files with 18 additions and 18 deletions

View file

@ -45,7 +45,7 @@ ext {
}
dependencies {
compile 'com.simplemobiletools:commons:2.37.12'
compile 'com.simplemobiletools:commons:2.38.0'
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.7.2'
compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0'
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'

View file

@ -60,7 +60,7 @@ class IncludedFoldersActivity : SimpleActivity() {
FilePickerDialog(this, pickFile = false, showHidden = config.shouldShowHidden) {
config.addIncludedFolder(it)
updateIncludedFolders()
scanPath(it) {}
scanPath(it)
}
}
}

View file

@ -209,7 +209,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
val newFolder = File(config.tempFolderPath)
if (newFolder.exists() && newFolder.isDirectory) {
if (newFolder.list()?.isEmpty() == true) {
deleteFileBg(newFolder, true) { }
deleteFileBg(newFolder, true)
}
}
config.tempFolderPath = ""

View file

@ -347,7 +347,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
private fun deleteDirectoryIfEmpty() {
val file = File(mPath)
if (config.deleteEmptyFolders && !file.isDownloadsFolder() && file.isDirectory && file.listFiles()?.isEmpty() == true) {
deleteFile(file, true) {}
deleteFile(file, true)
}
}

View file

@ -59,14 +59,14 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
mIsFromGallery = intent.getBooleanExtra(IS_FROM_GALLERY, false)
if (mUri!!.scheme == "file") {
scanPath(mUri!!.path) {}
scanPath(mUri!!.path)
sendViewPagerIntent(mUri!!.path)
finish()
return
} else {
val path = applicationContext.getRealPathFromURI(mUri!!) ?: ""
if (path != mUri.toString() && path.isNotEmpty()) {
scanPath(mUri!!.path) {}
scanPath(mUri!!.path)
sendViewPagerIntent(path)
finish()
return

View file

@ -194,7 +194,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}
reloadViewPager()
scanPath(mPath) {}
scanPath(mPath)
if (config.darkBackground)
view_pager.background = ColorDrawable(Color.BLACK)
@ -525,10 +525,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}
if (tmpFile.length() > 0 && newFile.exists()) {
deleteFile(newFile) {}
deleteFile(newFile)
}
copyFile(tmpFile, newFile)
scanFile(newFile) {}
scanFile(newFile)
toast(R.string.file_saved)
if (config.keepLastModified) {
@ -553,7 +553,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} catch (e: Exception) {
showErrorToast(e)
} finally {
deleteFile(tmpFile) {}
deleteFile(tmpFile)
}
}
@ -794,10 +794,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun deleteDirectoryIfEmpty() {
val file = File(mDirectory)
if (config.deleteEmptyFolders && !file.isDownloadsFolder() && file.isDirectory && file.listFiles()?.isEmpty() == true) {
deleteFile(file, true) {}
deleteFile(file, true)
}
scanPath(mDirectory) {}
scanPath(mDirectory)
}
private fun checkOrientation() {

View file

@ -173,7 +173,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
Thread({
getSelectedMedia().forEach {
val oldFile = File(it.path)
activity.toggleFileVisibility(oldFile, hide) {}
activity.toggleFileVisibility(oldFile, hide)
}
activity.runOnUiThread {
listener?.refreshItems()

View file

@ -116,14 +116,14 @@ fun SimpleActivity.addNoMedia(path: String, callback: () -> Unit) {
}
}
fun SimpleActivity.removeNoMedia(path: String, callback: () -> Unit) {
fun SimpleActivity.removeNoMedia(path: String, callback: (() -> Unit)? = null) {
val file = File(path, NOMEDIA)
deleteFile(file) {
callback()
callback?.invoke()
}
}
fun SimpleActivity.toggleFileVisibility(oldFile: File, hide: Boolean, callback: (newFile: File) -> Unit) {
fun SimpleActivity.toggleFileVisibility(oldFile: File, hide: Boolean, callback: ((newFile: File) -> Unit)? = null) {
val path = oldFile.parent
var filename = oldFile.name
filename = if (hide) {
@ -133,7 +133,7 @@ fun SimpleActivity.toggleFileVisibility(oldFile: File, hide: Boolean, callback:
}
val newFile = File(path, filename)
renameFile(oldFile, newFile) {
callback(newFile)
callback?.invoke(newFile)
}
}

View file

@ -282,7 +282,7 @@ class MediaFetcher(val context: Context) {
val isAlreadyAdded = curMedia.any { it.path == file.absolutePath }
if (!isAlreadyAdded) {
curMedia.add(medium)
context.scanPath(file.absolutePath) {}
context.scanPath(file.absolutePath)
}
}
}