handle deleting folders from local db

This commit is contained in:
tibbi 2018-04-20 13:20:44 +02:00
parent 5b8143d41e
commit 73ac822661
3 changed files with 19 additions and 1 deletions

View file

@ -362,6 +362,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
runOnUiThread {
refreshItems()
}
Thread {
folders.filter { !it.exists() }.forEach {
galleryDB.DirectoryDao().deleteDirPath(it.absolutePath)
}
}.start()
}
}

View file

@ -246,7 +246,13 @@ fun Activity.loadJpg(path: String, target: MySquareImageView, cropThumbnails: Bo
fun Activity.getCachedDirectories(callback: (ArrayList<Directory>) -> Unit) {
Thread {
callback(galleryDB.DirectoryDao().getAll() as ArrayList<Directory>)
val directoryDao = galleryDB.DirectoryDao()
val directories = directoryDao.getAll() as ArrayList<Directory>
callback(directories)
directories.filter { !File(it.path).exists() }.forEach {
directoryDao.deleteDir(it)
}
}.start()
}

View file

@ -1,6 +1,7 @@
package com.simplemobiletools.gallery.interfaces
import android.arch.persistence.room.Dao
import android.arch.persistence.room.Delete
import android.arch.persistence.room.Insert
import android.arch.persistence.room.OnConflictStrategy.REPLACE
import android.arch.persistence.room.Query
@ -16,4 +17,10 @@ interface DirectoryDao {
@Insert(onConflict = REPLACE)
fun insertAll(directories: List<Directory>)
@Delete
fun deleteDir(directory: Directory)
@Query("DELETE FROM directories WHERE path = :path")
fun deleteDirPath(path: String)
}