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 d230fa2f6..6871069c2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt @@ -87,7 +87,8 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList val type = when { file.isImageFast() -> TYPE_IMAGES file.isVideoFast() -> TYPE_VIDEOS - else -> TYPE_GIFS + file.isGif() -> TYPE_GIFS + else -> TYPE_RAWS } mMedium = Medium(null, getFilenameFromUri(mUri!!), mUri.toString(), mUri!!.path.getParentPath(), 0, 0, file.length(), type) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index b85316f05..b44e0f7f4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -444,7 +444,8 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList TYPE_IMAGES directory.tmb.isVideoFast() -> TYPE_VIDEOS - else -> TYPE_GIFS + directory.tmb.isGif() -> TYPE_GIFS + else -> TYPE_RAWS } activity.loadImage(thumbnailType, directory.tmb, dir_thumbnail, scrollHorizontally, animateGifs, cropThumbnails) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/FilterMediaDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/FilterMediaDialog.kt index ec3cd7faa..4c1925b04 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/FilterMediaDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/FilterMediaDialog.kt @@ -7,6 +7,7 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.helpers.TYPE_GIFS import com.simplemobiletools.gallery.helpers.TYPE_IMAGES +import com.simplemobiletools.gallery.helpers.TYPE_RAWS import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS import kotlinx.android.synthetic.main.dialog_filter_media.view.* @@ -19,10 +20,11 @@ class FilterMediaDialog(val activity: BaseSimpleActivity, val callback: (result: filter_media_images.isChecked = filterMedia and TYPE_IMAGES != 0 filter_media_videos.isChecked = filterMedia and TYPE_VIDEOS != 0 filter_media_gifs.isChecked = filterMedia and TYPE_GIFS != 0 + filter_media_raws.isChecked = filterMedia and TYPE_RAWS != 0 } AlertDialog.Builder(activity) - .setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() }) + .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } .setNegativeButton(R.string.cancel, null) .create().apply { activity.setupDialogStuff(view, this, R.string.filter_media) @@ -37,6 +39,8 @@ class FilterMediaDialog(val activity: BaseSimpleActivity, val callback: (result: result += TYPE_VIDEOS if (view.filter_media_gifs.isChecked) result += TYPE_GIFS + if (view.filter_media_raws.isChecked) + result += TYPE_RAWS activity.config.filterMedia = result callback(result) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/ArrayList.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/ArrayList.kt index afd1c36e5..5d221bffa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/ArrayList.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/ArrayList.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.gallery.extensions import com.simplemobiletools.gallery.helpers.TYPE_GIFS import com.simplemobiletools.gallery.helpers.TYPE_IMAGES +import com.simplemobiletools.gallery.helpers.TYPE_RAWS import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS import com.simplemobiletools.gallery.models.Medium @@ -19,5 +20,9 @@ fun ArrayList.getDirMediaTypes(): Int { types += TYPE_GIFS } + if (any { it.isRaw() }) { + types += TYPE_RAWS + } + return types } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt index 9ed2214b5..cdcee9016 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -203,7 +203,7 @@ fun Context.checkAppendingHidden(path: String, hidden: String, includedFolders: fun Context.loadImage(type: Int, path: String, target: MySquareImageView, horizontalScroll: Boolean, animateGifs: Boolean, cropThumbnails: Boolean) { target.isHorizontalScrolling = horizontalScroll - if (type == TYPE_IMAGES || type == TYPE_VIDEOS) { + if (type == TYPE_IMAGES || type == TYPE_VIDEOS || type == TYPE_RAWS) { if (type == TYPE_IMAGES && path.isPng()) { loadPng(path, target, cropThumbnails) } else { @@ -289,7 +289,8 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly: else -> filteredDirectories.filter { (filterMedia and TYPE_IMAGES != 0 && it.types and TYPE_IMAGES != 0) || (filterMedia and TYPE_VIDEOS != 0 && it.types and TYPE_VIDEOS != 0) || - (filterMedia and TYPE_GIFS != 0 && it.types and TYPE_GIFS != 0) + (filterMedia and TYPE_GIFS != 0 && it.types and TYPE_GIFS != 0) || + (filterMedia and TYPE_RAWS != 0 && it.types and TYPE_RAWS != 0) } }) as ArrayList @@ -331,7 +332,8 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag else -> media.filter { (filterMedia and TYPE_IMAGES != 0 && it.type == TYPE_IMAGES) || (filterMedia and TYPE_VIDEOS != 0 && it.type == TYPE_VIDEOS) || - (filterMedia and TYPE_GIFS != 0 && it.type == TYPE_GIFS) + (filterMedia and TYPE_GIFS != 0 && it.type == TYPE_GIFS) || + (filterMedia and TYPE_RAWS != 0 && it.type == TYPE_RAWS) } }) as ArrayList diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt index f52fc5215..1b04f99c3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -151,7 +151,7 @@ class Config(context: Context) : BaseConfig(context) { set(darkBackground) = prefs.edit().putBoolean(DARK_BACKGROUND, darkBackground).apply() var filterMedia: Int - get() = prefs.getInt(FILTER_MEDIA, TYPE_IMAGES or TYPE_VIDEOS or TYPE_GIFS) + get() = prefs.getInt(FILTER_MEDIA, TYPE_IMAGES or TYPE_VIDEOS or TYPE_GIFS or TYPE_RAWS) set(filterMedia) = prefs.edit().putInt(FILTER_MEDIA, filterMedia).apply() var dirColumnCnt: Int diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index e3b86de96..ceab93a20 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -104,6 +104,7 @@ const val EXT_ALBUM = 1024 const val TYPE_IMAGES = 1 const val TYPE_VIDEOS = 2 const val TYPE_GIFS = 4 +const val TYPE_RAWS = 8 const val LOCAITON_INTERNAL = 1 const val LOCATION_SD = 2 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 13e3b826a..f5d989c50 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -70,6 +70,12 @@ class MediaFetcher(val context: Context) { query.append("${MediaStore.Images.Media.DATA} LIKE ?") } + if (filterMedia and TYPE_RAWS != 0) { + rawExtensions.forEach { + query.append("${MediaStore.Images.Media.DATA} LIKE ? OR ") + } + } + var selectionQuery = query.toString().trim().removeSuffix("OR") selectionQuery += ") AND " return selectionQuery @@ -93,6 +99,12 @@ class MediaFetcher(val context: Context) { args.add("%.gif") } + if (filterMedia and TYPE_RAWS != 0) { + rawExtensions.forEach { + args.add("%$it") + } + } + return args } @@ -160,8 +172,9 @@ class MediaFetcher(val context: Context) { val isImage = filename.isImageFast() val isVideo = if (isImage) false else filename.isVideoFast() val isGif = if (isImage || isVideo) false else filename.isGif() + val isRaw = if (isImage || isVideo || isGif) false else filename.isRaw() - if (!isImage && !isVideo && !isGif) + if (!isImage && !isVideo && !isGif && !isRaw) continue if (isVideo && (isPickImage || filterMedia and TYPE_VIDEOS == 0)) @@ -173,6 +186,9 @@ class MediaFetcher(val context: Context) { if (isGif && filterMedia and TYPE_GIFS == 0) continue + if (isRaw && filterMedia and TYPE_RAWS == 0) + continue + if (!showHidden && filename.startsWith('.')) continue @@ -190,7 +206,8 @@ class MediaFetcher(val context: Context) { val type = when { isImage -> TYPE_IMAGES isVideo -> TYPE_VIDEOS - else -> TYPE_GIFS + isGif -> TYPE_GIFS + else -> TYPE_RAWS } val medium = Medium(null, filename, file.absolutePath, folder, lastModified, dateTaken, size, type) @@ -214,8 +231,9 @@ class MediaFetcher(val context: Context) { val isImage = filename.isImageFast() val isVideo = if (isImage) false else filename.isVideoFast() val isGif = if (isImage || isVideo) false else filename.isGif() + val isRaw = if (isImage || isVideo || isGif) false else filename.isRaw() - if (!isImage && !isVideo && !isGif) + if (!isImage && !isVideo && !isGif || !isRaw) continue if (isVideo && (isPickImage || filterMedia and TYPE_VIDEOS == 0)) @@ -227,6 +245,9 @@ class MediaFetcher(val context: Context) { if (isGif && filterMedia and TYPE_GIFS == 0) continue + if (isRaw && filterMedia and TYPE_RAWS == 0) + continue + if (!showHidden && filename.startsWith('.')) continue @@ -240,7 +261,8 @@ class MediaFetcher(val context: Context) { val type = when { isImage -> TYPE_IMAGES isVideo -> TYPE_VIDEOS - else -> TYPE_GIFS + isGif -> TYPE_GIFS + else -> TYPE_RAWS } val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGTreeUri}/document/${context.config.OTGPartition}%3A", OTG_PATH)) 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 d4f2b953e..9fe49658b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -6,13 +6,13 @@ import android.arch.persistence.room.Index import android.arch.persistence.room.PrimaryKey import com.simplemobiletools.commons.extensions.formatDate import com.simplemobiletools.commons.extensions.formatSize -import com.simplemobiletools.commons.extensions.isRaw import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED import com.simplemobiletools.commons.helpers.SORT_BY_NAME import com.simplemobiletools.commons.helpers.SORT_BY_PATH import com.simplemobiletools.commons.helpers.SORT_BY_SIZE import com.simplemobiletools.gallery.helpers.TYPE_GIFS import com.simplemobiletools.gallery.helpers.TYPE_IMAGES +import com.simplemobiletools.gallery.helpers.TYPE_RAWS import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS import java.io.Serializable @@ -37,7 +37,7 @@ data class Medium( fun isVideo() = type == TYPE_VIDEOS - fun isRaw() = path.isRaw() + fun isRaw() = type == TYPE_RAWS fun getBubbleText(sorting: Int) = when { sorting and SORT_BY_NAME != 0 -> name 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 8b3f9921e..f90441e46 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt @@ -3,14 +3,12 @@ package com.simplemobiletools.gallery.receivers import android.content.BroadcastReceiver import android.content.Context import android.content.Intent -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.extensions.* 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_RAWS import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS import com.simplemobiletools.gallery.models.Medium import java.io.File @@ -29,6 +27,7 @@ class RefreshMediaReceiver : BroadcastReceiver() { private fun getFileType(path: String) = when { path.isImageFast() -> TYPE_IMAGES path.isVideoFast() -> TYPE_VIDEOS - else -> TYPE_GIFS + path.isGif() -> TYPE_GIFS + else -> TYPE_RAWS } } diff --git a/app/src/main/res/layout/dialog_filter_media.xml b/app/src/main/res/layout/dialog_filter_media.xml index 37f2aba11..1554adec9 100644 --- a/app/src/main/res/layout/dialog_filter_media.xml +++ b/app/src/main/res/layout/dialog_filter_media.xml @@ -33,4 +33,12 @@ android:paddingTop="@dimen/activity_margin" android:text="@string/gifs"/> + +