handle deleting folders from local db
This commit is contained in:
parent
5b8143d41e
commit
73ac822661
3 changed files with 19 additions and 1 deletions
|
@ -362,6 +362,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
runOnUiThread {
|
||||
refreshItems()
|
||||
}
|
||||
Thread {
|
||||
folders.filter { !it.exists() }.forEach {
|
||||
galleryDB.DirectoryDao().deleteDirPath(it.absolutePath)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue