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 { 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.davemorrissey.labs:subsampling-scale-image-view:3.7.2'
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

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

View file

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

View file

@ -347,7 +347,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
private fun deleteDirectoryIfEmpty() { private fun deleteDirectoryIfEmpty() {
val file = File(mPath) val file = File(mPath)
if (config.deleteEmptyFolders && !file.isDownloadsFolder() && file.isDirectory && file.listFiles()?.isEmpty() == true) { 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) mIsFromGallery = intent.getBooleanExtra(IS_FROM_GALLERY, false)
if (mUri!!.scheme == "file") { if (mUri!!.scheme == "file") {
scanPath(mUri!!.path) {} scanPath(mUri!!.path)
sendViewPagerIntent(mUri!!.path) sendViewPagerIntent(mUri!!.path)
finish() finish()
return return
} else { } else {
val path = applicationContext.getRealPathFromURI(mUri!!) ?: "" val path = applicationContext.getRealPathFromURI(mUri!!) ?: ""
if (path != mUri.toString() && path.isNotEmpty()) { if (path != mUri.toString() && path.isNotEmpty()) {
scanPath(mUri!!.path) {} scanPath(mUri!!.path)
sendViewPagerIntent(path) sendViewPagerIntent(path)
finish() finish()
return return

View file

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

View file

@ -173,7 +173,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
Thread({ Thread({
getSelectedMedia().forEach { getSelectedMedia().forEach {
val oldFile = File(it.path) val oldFile = File(it.path)
activity.toggleFileVisibility(oldFile, hide) {} activity.toggleFileVisibility(oldFile, hide)
} }
activity.runOnUiThread { activity.runOnUiThread {
listener?.refreshItems() 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) val file = File(path, NOMEDIA)
deleteFile(file) { 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 val path = oldFile.parent
var filename = oldFile.name var filename = oldFile.name
filename = if (hide) { filename = if (hide) {
@ -133,7 +133,7 @@ fun SimpleActivity.toggleFileVisibility(oldFile: File, hide: Boolean, callback:
} }
val newFile = File(path, filename) val newFile = File(path, filename)
renameFile(oldFile, newFile) { 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 } val isAlreadyAdded = curMedia.any { it.path == file.absolutePath }
if (!isAlreadyAdded) { if (!isAlreadyAdded) {
curMedia.add(medium) curMedia.add(medium)
context.scanPath(file.absolutePath) {} context.scanPath(file.absolutePath)
} }
} }
} }