add a new field to media, the timestamp of their move to recycle bin

This commit is contained in:
tibbi 2018-06-27 09:51:33 +02:00
parent 3468a9860b
commit f7e7482fc8
6 changed files with 14 additions and 10 deletions

View File

@ -95,7 +95,7 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
else -> TYPE_RAWS
}
mMedium = Medium(null, getFilenameFromUri(mUri!!), mUri.toString(), mUri!!.path.getParentPath(), 0, 0, file.length(), type, false)
mMedium = Medium(null, getFilenameFromUri(mUri!!), mUri.toString(), mUri!!.path.getParentPath(), 0, 0, file.length(), type, false, 0)
supportActionBar?.title = mMedium!!.name
bundle.putSerializable(MEDIUM, mMedium)

View File

@ -9,7 +9,7 @@ import com.simplemobiletools.gallery.interfaces.MediumDao
import com.simplemobiletools.gallery.models.Directory
import com.simplemobiletools.gallery.models.Medium
@Database(entities = [(Directory::class), (Medium::class)], version = 3)
@Database(entities = [(Directory::class), (Medium::class)], version = 4)
abstract class GalleryDatabase : RoomDatabase() {
abstract fun DirectoryDao(): DirectoryDao

View File

@ -224,7 +224,7 @@ class MediaFetcher(val context: Context) {
val path = file.absolutePath
val isFavorite = favoritePaths.contains(path)
val medium = Medium(null, filename, path, file.parent, lastModified, dateTaken, size, type, isFavorite)
val medium = Medium(null, filename, path, file.parent, lastModified, dateTaken, size, type, isFavorite, 0)
media.add(medium)
}
return media
@ -281,7 +281,7 @@ class MediaFetcher(val context: Context) {
val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGTreeUri}/document/${context.config.OTGPartition}%3A", OTG_PATH))
val isFavorite = favoritePaths.contains(path)
val medium = Medium(null, filename, path, folder, dateModified, dateTaken, size, type, isFavorite)
val medium = Medium(null, filename, path, folder, dateModified, dateTaken, size, type, isFavorite, 0)
media.add(medium)
}

View File

@ -8,15 +8,18 @@ import com.simplemobiletools.gallery.models.Medium
@Dao
interface MediumDao {
@Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, is_favorite FROM media WHERE parent_path = :path COLLATE NOCASE")
@Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, is_favorite, deleted_ts FROM media WHERE deleted_ts = 0 AND parent_path = :path COLLATE NOCASE")
fun getMediaFromPath(path: String): List<Medium>
@Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, is_favorite FROM media WHERE is_favorite = 1")
@Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, is_favorite, deleted_ts FROM media WHERE deleted_ts = 0 AND is_favorite = 1")
fun getFavorites(): List<Medium>
@Query("SELECT full_path FROM media WHERE is_favorite = 1")
@Query("SELECT full_path FROM media WHERE deleted_ts = 0 AND is_favorite = 1")
fun getFavoritePaths(): List<String>
@Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, is_favorite, deleted_ts FROM media WHERE deleted_ts != 0")
fun getDeletedMedia(): List<Medium>
@Insert(onConflict = REPLACE)
fun insert(medium: Medium)

View File

@ -25,10 +25,11 @@ data class Medium(
@ColumnInfo(name = "date_taken") var taken: Long,
@ColumnInfo(name = "size") val size: Long,
@ColumnInfo(name = "type") val type: Int,
@ColumnInfo(name = "is_favorite") var isFavorite: Boolean) : Serializable, ThumbnailItem() {
@ColumnInfo(name = "is_favorite") var isFavorite: Boolean,
@ColumnInfo(name = "deleted_ts") var deletedTS: Int) : Serializable, ThumbnailItem() {
companion object {
private const val serialVersionUID = -6553149366975455L
private const val serialVersionUID = -6553149366975655L
}
fun isGif() = type == TYPE_GIFS

View File

@ -19,7 +19,7 @@ class RefreshMediaReceiver : BroadcastReceiver() {
Thread {
val medium = Medium(null, path.getFilenameFromPath(), path, path.getParentPath(), System.currentTimeMillis(), System.currentTimeMillis(),
File(path).length(), getFileType(path), false)
File(path).length(), getFileType(path), false, 0)
context.galleryDB.MediumDao().insert(medium)
}.start()
}