From cde57f35b84fa1ed52e5d810720838e137662e94 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 23 Apr 2018 23:05:57 +0200 Subject: [PATCH] store new images from refresh_media broadcast in the local db --- app/build.gradle | 2 +- .../gallery/receivers/RefreshMediaReceiver.kt | 29 +++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c1e93b509..61e0ff749 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' 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 7163a5af5..8b3f9921e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt @@ -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 } }