mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 13:08:00 +01:00
store media in a room db too
This commit is contained in:
parent
30ce207b1f
commit
ce4ee915bb
8 changed files with 63 additions and 18 deletions
|
@ -29,7 +29,7 @@ import com.simplemobiletools.gallery.BuildConfig
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.adapters.DirectoryAdapter
|
import com.simplemobiletools.gallery.adapters.DirectoryAdapter
|
||||||
import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask
|
import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask
|
||||||
import com.simplemobiletools.gallery.databases.DirectoryDataBase
|
import com.simplemobiletools.gallery.databases.GalleryDataBase
|
||||||
import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog
|
import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog
|
||||||
import com.simplemobiletools.gallery.dialogs.FilterMediaDialog
|
import com.simplemobiletools.gallery.dialogs.FilterMediaDialog
|
||||||
import com.simplemobiletools.gallery.extensions.*
|
import com.simplemobiletools.gallery.extensions.*
|
||||||
|
@ -63,7 +63,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
private var mTempShowHiddenHandler = Handler()
|
private var mTempShowHiddenHandler = Handler()
|
||||||
private var mCurrAsyncTask: GetDirectoriesAsynctask? = null
|
private var mCurrAsyncTask: GetDirectoriesAsynctask? = null
|
||||||
private var mZoomListener: MyRecyclerView.MyZoomListener? = null
|
private var mZoomListener: MyRecyclerView.MyZoomListener? = null
|
||||||
private var mDirsDB: DirectoryDataBase? = null
|
private var mGalleryDB: GalleryDataBase? = null
|
||||||
|
|
||||||
private var mStoredAnimateGifs = true
|
private var mStoredAnimateGifs = true
|
||||||
private var mStoredCropThumbnails = true
|
private var mStoredCropThumbnails = true
|
||||||
|
@ -91,7 +91,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
removeTempFolder()
|
removeTempFolder()
|
||||||
directories_refresh_layout.setOnRefreshListener { getDirectories() }
|
directories_refresh_layout.setOnRefreshListener { getDirectories() }
|
||||||
mDirs = ArrayList()
|
mDirs = ArrayList()
|
||||||
mDirsDB = DirectoryDataBase.getInstance(applicationContext)
|
mGalleryDB = GalleryDataBase.getInstance(applicationContext)
|
||||||
storeStateVariables()
|
storeStateVariables()
|
||||||
checkWhatsNewDialog()
|
checkWhatsNewDialog()
|
||||||
|
|
||||||
|
@ -557,9 +557,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
if (!isFromCache) {
|
if (!isFromCache) {
|
||||||
Thread {
|
Thread {
|
||||||
//checkFolderContentChange(newDirs)
|
//checkFolderContentChange(newDirs)
|
||||||
newDirs.forEach {
|
mGalleryDB!!.DirectoryDao().insertAll(newDirs)
|
||||||
mDirsDB!!.DirectoryDao().insert(it)
|
|
||||||
}
|
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ import com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.adapters.MediaAdapter
|
import com.simplemobiletools.gallery.adapters.MediaAdapter
|
||||||
import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask
|
import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask
|
||||||
|
import com.simplemobiletools.gallery.databases.GalleryDataBase
|
||||||
import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog
|
import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog
|
||||||
import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog
|
import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog
|
||||||
import com.simplemobiletools.gallery.dialogs.FilterMediaDialog
|
import com.simplemobiletools.gallery.dialogs.FilterMediaDialog
|
||||||
|
@ -62,6 +63,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
private var mCurrAsyncTask: GetMediaAsynctask? = null
|
private var mCurrAsyncTask: GetMediaAsynctask? = null
|
||||||
private var mZoomListener: MyRecyclerView.MyZoomListener? = null
|
private var mZoomListener: MyRecyclerView.MyZoomListener? = null
|
||||||
private var mSearchMenuItem: MenuItem? = null
|
private var mSearchMenuItem: MenuItem? = null
|
||||||
|
private var mGalleryDB: GalleryDataBase? = null
|
||||||
|
|
||||||
private var mStoredAnimateGifs = true
|
private var mStoredAnimateGifs = true
|
||||||
private var mStoredCropThumbnails = true
|
private var mStoredCropThumbnails = true
|
||||||
|
@ -94,8 +96,11 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
storeStateVariables()
|
storeStateVariables()
|
||||||
if (mShowAll)
|
mGalleryDB = GalleryDataBase.getInstance(applicationContext)
|
||||||
|
|
||||||
|
if (mShowAll) {
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(false)
|
supportActionBar?.setDisplayHomeAsUpEnabled(false)
|
||||||
|
}
|
||||||
|
|
||||||
media_empty_text.setOnClickListener {
|
media_empty_text.setOnClickListener {
|
||||||
showFilterMediaDialog()
|
showFilterMediaDialog()
|
||||||
|
@ -623,6 +628,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
Thread {
|
Thread {
|
||||||
mLatestMediaId = getLatestMediaId()
|
mLatestMediaId = getLatestMediaId()
|
||||||
mLatestMediaDateId = getLatestMediaByDateId()
|
mLatestMediaDateId = getLatestMediaByDateId()
|
||||||
|
if (!isFromCache) {
|
||||||
|
mGalleryDB!!.MediumDao().insertAll(media)
|
||||||
|
}
|
||||||
}.start()
|
}.start()
|
||||||
|
|
||||||
mIsGettingMedia = false
|
mIsGettingMedia = false
|
||||||
|
|
|
@ -90,7 +90,7 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
|
||||||
else -> TYPE_GIF
|
else -> TYPE_GIF
|
||||||
}
|
}
|
||||||
|
|
||||||
mMedium = Medium(getFilenameFromUri(mUri!!), mUri.toString(), 0, 0, file.length(), type)
|
mMedium = Medium(null, getFilenameFromUri(mUri!!), mUri.toString(), 0, 0, file.length(), type)
|
||||||
supportActionBar?.title = mMedium!!.name
|
supportActionBar?.title = mMedium!!.name
|
||||||
bundle.putSerializable(MEDIUM, mMedium)
|
bundle.putSerializable(MEDIUM, mMedium)
|
||||||
|
|
||||||
|
|
|
@ -5,20 +5,24 @@ import android.arch.persistence.room.Room
|
||||||
import android.arch.persistence.room.RoomDatabase
|
import android.arch.persistence.room.RoomDatabase
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.simplemobiletools.gallery.interfaces.DirectoryDao
|
import com.simplemobiletools.gallery.interfaces.DirectoryDao
|
||||||
|
import com.simplemobiletools.gallery.interfaces.MediumDao
|
||||||
import com.simplemobiletools.gallery.models.Directory
|
import com.simplemobiletools.gallery.models.Directory
|
||||||
|
import com.simplemobiletools.gallery.models.Medium
|
||||||
|
|
||||||
@Database(entities = [(Directory::class)], version = 1)
|
@Database(entities = [(Directory::class), (Medium::class)], version = 1)
|
||||||
abstract class DirectoryDataBase : RoomDatabase() {
|
abstract class GalleryDataBase : RoomDatabase() {
|
||||||
|
|
||||||
abstract fun DirectoryDao(): DirectoryDao
|
abstract fun DirectoryDao(): DirectoryDao
|
||||||
|
|
||||||
companion object {
|
abstract fun MediumDao(): MediumDao
|
||||||
private var INSTANCE: DirectoryDataBase? = null
|
|
||||||
|
|
||||||
fun getInstance(context: Context): DirectoryDataBase {
|
companion object {
|
||||||
|
private var INSTANCE: GalleryDataBase? = null
|
||||||
|
|
||||||
|
fun getInstance(context: Context): GalleryDataBase {
|
||||||
if (INSTANCE == null) {
|
if (INSTANCE == null) {
|
||||||
synchronized(DirectoryDataBase::class) {
|
synchronized(GalleryDataBase::class) {
|
||||||
INSTANCE = Room.databaseBuilder(context.applicationContext, DirectoryDataBase::class.java, "directories.db").build()
|
INSTANCE = Room.databaseBuilder(context.applicationContext, GalleryDataBase::class.java, "gallery.db").build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return INSTANCE!!
|
return INSTANCE!!
|
|
@ -247,7 +247,7 @@ class MediaFetcher(val context: Context) {
|
||||||
else -> TYPE_GIF
|
else -> TYPE_GIF
|
||||||
}
|
}
|
||||||
|
|
||||||
val medium = Medium(filename, file.absolutePath, dateModified, dateTaken, size, type)
|
val medium = Medium(null, filename, file.absolutePath, dateModified, dateTaken, size, type)
|
||||||
curMedia.add(medium)
|
curMedia.add(medium)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -296,7 +296,7 @@ class MediaFetcher(val context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGBasePath}%3A", OTG_PATH))
|
val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGBasePath}%3A", OTG_PATH))
|
||||||
val medium = Medium(filename, path, dateModified, dateTaken, size, type)
|
val medium = Medium(null, filename, path, dateModified, dateTaken, size, type)
|
||||||
curMedia.add(medium)
|
curMedia.add(medium)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,4 +13,7 @@ interface DirectoryDao {
|
||||||
|
|
||||||
@Insert(onConflict = REPLACE)
|
@Insert(onConflict = REPLACE)
|
||||||
fun insert(directory: Directory)
|
fun insert(directory: Directory)
|
||||||
|
|
||||||
|
@Insert(onConflict = REPLACE)
|
||||||
|
fun insertAll(directories: List<Directory>)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.simplemobiletools.gallery.interfaces
|
||||||
|
|
||||||
|
import android.arch.persistence.room.Dao
|
||||||
|
import android.arch.persistence.room.Insert
|
||||||
|
import android.arch.persistence.room.OnConflictStrategy.REPLACE
|
||||||
|
import android.arch.persistence.room.Query
|
||||||
|
import com.simplemobiletools.gallery.models.Medium
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface MediumDao {
|
||||||
|
@Query("SELECT * from media")
|
||||||
|
fun getAll(): List<Medium>
|
||||||
|
|
||||||
|
@Insert(onConflict = REPLACE)
|
||||||
|
fun insert(medium: Medium)
|
||||||
|
|
||||||
|
@Insert(onConflict = REPLACE)
|
||||||
|
fun insertAll(media: List<Medium>)
|
||||||
|
}
|
|
@ -1,5 +1,9 @@
|
||||||
package com.simplemobiletools.gallery.models
|
package com.simplemobiletools.gallery.models
|
||||||
|
|
||||||
|
import android.arch.persistence.room.ColumnInfo
|
||||||
|
import android.arch.persistence.room.Entity
|
||||||
|
import android.arch.persistence.room.Index
|
||||||
|
import android.arch.persistence.room.PrimaryKey
|
||||||
import com.simplemobiletools.commons.extensions.formatDate
|
import com.simplemobiletools.commons.extensions.formatDate
|
||||||
import com.simplemobiletools.commons.extensions.formatSize
|
import com.simplemobiletools.commons.extensions.formatSize
|
||||||
import com.simplemobiletools.commons.extensions.isDng
|
import com.simplemobiletools.commons.extensions.isDng
|
||||||
|
@ -9,7 +13,16 @@ import com.simplemobiletools.gallery.helpers.TYPE_IMAGE
|
||||||
import com.simplemobiletools.gallery.helpers.TYPE_VIDEO
|
import com.simplemobiletools.gallery.helpers.TYPE_VIDEO
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
|
||||||
data class Medium(var name: String, var path: String, val modified: Long, val taken: Long, val size: Long, val type: Int) : Serializable, Comparable<Medium> {
|
@Entity(tableName = "media", indices = [(Index(value = "path", unique = true))])
|
||||||
|
data class Medium(
|
||||||
|
@PrimaryKey(autoGenerate = true) var id: Long?,
|
||||||
|
@ColumnInfo(name = "filename") var name: String,
|
||||||
|
@ColumnInfo(name = "path") var path: String,
|
||||||
|
@ColumnInfo(name = "last_modified") val modified: Long,
|
||||||
|
@ColumnInfo(name = "date_taken") val taken: Long,
|
||||||
|
@ColumnInfo(name = "size") val size: Long,
|
||||||
|
@ColumnInfo(name = "type") val type: Int) : Serializable, Comparable<Medium> {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val serialVersionUID = -6553149366975455L
|
private const val serialVersionUID = -6553149366975455L
|
||||||
var sorting: Int = 0
|
var sorting: Int = 0
|
||||||
|
|
Loading…
Reference in a new issue