mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 04:57:59 +01:00
store the medium type in it, to improve performance
This commit is contained in:
parent
289c20a023
commit
8a31ad1b1c
9 changed files with 69 additions and 35 deletions
|
@ -9,10 +9,7 @@ import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
||||||
import com.simplemobiletools.commons.extensions.getFilenameFromUri
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.extensions.getRealPathFromURI
|
|
||||||
import com.simplemobiletools.commons.extensions.scanPath
|
|
||||||
import com.simplemobiletools.commons.extensions.toast
|
|
||||||
import com.simplemobiletools.commons.helpers.IS_FROM_GALLERY
|
import com.simplemobiletools.commons.helpers.IS_FROM_GALLERY
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
||||||
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
|
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
|
||||||
|
@ -21,9 +18,7 @@ import com.simplemobiletools.gallery.extensions.*
|
||||||
import com.simplemobiletools.gallery.fragments.PhotoFragment
|
import com.simplemobiletools.gallery.fragments.PhotoFragment
|
||||||
import com.simplemobiletools.gallery.fragments.VideoFragment
|
import com.simplemobiletools.gallery.fragments.VideoFragment
|
||||||
import com.simplemobiletools.gallery.fragments.ViewPagerFragment
|
import com.simplemobiletools.gallery.fragments.ViewPagerFragment
|
||||||
import com.simplemobiletools.gallery.helpers.IS_VIEW_INTENT
|
import com.simplemobiletools.gallery.helpers.*
|
||||||
import com.simplemobiletools.gallery.helpers.MEDIUM
|
|
||||||
import com.simplemobiletools.gallery.helpers.PATH
|
|
||||||
import com.simplemobiletools.gallery.models.Medium
|
import com.simplemobiletools.gallery.models.Medium
|
||||||
import kotlinx.android.synthetic.main.fragment_holder.*
|
import kotlinx.android.synthetic.main.fragment_holder.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -52,6 +47,14 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
supportActionBar?.setBackgroundDrawable(resources.getDrawable(R.drawable.actionbar_gradient_background))
|
||||||
|
if (config.blackBackground) {
|
||||||
|
updateStatusbarColor(Color.BLACK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun checkIntent(savedInstanceState: Bundle? = null) {
|
private fun checkIntent(savedInstanceState: Bundle? = null) {
|
||||||
mUri = intent.data ?: return
|
mUri = intent.data ?: return
|
||||||
if (intent.extras?.containsKey(REAL_FILE_PATH) == true) {
|
if (intent.extras?.containsKey(REAL_FILE_PATH) == true) {
|
||||||
|
@ -78,7 +81,13 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
|
||||||
showSystemUI()
|
showSystemUI()
|
||||||
val bundle = Bundle()
|
val bundle = Bundle()
|
||||||
val file = File(mUri.toString())
|
val file = File(mUri.toString())
|
||||||
mMedium = Medium(getFilenameFromUri(mUri!!), mUri.toString(), mIsVideo, 0, 0, file.length())
|
val type = when {
|
||||||
|
file.isImageFast() -> TYPE_IMAGE
|
||||||
|
file.isVideoFast() -> TYPE_VIDEO
|
||||||
|
else -> TYPE_GIF
|
||||||
|
}
|
||||||
|
|
||||||
|
mMedium = Medium(getFilenameFromUri(mUri!!), mUri.toString(), 0, 0, file.length(), type)
|
||||||
supportActionBar?.title = mMedium!!.name
|
supportActionBar?.title = mMedium!!.name
|
||||||
bundle.putSerializable(MEDIUM, mMedium)
|
bundle.putSerializable(MEDIUM, mMedium)
|
||||||
|
|
||||||
|
@ -99,14 +108,6 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
|
||||||
super.onResume()
|
|
||||||
supportActionBar?.setBackgroundDrawable(resources.getDrawable(R.drawable.actionbar_gradient_background))
|
|
||||||
if (config.blackBackground) {
|
|
||||||
updateStatusbarColor(Color.BLACK)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun sendViewPagerIntent(path: String) {
|
private fun sendViewPagerIntent(path: String) {
|
||||||
Intent(this, ViewPagerActivity::class.java).apply {
|
Intent(this, ViewPagerActivity::class.java).apply {
|
||||||
putExtra(IS_VIEW_INTENT, true)
|
putExtra(IS_VIEW_INTENT, true)
|
||||||
|
|
|
@ -17,6 +17,9 @@ import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog
|
import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog
|
||||||
import com.simplemobiletools.gallery.dialogs.PickMediumDialog
|
import com.simplemobiletools.gallery.dialogs.PickMediumDialog
|
||||||
import com.simplemobiletools.gallery.extensions.*
|
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.VIEW_TYPE_LIST
|
import com.simplemobiletools.gallery.helpers.VIEW_TYPE_LIST
|
||||||
import com.simplemobiletools.gallery.models.AlbumCover
|
import com.simplemobiletools.gallery.models.AlbumCover
|
||||||
import com.simplemobiletools.gallery.models.Directory
|
import com.simplemobiletools.gallery.models.Directory
|
||||||
|
@ -334,7 +337,13 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
|
||||||
dir_name.text = directory.name
|
dir_name.text = directory.name
|
||||||
dir_path?.text = "${directory.path.substringBeforeLast("/")}/"
|
dir_path?.text = "${directory.path.substringBeforeLast("/")}/"
|
||||||
photo_cnt.text = directory.mediaCnt.toString()
|
photo_cnt.text = directory.mediaCnt.toString()
|
||||||
activity.loadImage(directory.tmb, dir_thumbnail, scrollHorizontally, animateGifs, cropThumbnails)
|
val thumbnailType = when {
|
||||||
|
directory.tmb.isImageFast() -> TYPE_IMAGE
|
||||||
|
directory.tmb.isVideoFast() -> TYPE_VIDEO
|
||||||
|
else -> TYPE_GIF
|
||||||
|
}
|
||||||
|
|
||||||
|
activity.loadImage(thumbnailType, directory.tmb, dir_thumbnail, scrollHorizontally, animateGifs, cropThumbnails)
|
||||||
dir_pin.beVisibleIf(pinnedFolders.contains(directory.path))
|
dir_pin.beVisibleIf(pinnedFolders.contains(directory.path))
|
||||||
dir_sd_card.beVisibleIf(activity.isPathOnSD(directory.path))
|
dir_sd_card.beVisibleIf(activity.isPathOnSD(directory.path))
|
||||||
photo_cnt.beVisibleIf(showMediaCount)
|
photo_cnt.beVisibleIf(showMediaCount)
|
||||||
|
|
|
@ -282,20 +282,20 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
|
||||||
|
|
||||||
private fun setupView(view: View, medium: Medium) {
|
private fun setupView(view: View, medium: Medium) {
|
||||||
view.apply {
|
view.apply {
|
||||||
play_outline.beVisibleIf(medium.video)
|
play_outline.beVisibleIf(medium.isVideo())
|
||||||
photo_name.beVisibleIf(displayFilenames || isListViewType)
|
photo_name.beVisibleIf(displayFilenames || isListViewType)
|
||||||
photo_name.text = medium.name
|
photo_name.text = medium.name
|
||||||
photo_name.tag = medium.path
|
photo_name.tag = medium.path
|
||||||
|
|
||||||
if (loadImageInstantly) {
|
if (loadImageInstantly) {
|
||||||
activity.loadImage(medium.path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails)
|
activity.loadImage(medium.type, medium.path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails)
|
||||||
} else {
|
} else {
|
||||||
medium_thumbnail.setImageDrawable(null)
|
medium_thumbnail.setImageDrawable(null)
|
||||||
medium_thumbnail.isHorizontalScrolling = scrollHorizontally
|
medium_thumbnail.isHorizontalScrolling = scrollHorizontally
|
||||||
delayHandler.postDelayed({
|
delayHandler.postDelayed({
|
||||||
val isVisible = visibleItemPaths.contains(medium.path)
|
val isVisible = visibleItemPaths.contains(medium.path)
|
||||||
if (isVisible) {
|
if (isVisible) {
|
||||||
activity.loadImage(medium.path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails)
|
activity.loadImage(medium.type, medium.path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails)
|
||||||
}
|
}
|
||||||
}, IMAGE_LOAD_DELAY)
|
}, IMAGE_LOAD_DELAY)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ class MyPagerAdapter(val activity: ViewPagerActivity, fm: FragmentManager, val m
|
||||||
bundle.putSerializable(MEDIUM, medium)
|
bundle.putSerializable(MEDIUM, medium)
|
||||||
val fragment: ViewPagerFragment
|
val fragment: ViewPagerFragment
|
||||||
|
|
||||||
fragment = if (medium.video) {
|
fragment = if (medium.isVideo()) {
|
||||||
VideoFragment()
|
VideoFragment()
|
||||||
} else {
|
} else {
|
||||||
PhotoFragment()
|
PhotoFragment()
|
||||||
|
|
|
@ -35,7 +35,7 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c
|
||||||
activity.setupDialogStuff(view, this, R.string.select_photo)
|
activity.setupDialogStuff(view, this, R.string.select_photo)
|
||||||
}
|
}
|
||||||
|
|
||||||
val media = activity.getCachedMedia(path).filter { !it.video } as ArrayList
|
val media = activity.getCachedMedia(path).filter { !it.isVideo() } as ArrayList
|
||||||
if (media.isNotEmpty()) {
|
if (media.isNotEmpty()) {
|
||||||
gotMedia(media)
|
gotMedia(media)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,9 @@ import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.activities.SimpleActivity
|
import com.simplemobiletools.gallery.activities.SimpleActivity
|
||||||
import com.simplemobiletools.gallery.dialogs.PickDirectoryDialog
|
import com.simplemobiletools.gallery.dialogs.PickDirectoryDialog
|
||||||
import com.simplemobiletools.gallery.helpers.NOMEDIA
|
import com.simplemobiletools.gallery.helpers.NOMEDIA
|
||||||
|
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.models.Directory
|
import com.simplemobiletools.gallery.models.Directory
|
||||||
import com.simplemobiletools.gallery.models.Medium
|
import com.simplemobiletools.gallery.models.Medium
|
||||||
import com.simplemobiletools.gallery.views.MySquareImageView
|
import com.simplemobiletools.gallery.views.MySquareImageView
|
||||||
|
@ -139,15 +142,15 @@ fun BaseSimpleActivity.toggleFileVisibility(oldFile: File, hide: Boolean, callba
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Activity.loadImage(path: String, target: MySquareImageView, horizontalScroll: Boolean, animateGifs: Boolean, cropThumbnails: Boolean) {
|
fun Activity.loadImage(type: Int, path: String, target: MySquareImageView, horizontalScroll: Boolean, animateGifs: Boolean, cropThumbnails: Boolean) {
|
||||||
target.isHorizontalScrolling = horizontalScroll
|
target.isHorizontalScrolling = horizontalScroll
|
||||||
if (path.isImageFast() || path.isVideoFast()) {
|
if (type == TYPE_IMAGE || type == TYPE_VIDEO) {
|
||||||
if (path.isPng()) {
|
if (type == TYPE_IMAGE && path.isPng()) {
|
||||||
loadPng(path, target, cropThumbnails)
|
loadPng(path, target, cropThumbnails)
|
||||||
} else {
|
} else {
|
||||||
loadJpg(path, target, cropThumbnails)
|
loadJpg(path, target, cropThumbnails)
|
||||||
}
|
}
|
||||||
} else if (path.isGif()) {
|
} else if (type == TYPE_GIF) {
|
||||||
try {
|
try {
|
||||||
val gifDrawable = GifDrawable(path)
|
val gifDrawable = GifDrawable(path)
|
||||||
target.setImageDrawable(gifDrawable)
|
target.setImageDrawable(gifDrawable)
|
||||||
|
|
|
@ -101,3 +101,8 @@ val EXT_EXIF_PROPERTIES = 128
|
||||||
val EXT_DURATION = 256
|
val EXT_DURATION = 256
|
||||||
val EXT_ARTIST = 512
|
val EXT_ARTIST = 512
|
||||||
val EXT_ALBUM = 1024
|
val EXT_ALBUM = 1024
|
||||||
|
|
||||||
|
// media types
|
||||||
|
val TYPE_IMAGE = 1
|
||||||
|
val TYPE_VIDEO = 2
|
||||||
|
val TYPE_GIF = 3
|
||||||
|
|
|
@ -153,7 +153,13 @@ class MediaFetcher(val context: Context) {
|
||||||
val dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
|
val dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
|
||||||
val dateModified = cur.getIntValue(MediaStore.Images.Media.DATE_MODIFIED) * 1000L
|
val dateModified = cur.getIntValue(MediaStore.Images.Media.DATE_MODIFIED) * 1000L
|
||||||
|
|
||||||
val medium = Medium(filename, path, isVideo, dateModified, dateTaken, size)
|
val type = when {
|
||||||
|
isImage -> TYPE_IMAGE
|
||||||
|
isVideo -> TYPE_VIDEO
|
||||||
|
else -> TYPE_GIF
|
||||||
|
}
|
||||||
|
|
||||||
|
val medium = Medium(filename, path, dateModified, dateTaken, size, type)
|
||||||
curMedia.add(medium)
|
curMedia.add(medium)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
continue
|
continue
|
||||||
|
@ -255,7 +261,13 @@ class MediaFetcher(val context: Context) {
|
||||||
val dateTaken = file.lastModified()
|
val dateTaken = file.lastModified()
|
||||||
val dateModified = file.lastModified()
|
val dateModified = file.lastModified()
|
||||||
|
|
||||||
val medium = Medium(filename, file.absolutePath, isVideo, dateModified, dateTaken, size)
|
val type = when {
|
||||||
|
isImage -> TYPE_IMAGE
|
||||||
|
isVideo -> TYPE_VIDEO
|
||||||
|
else -> TYPE_GIF
|
||||||
|
}
|
||||||
|
|
||||||
|
val medium = Medium(filename, file.absolutePath, dateModified, dateTaken, size, type)
|
||||||
val isAlreadyAdded = curMedia.any { it.path == file.absolutePath }
|
val isAlreadyAdded = curMedia.any { it.path == file.absolutePath }
|
||||||
if (!isAlreadyAdded) {
|
if (!isAlreadyAdded) {
|
||||||
curMedia.add(medium)
|
curMedia.add(medium)
|
||||||
|
|
|
@ -1,22 +1,26 @@
|
||||||
package com.simplemobiletools.gallery.models
|
package com.simplemobiletools.gallery.models
|
||||||
|
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.formatDate
|
||||||
|
import com.simplemobiletools.commons.extensions.formatSize
|
||||||
|
import com.simplemobiletools.commons.extensions.getMimeTypeFromPath
|
||||||
|
import com.simplemobiletools.commons.extensions.isDng
|
||||||
import com.simplemobiletools.commons.helpers.*
|
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 java.io.Serializable
|
import java.io.Serializable
|
||||||
|
|
||||||
data class Medium(var name: String, var path: String, val video: Boolean, val modified: Long, val taken: Long, val size: Long) : Serializable, Comparable<Medium> {
|
data class Medium(var name: String, var path: String, val modified: Long, val taken: Long, val size: Long, val type: Int) : Serializable, Comparable<Medium> {
|
||||||
companion object {
|
companion object {
|
||||||
private val serialVersionUID = -6553149366975455L
|
private val serialVersionUID = -6553149366975455L
|
||||||
var sorting: Int = 0
|
var sorting: Int = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isPng() = path.isPng()
|
fun isGif() = type == TYPE_GIF
|
||||||
|
|
||||||
fun isGif() = path.isGif()
|
fun isImage() = type == TYPE_IMAGE
|
||||||
|
|
||||||
fun isJpg() = path.endsWith(".jpg", true) || path.endsWith(".jpeg", true)
|
fun isVideo() = type == TYPE_VIDEO
|
||||||
|
|
||||||
fun isImage() = !isGif() && !video
|
|
||||||
|
|
||||||
fun isDng() = path.isDng()
|
fun isDng() = path.isDng()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue