diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index e29352681..fda440ae3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -121,8 +121,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.viewpager_menu, menu) - menu.findItem(R.id.menu_set_as_wallpaper).isVisible = getCurrentMedium().isImage - menu.findItem(R.id.menu_edit).isVisible = getCurrentMedium().isImage + menu.findItem(R.id.menu_set_as_wallpaper).isVisible = getCurrentMedium().isImage() + menu.findItem(R.id.menu_edit).isVisible = getCurrentMedium().isImage() return true } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index 75d705f3e..af2719e79 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -181,7 +181,7 @@ class MediaAdapter(val activity: SimpleActivity, val media: MutableList, val path = medium.path val timestampSignature = StringSignature(medium.timestamp.toString()) - if (medium.isGif) { + if (medium.isGif()) { Glide.with(activity).load(path).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature).into(itemView.medium_thumbnail) } else { Glide.with(activity).load(path).diskCacheStrategy(DiskCacheStrategy.RESULT).signature(timestampSignature) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt index c8154e76a..36ba57bec 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -27,7 +27,7 @@ class PhotoFragment : ViewPagerFragment(), View.OnClickListener { medium.path = context.getRealPathFromURI(Uri.parse(medium.path)) ?: "" subsamplingView = view.photo_view - if (medium.isGif) { + if (medium.isGif()) { subsamplingView.visibility = View.GONE view.gif_view.apply { visibility = View.VISIBLE diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt index e72d7cad2..c9900d325 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt @@ -5,6 +5,10 @@ import com.simplemobiletools.gallery.SORT_BY_NAME import com.simplemobiletools.gallery.SORT_DESCENDING class Directory(val path: String, val thumbnail: String, val name: String, var mediaCnt: Int, val timestamp: Long, var size: Long) : Comparable { + companion object { + var sorting: Int = 0 + } + fun addSize(bytes: Long) { size += bytes } @@ -14,9 +18,19 @@ class Directory(val path: String, val thumbnail: String, val name: String, var m if (sorting and SORT_BY_NAME != 0) { res = name.toLowerCase().compareTo(other.name.toLowerCase()) } else if (sorting and SORT_BY_DATE != 0) { - res = if (timestamp > other.timestamp) 1 else -1 + res = if (timestamp == other.timestamp) + 0 + else if (timestamp > other.timestamp) + 1 + else + -1 } else { - res = if (size > other.size) 1 else -1 + res = if (size == other.size) + 0 + else if (size > other.size) + 1 + else + -1 } if (sorting and SORT_DESCENDING != 0) { @@ -26,8 +40,4 @@ class Directory(val path: String, val thumbnail: String, val name: String, var m } override fun toString() = "Directory {path=$path, thumbnail=$thumbnail, name=$name, mediaCnt=$mediaCnt, timestamp=$timestamp, size $size}" - - companion object { - var sorting: Int = 0 - } } 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 8c2ddd839..81104298b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -6,11 +6,14 @@ import com.simplemobiletools.gallery.SORT_DESCENDING import java.io.Serializable class Medium(val name: String, var path: String, val isVideo: Boolean, val timestamp: Long, val size: Long) : Serializable, Comparable { - val isGif: Boolean - get() = path.toLowerCase().endsWith(".gif") + companion object { + private val serialVersionUID = -6553149466975455L + var sorting: Int = 0 + } - val isImage: Boolean - get() = !isGif && !isVideo + fun isGif() = path.toLowerCase().endsWith(".gif") + + fun isImage() = !isGif() && !isVideo fun getMimeType() = if (isVideo) "video/*" else "image/*" @@ -41,9 +44,4 @@ class Medium(val name: String, var path: String, val isVideo: Boolean, val times } override fun toString() = "Medium {name=$name, path=$path, isVideo=$isVideo, timestamp=$timestamp, size=$size}" - - companion object { - private val serialVersionUID = -6553149466975455L - var sorting: Int = 0 - } }