From d0f4f0d403a34b4c9b835924a3d5f76d4f594397 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 22 Apr 2018 20:16:02 +0200 Subject: [PATCH] rename some media type related constants --- .../gallery/activities/PhotoVideoActivity.kt | 6 ++-- .../gallery/adapters/DirectoryAdapter.kt | 12 +++---- .../asynctasks/GetDirectoriesAsynctask.kt | 12 +++---- .../gallery/dialogs/FilterMediaDialog.kt | 22 ++++++------ .../gallery/extensions/Context.kt | 18 +++++----- .../gallery/helpers/Config.kt | 2 +- .../gallery/helpers/Constants.kt | 11 ++---- .../gallery/helpers/MediaFetcher.kt | 36 +++++++++---------- .../gallery/models/Medium.kt | 12 +++---- 9 files changed, 63 insertions(+), 68 deletions(-) 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 0e16febe8..3cd1fcecc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt @@ -85,9 +85,9 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList val bundle = Bundle() val file = File(mUri.toString()) val type = when { - file.isImageFast() -> TYPE_IMAGE - file.isVideoFast() -> TYPE_VIDEO - else -> TYPE_GIF + file.isImageFast() -> TYPE_IMAGES + file.isVideoFast() -> TYPE_VIDEOS + else -> TYPE_GIFS } 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 96cddb557..1d0529e1c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -19,9 +19,9 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog import com.simplemobiletools.gallery.dialogs.PickMediumDialog import com.simplemobiletools.gallery.extensions.* -import com.simplemobiletools.gallery.helpers.TYPE_GIF -import com.simplemobiletools.gallery.helpers.TYPE_IMAGE -import com.simplemobiletools.gallery.helpers.TYPE_VIDEO +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.helpers.VIEW_TYPE_LIST import com.simplemobiletools.gallery.models.AlbumCover import com.simplemobiletools.gallery.models.Directory @@ -413,9 +413,9 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList TYPE_IMAGE - directory.tmb.isVideoFast() -> TYPE_VIDEO - else -> TYPE_GIF + directory.tmb.isImageFast() -> TYPE_IMAGES + directory.tmb.isVideoFast() -> TYPE_VIDEOS + else -> TYPE_GIFS } activity.loadImage(thumbnailType, directory.tmb, dir_thumbnail, scrollHorizontally, animateGifs, cropThumbnails) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt index 2ae5d3b46..f3c06916a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -10,10 +10,10 @@ import com.simplemobiletools.commons.helpers.sumByLong import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.extensions.checkAppendingHidden import com.simplemobiletools.gallery.extensions.config -import com.simplemobiletools.gallery.helpers.GIFS -import com.simplemobiletools.gallery.helpers.IMAGES import com.simplemobiletools.gallery.helpers.MediaFetcher -import com.simplemobiletools.gallery.helpers.VIDEOS +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.Directory import com.simplemobiletools.gallery.models.Medium import java.io.File @@ -74,15 +74,15 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va private fun getDirMediaTypes(media: ArrayList): Int { var types = 0 if (media.any { it.isImage() }) { - types += IMAGES + types += TYPE_IMAGES } if (media.any { it.isVideo() }) { - types += VIDEOS + types += TYPE_VIDEOS } if (media.any { it.isGif() }) { - types += GIFS + types += TYPE_GIFS } return types 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 b1f10323f..ec3cd7faa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/FilterMediaDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/FilterMediaDialog.kt @@ -5,9 +5,9 @@ import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.extensions.config -import com.simplemobiletools.gallery.helpers.GIFS -import com.simplemobiletools.gallery.helpers.IMAGES -import com.simplemobiletools.gallery.helpers.VIDEOS +import com.simplemobiletools.gallery.helpers.TYPE_GIFS +import com.simplemobiletools.gallery.helpers.TYPE_IMAGES +import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS import kotlinx.android.synthetic.main.dialog_filter_media.view.* class FilterMediaDialog(val activity: BaseSimpleActivity, val callback: (result: Int) -> Unit) { @@ -16,27 +16,27 @@ class FilterMediaDialog(val activity: BaseSimpleActivity, val callback: (result: init { val filterMedia = activity.config.filterMedia view.apply { - filter_media_images.isChecked = filterMedia and IMAGES != 0 - filter_media_videos.isChecked = filterMedia and VIDEOS != 0 - filter_media_gifs.isChecked = filterMedia and GIFS != 0 + 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 } AlertDialog.Builder(activity) .setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() }) .setNegativeButton(R.string.cancel, null) .create().apply { - activity.setupDialogStuff(view, this, R.string.filter_media) - } + activity.setupDialogStuff(view, this, R.string.filter_media) + } } private fun dialogConfirmed() { var result = 0 if (view.filter_media_images.isChecked) - result += IMAGES + result += TYPE_IMAGES if (view.filter_media_videos.isChecked) - result += VIDEOS + result += TYPE_VIDEOS if (view.filter_media_gifs.isChecked) - result += GIFS + result += TYPE_GIFS activity.config.filterMedia = result callback(result) 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 0a0209975..6d8c64bb7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -183,13 +183,13 @@ 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_IMAGE || type == TYPE_VIDEO) { - if (type == TYPE_IMAGE && path.isPng()) { + if (type == TYPE_IMAGES || type == TYPE_VIDEOS) { + if (type == TYPE_IMAGES && path.isPng()) { loadPng(path, target, cropThumbnails) } else { loadJpg(path, target, cropThumbnails) } - } else if (type == TYPE_GIF) { + } else if (type == TYPE_GIFS) { try { val gifDrawable = GifDrawable(path) target.setImageDrawable(gifDrawable) @@ -255,9 +255,9 @@ fun Context.getCachedDirectories(callback: (ArrayList) -> Unit) { var filteredDirectories = directories.filter { it.path.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden) } as ArrayList val filterMedia = config.filterMedia filteredDirectories = filteredDirectories.filter { - (filterMedia and IMAGES != 0 && it.types == TYPE_IMAGE) || - (filterMedia and VIDEOS != 0 && it.types == TYPE_VIDEO) || - (filterMedia and GIFS != 0 && it.types == TYPE_GIF) + (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) } as ArrayList callback(filteredDirectories) @@ -278,9 +278,9 @@ fun Context.getCachedMedia(path: String, callback: (ArrayList) -> Unit) val filterMedia = config.filterMedia filteredMedia = filteredMedia.filter { - (filterMedia and IMAGES != 0 && it.type == TYPE_IMAGE) || - (filterMedia and VIDEOS != 0 && it.type == TYPE_VIDEO) || - (filterMedia and GIFS != 0 && it.type == TYPE_GIF) + (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) } as ArrayList callback(filteredMedia) 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 cc9d07b0f..86cd7caf8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -164,7 +164,7 @@ class Config(context: Context) : BaseConfig(context) { set(darkBackground) = prefs.edit().putBoolean(DARK_BACKGROUND, darkBackground).apply() var filterMedia: Int - get() = prefs.getInt(FILTER_MEDIA, IMAGES or VIDEOS or GIFS) + get() = prefs.getInt(FILTER_MEDIA, TYPE_IMAGES or TYPE_VIDEOS or TYPE_GIFS) 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 adff9c62b..d75ce223d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -81,11 +81,6 @@ const val ROTATE_BY_SYSTEM_SETTING = 0 const val ROTATE_BY_DEVICE_ROTATION = 1 const val ROTATE_BY_ASPECT_RATIO = 2 -// filter media -const val IMAGES = 1 -const val VIDEOS = 2 -const val GIFS = 4 - // view types const val VIEW_TYPE_GRID = 1 const val VIEW_TYPE_LIST = 2 @@ -104,6 +99,6 @@ const val EXT_ARTIST = 512 const val EXT_ALBUM = 1024 // media types -const val TYPE_IMAGE = 1 -const val TYPE_VIDEO = 2 -const val TYPE_GIF = 3 +const val TYPE_IMAGES = 1 +const val TYPE_VIDEOS = 2 +const val TYPE_GIFS = 4 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 2068d35c0..172bbcc81 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -58,19 +58,19 @@ class MediaFetcher(val context: Context) { } query.append("(") - if (filterMedia and IMAGES != 0) { + if (filterMedia and TYPE_IMAGES != 0) { photoExtensions.forEach { query.append("${MediaStore.Images.Media.DATA} LIKE ? OR ") } } - if (filterMedia and VIDEOS != 0) { + if (filterMedia and TYPE_VIDEOS != 0) { videoExtensions.forEach { query.append("${MediaStore.Images.Media.DATA} LIKE ? OR ") } } - if (filterMedia and GIFS != 0) { + if (filterMedia and TYPE_GIFS != 0) { query.append("${MediaStore.Images.Media.DATA} LIKE ?") } @@ -86,19 +86,19 @@ class MediaFetcher(val context: Context) { args.add("$path/%/%") } - if (filterMedia and IMAGES != 0) { + if (filterMedia and TYPE_IMAGES != 0) { photoExtensions.forEach { args.add("%$it") } } - if (filterMedia and VIDEOS != 0) { + if (filterMedia and TYPE_VIDEOS != 0) { videoExtensions.forEach { args.add("%$it") } } - if (filterMedia and GIFS != 0) { + if (filterMedia and TYPE_GIFS != 0) { args.add("%.gif") } @@ -200,13 +200,13 @@ class MediaFetcher(val context: Context) { if (!isImage && !isVideo && !isGif) continue - if (isVideo && (isPickImage || filterMedia and VIDEOS == 0)) + if (isVideo && (isPickImage || filterMedia and TYPE_VIDEOS == 0)) continue - if (isImage && (isPickVideo || filterMedia and IMAGES == 0)) + if (isImage && (isPickVideo || filterMedia and TYPE_IMAGES == 0)) continue - if (isGif && filterMedia and GIFS == 0) + if (isGif && filterMedia and TYPE_GIFS == 0) continue if (!showHidden && filename.startsWith('.')) @@ -220,9 +220,9 @@ class MediaFetcher(val context: Context) { val dateModified = file.lastModified() val type = when { - isImage -> TYPE_IMAGE - isVideo -> TYPE_VIDEO - else -> TYPE_GIF + isImage -> TYPE_IMAGES + isVideo -> TYPE_VIDEOS + else -> TYPE_GIFS } val medium = Medium(null, filename, file.absolutePath, folder, dateModified, dateTaken, size, type) @@ -248,13 +248,13 @@ class MediaFetcher(val context: Context) { if (!isImage && !isVideo && !isGif) continue - if (isVideo && (isPickImage || filterMedia and VIDEOS == 0)) + if (isVideo && (isPickImage || filterMedia and TYPE_VIDEOS == 0)) continue - if (isImage && (isPickVideo || filterMedia and IMAGES == 0)) + if (isImage && (isPickVideo || filterMedia and TYPE_IMAGES == 0)) continue - if (isGif && filterMedia and GIFS == 0) + if (isGif && filterMedia and TYPE_GIFS == 0) continue if (!showHidden && filename.startsWith('.')) @@ -268,9 +268,9 @@ class MediaFetcher(val context: Context) { val dateModified = file.lastModified() val type = when { - isImage -> TYPE_IMAGE - isVideo -> TYPE_VIDEO - else -> TYPE_GIF + isImage -> TYPE_IMAGES + isVideo -> TYPE_VIDEOS + else -> TYPE_GIFS } val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGBasePath}%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 5dbfefcc2..2327feadb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -8,9 +8,9 @@ import com.simplemobiletools.commons.extensions.formatDate import com.simplemobiletools.commons.extensions.formatSize import com.simplemobiletools.commons.extensions.isDng import com.simplemobiletools.commons.helpers.* -import com.simplemobiletools.gallery.helpers.TYPE_GIF -import com.simplemobiletools.gallery.helpers.TYPE_IMAGE -import com.simplemobiletools.gallery.helpers.TYPE_VIDEO +import com.simplemobiletools.gallery.helpers.TYPE_GIFS +import com.simplemobiletools.gallery.helpers.TYPE_IMAGES +import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS import java.io.Serializable @Entity(tableName = "media", indices = [(Index(value = "full_path", unique = true))]) @@ -29,11 +29,11 @@ data class Medium( var sorting: Int = 0 } - fun isGif() = type == TYPE_GIF + fun isGif() = type == TYPE_GIFS - fun isImage() = type == TYPE_IMAGE + fun isImage() = type == TYPE_IMAGES - fun isVideo() = type == TYPE_VIDEO + fun isVideo() = type == TYPE_VIDEOS fun isDng() = path.isDng()