mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
adding a new MediaStoreId field to Medium model
This commit is contained in:
parent
8ec9e70df8
commit
d4bf065cb5
7 changed files with 23 additions and 12 deletions
|
@ -149,7 +149,7 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
|
||||||
}
|
}
|
||||||
|
|
||||||
mIsVideo = type == TYPE_VIDEOS
|
mIsVideo = type == TYPE_VIDEOS
|
||||||
mMedium = Medium(null, filename, mUri.toString(), mUri!!.path!!.getParentPath(), 0, 0, file.length(), type, 0, false, 0L)
|
mMedium = Medium(null, filename, mUri.toString(), mUri!!.path!!.getParentPath(), 0, 0, file.length(), type, 0, false, 0L, 0)
|
||||||
supportActionBar?.title = mMedium!!.name
|
supportActionBar?.title = mMedium!!.name
|
||||||
bundle.putSerializable(MEDIUM, mMedium)
|
bundle.putSerializable(MEDIUM, mMedium)
|
||||||
|
|
||||||
|
|
|
@ -407,7 +407,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
val duration = if (type == TYPE_VIDEOS) getDuration(mPath) ?: 0 else 0
|
val duration = if (type == TYPE_VIDEOS) getDuration(mPath) ?: 0 else 0
|
||||||
val ts = System.currentTimeMillis()
|
val ts = System.currentTimeMillis()
|
||||||
val medium =
|
val medium =
|
||||||
Medium(null, mPath.getFilenameFromPath(), mPath, mPath.getParentPath(), ts, ts, File(mPath).length(), type, duration, isFavorite, 0)
|
Medium(null, mPath.getFilenameFromPath(), mPath, mPath.getParentPath(), ts, ts, File(mPath).length(), type, duration, isFavorite, 0, 0L)
|
||||||
mediaDB.insert(medium)
|
mediaDB.insert(medium)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
import com.simplemobiletools.gallery.pro.interfaces.*
|
import com.simplemobiletools.gallery.pro.interfaces.*
|
||||||
import com.simplemobiletools.gallery.pro.models.*
|
import com.simplemobiletools.gallery.pro.models.*
|
||||||
|
|
||||||
@Database(entities = [Directory::class, Medium::class, Widget::class, DateTaken::class, Favorite::class], version = 9)
|
@Database(entities = [Directory::class, Medium::class, Widget::class, DateTaken::class, Favorite::class], version = 10)
|
||||||
abstract class GalleryDatabase : RoomDatabase() {
|
abstract class GalleryDatabase : RoomDatabase() {
|
||||||
|
|
||||||
abstract fun DirectoryDao(): DirectoryDao
|
abstract fun DirectoryDao(): DirectoryDao
|
||||||
|
@ -36,6 +36,7 @@ abstract class GalleryDatabase : RoomDatabase() {
|
||||||
.addMigrations(MIGRATION_6_7)
|
.addMigrations(MIGRATION_6_7)
|
||||||
.addMigrations(MIGRATION_7_8)
|
.addMigrations(MIGRATION_7_8)
|
||||||
.addMigrations(MIGRATION_8_9)
|
.addMigrations(MIGRATION_8_9)
|
||||||
|
.addMigrations(MIGRATION_9_10)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,5 +85,11 @@ abstract class GalleryDatabase : RoomDatabase() {
|
||||||
database.execSQL("ALTER TABLE date_takens ADD COLUMN last_modified INTEGER default 0 NOT NULL")
|
database.execSQL("ALTER TABLE date_takens ADD COLUMN last_modified INTEGER default 0 NOT NULL")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val MIGRATION_9_10 = object : Migration(9, 10) {
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
database.execSQL("ALTER TABLE media ADD COLUMN media_store_id INTEGER default 0 NOT NULL")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -969,7 +969,7 @@ fun Context.addPathToDB(path: String) {
|
||||||
val videoDuration = if (type == TYPE_VIDEOS) getDuration(path) ?: 0 else 0
|
val videoDuration = if (type == TYPE_VIDEOS) getDuration(path) ?: 0 else 0
|
||||||
val medium = Medium(
|
val medium = Medium(
|
||||||
null, path.getFilenameFromPath(), path, path.getParentPath(), System.currentTimeMillis(), System.currentTimeMillis(),
|
null, path.getFilenameFromPath(), path, path.getParentPath(), System.currentTimeMillis(), System.currentTimeMillis(),
|
||||||
File(path).length(), type, videoDuration, isFavorite, 0L
|
File(path).length(), type, videoDuration, isFavorite, 0L, 0L
|
||||||
)
|
)
|
||||||
|
|
||||||
mediaDB.insert(medium)
|
mediaDB.insert(medium)
|
||||||
|
@ -1002,7 +1002,7 @@ fun Context.createDirectoryFromMedia(
|
||||||
}
|
}
|
||||||
|
|
||||||
val isSortingAscending = config.directorySorting.isSortingAscending()
|
val isSortingAscending = config.directorySorting.isSortingAscending()
|
||||||
val defaultMedium = Medium(0, "", "", "", 0L, 0L, 0L, 0, 0, false, 0L)
|
val defaultMedium = Medium(0, "", "", "", 0L, 0L, 0L, 0, 0, false, 0L, 0L)
|
||||||
val firstItem = curMedia.firstOrNull() ?: defaultMedium
|
val firstItem = curMedia.firstOrNull() ?: defaultMedium
|
||||||
val lastItem = curMedia.lastOrNull() ?: defaultMedium
|
val lastItem = curMedia.lastOrNull() ?: defaultMedium
|
||||||
val dirName = checkAppendingHidden(path, hiddenString, includedFolders, noMediaFolders)
|
val dirName = checkAppendingHidden(path, hiddenString, includedFolders, noMediaFolders)
|
||||||
|
|
|
@ -400,7 +400,7 @@ class MediaFetcher(val context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
val isFavorite = favoritePaths.contains(path)
|
val isFavorite = favoritePaths.contains(path)
|
||||||
val medium = Medium(null, filename, path, file.parent, lastModified, dateTaken, size, type, videoDuration, isFavorite, 0L)
|
val medium = Medium(null, filename, path, file.parent, lastModified, dateTaken, size, type, videoDuration, isFavorite, 0L, 0L)
|
||||||
media.add(medium)
|
media.add(medium)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -421,6 +421,7 @@ class MediaFetcher(val context: Context) {
|
||||||
val showHidden = context.config.shouldShowHidden
|
val showHidden = context.config.shouldShowHidden
|
||||||
|
|
||||||
val projection = arrayOf(
|
val projection = arrayOf(
|
||||||
|
Images.Media._ID,
|
||||||
Images.Media.DISPLAY_NAME,
|
Images.Media.DISPLAY_NAME,
|
||||||
Images.Media.DATA,
|
Images.Media.DATA,
|
||||||
Images.Media.DATE_MODIFIED,
|
Images.Media.DATE_MODIFIED,
|
||||||
|
@ -437,6 +438,7 @@ class MediaFetcher(val context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
val mediaStoreId = cursor.getLongValue(Images.Media._ID)
|
||||||
val filename = cursor.getStringValue(Images.Media.DISPLAY_NAME)
|
val filename = cursor.getStringValue(Images.Media.DISPLAY_NAME)
|
||||||
val path = cursor.getStringValue(Images.Media.DATA)
|
val path = cursor.getStringValue(Images.Media.DATA)
|
||||||
val lastModified = cursor.getLongValue(Images.Media.DATE_MODIFIED) * 1000
|
val lastModified = cursor.getLongValue(Images.Media.DATE_MODIFIED) * 1000
|
||||||
|
@ -487,7 +489,8 @@ class MediaFetcher(val context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
val isFavorite = favoritePaths.contains(path)
|
val isFavorite = favoritePaths.contains(path)
|
||||||
val medium = Medium(null, filename, path, path.getParentPath(), lastModified, dateTaken, size, type, videoDuration, isFavorite, 0L)
|
val medium =
|
||||||
|
Medium(null, filename, path, path.getParentPath(), lastModified, dateTaken, size, type, videoDuration, isFavorite, 0L, mediaStoreId)
|
||||||
val parent = medium.parentPath.lowercase(Locale.getDefault())
|
val parent = medium.parentPath.lowercase(Locale.getDefault())
|
||||||
val currentFolderMedia = media[parent]
|
val currentFolderMedia = media[parent]
|
||||||
if (currentFolderMedia == null) {
|
if (currentFolderMedia == null) {
|
||||||
|
@ -565,7 +568,7 @@ class MediaFetcher(val context: Context) {
|
||||||
)
|
)
|
||||||
val videoDuration = if (getVideoDurations) context.getDuration(path) ?: 0 else 0
|
val videoDuration = if (getVideoDurations) context.getDuration(path) ?: 0 else 0
|
||||||
val isFavorite = favoritePaths.contains(path)
|
val isFavorite = favoritePaths.contains(path)
|
||||||
val medium = Medium(null, filename, path, folder, dateModified, dateTaken, size, type, videoDuration, isFavorite, 0L)
|
val medium = Medium(null, filename, path, folder, dateModified, dateTaken, size, type, videoDuration, isFavorite, 0L, 0L)
|
||||||
media.add(medium)
|
media.add(medium)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,16 +9,16 @@ import com.simplemobiletools.gallery.pro.models.Medium
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface MediumDao {
|
interface MediumDao {
|
||||||
@Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, video_duration, is_favorite, deleted_ts FROM media WHERE deleted_ts = 0 AND parent_path = :path COLLATE NOCASE")
|
@Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, video_duration, is_favorite, deleted_ts, media_store_id FROM media WHERE deleted_ts = 0 AND parent_path = :path COLLATE NOCASE")
|
||||||
fun getMediaFromPath(path: String): List<Medium>
|
fun getMediaFromPath(path: String): List<Medium>
|
||||||
|
|
||||||
@Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, video_duration, is_favorite, deleted_ts FROM media WHERE deleted_ts = 0 AND is_favorite = 1")
|
@Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, video_duration, is_favorite, deleted_ts, media_store_id FROM media WHERE deleted_ts = 0 AND is_favorite = 1")
|
||||||
fun getFavorites(): List<Medium>
|
fun getFavorites(): List<Medium>
|
||||||
|
|
||||||
@Query("SELECT COUNT(filename) FROM media WHERE deleted_ts = 0 AND is_favorite = 1")
|
@Query("SELECT COUNT(filename) FROM media WHERE deleted_ts = 0 AND is_favorite = 1")
|
||||||
fun getFavoritesCount(): Long
|
fun getFavoritesCount(): Long
|
||||||
|
|
||||||
@Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, video_duration, is_favorite, deleted_ts FROM media WHERE deleted_ts != 0")
|
@Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, video_duration, is_favorite, deleted_ts, media_store_id FROM media WHERE deleted_ts != 0")
|
||||||
fun getDeletedMedia(): List<Medium>
|
fun getDeletedMedia(): List<Medium>
|
||||||
|
|
||||||
@Query("SELECT COUNT(filename) FROM media WHERE deleted_ts != 0")
|
@Query("SELECT COUNT(filename) FROM media WHERE deleted_ts != 0")
|
||||||
|
|
|
@ -26,11 +26,12 @@ data class Medium(
|
||||||
@ColumnInfo(name = "video_duration") var videoDuration: Int,
|
@ColumnInfo(name = "video_duration") var videoDuration: Int,
|
||||||
@ColumnInfo(name = "is_favorite") var isFavorite: Boolean,
|
@ColumnInfo(name = "is_favorite") var isFavorite: Boolean,
|
||||||
@ColumnInfo(name = "deleted_ts") var deletedTS: Long,
|
@ColumnInfo(name = "deleted_ts") var deletedTS: Long,
|
||||||
|
@ColumnInfo(name = "media_store_id") var mediaStoreId: Long,
|
||||||
|
|
||||||
@Ignore var gridPosition: Int = 0 // used at grid view decoration at Grouping enabled
|
@Ignore var gridPosition: Int = 0 // used at grid view decoration at Grouping enabled
|
||||||
) : Serializable, ThumbnailItem() {
|
) : Serializable, ThumbnailItem() {
|
||||||
|
|
||||||
constructor() : this(null, "", "", "", 0L, 0L, 0L, 0, 0, false, 0L, 0)
|
constructor() : this(null, "", "", "", 0L, 0L, 0L, 0, 0, false, 0L, 0L, 0)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val serialVersionUID = -6553149366975655L
|
private const val serialVersionUID = -6553149366975655L
|
||||||
|
|
Loading…
Reference in a new issue