mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-30 00:17:58 +01:00
store new images from refresh_media broadcast in the local db
This commit is contained in:
parent
a6437181cb
commit
cde57f35b8
2 changed files with 25 additions and 6 deletions
|
@ -47,7 +47,7 @@ ext {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:3.19.9'
|
||||
implementation 'com.simplemobiletools:commons:3.19.10'
|
||||
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
|
||||
implementation 'com.android.support:multidex:1.0.3'
|
||||
implementation 'it.sephiroth.android.exif:library:1.0.1'
|
||||
|
|
|
@ -3,13 +3,32 @@ package com.simplemobiletools.gallery.receivers
|
|||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask
|
||||
import com.simplemobiletools.gallery.extensions.storeDirectoryItems
|
||||
import com.simplemobiletools.commons.extensions.getFilenameFromPath
|
||||
import com.simplemobiletools.commons.extensions.getParentPath
|
||||
import com.simplemobiletools.commons.extensions.isImageFast
|
||||
import com.simplemobiletools.commons.extensions.isVideoFast
|
||||
import com.simplemobiletools.commons.helpers.REFRESH_PATH
|
||||
import com.simplemobiletools.gallery.extensions.galleryDB
|
||||
import com.simplemobiletools.gallery.helpers.TYPE_GIFS
|
||||
import com.simplemobiletools.gallery.helpers.TYPE_IMAGES
|
||||
import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS
|
||||
import com.simplemobiletools.gallery.models.Medium
|
||||
import java.io.File
|
||||
|
||||
class RefreshMediaReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
GetDirectoriesAsynctask(context, false, false) {
|
||||
context.storeDirectoryItems(it)
|
||||
}.execute()
|
||||
val path = intent.getStringExtra(REFRESH_PATH) ?: return
|
||||
|
||||
Thread {
|
||||
val medium = Medium(null, path.getFilenameFromPath(), path, path.getParentPath(), System.currentTimeMillis(), System.currentTimeMillis(),
|
||||
File(path).length(), getFileType(path))
|
||||
context.galleryDB.MediumDao().insert(medium)
|
||||
}.start()
|
||||
}
|
||||
|
||||
private fun getFileType(path: String) = when {
|
||||
path.isImageFast() -> TYPE_IMAGES
|
||||
path.isVideoFast() -> TYPE_VIDEOS
|
||||
else -> TYPE_GIFS
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue