rename some media type related constants

This commit is contained in:
tibbi 2018-04-22 20:16:02 +02:00
parent 2eaff8568f
commit d0f4f0d403
9 changed files with 63 additions and 68 deletions

View file

@ -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)

View file

@ -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<Directo
dir_path?.text = "${directory.path.substringBeforeLast("/")}/"
photo_cnt.text = directory.mediaCnt.toString()
val thumbnailType = when {
directory.tmb.isImageFast() -> 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)

View file

@ -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<Medium>): 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

View file

@ -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,9 +16,9 @@ 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)
@ -32,11 +32,11 @@ class FilterMediaDialog(val activity: BaseSimpleActivity, val callback: (result:
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)

View file

@ -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<Directory>) -> Unit) {
var filteredDirectories = directories.filter { it.path.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden) } as ArrayList<Directory>
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<Directory>
callback(filteredDirectories)
@ -278,9 +278,9 @@ fun Context.getCachedMedia(path: String, callback: (ArrayList<Medium>) -> 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<Medium>
callback(filteredMedia)

View file

@ -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

View file

@ -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

View file

@ -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))

View file

@ -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()