From f7e7482fc822a1ee64bc1ae7d8760759c4374f2a Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 27 Jun 2018 09:51:33 +0200 Subject: [PATCH] add a new field to media, the timestamp of their move to recycle bin --- .../gallery/activities/PhotoVideoActivity.kt | 2 +- .../gallery/databases/GalleryDatabase.kt | 2 +- .../simplemobiletools/gallery/helpers/MediaFetcher.kt | 4 ++-- .../simplemobiletools/gallery/interfaces/MediumDao.kt | 9 ++++++--- .../com/simplemobiletools/gallery/models/Medium.kt | 5 +++-- .../gallery/receivers/RefreshMediaReceiver.kt | 2 +- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt index 3d49e28c9..b3c139420 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt @@ -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) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/databases/GalleryDatabase.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/databases/GalleryDatabase.kt index 56896a30b..8f8df8e23 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/databases/GalleryDatabase.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/databases/GalleryDatabase.kt @@ -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 diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index fc29815ae..349cb9aee 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -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) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt index a5dd5e221..955513380 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt @@ -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 - @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 - @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 + @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 + @Insert(onConflict = REPLACE) fun insert(medium: Medium) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt index 66ce260fe..a942039cf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -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 diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt index 7e6de9293..8ec3929c5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt @@ -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() }