allow directory comparison end in result 0

This commit is contained in:
tibbi 2016-12-01 23:36:51 +01:00
parent 59bba6fc2e
commit 865df01f3a
5 changed files with 27 additions and 19 deletions

View file

@ -121,8 +121,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.viewpager_menu, menu) menuInflater.inflate(R.menu.viewpager_menu, menu)
menu.findItem(R.id.menu_set_as_wallpaper).isVisible = getCurrentMedium().isImage 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_edit).isVisible = getCurrentMedium().isImage()
return true return true
} }

View file

@ -181,7 +181,7 @@ class MediaAdapter(val activity: SimpleActivity, val media: MutableList<Medium>,
val path = medium.path val path = medium.path
val timestampSignature = StringSignature(medium.timestamp.toString()) 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) Glide.with(activity).load(path).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature).into(itemView.medium_thumbnail)
} else { } else {
Glide.with(activity).load(path).diskCacheStrategy(DiskCacheStrategy.RESULT).signature(timestampSignature) Glide.with(activity).load(path).diskCacheStrategy(DiskCacheStrategy.RESULT).signature(timestampSignature)

View file

@ -27,7 +27,7 @@ class PhotoFragment : ViewPagerFragment(), View.OnClickListener {
medium.path = context.getRealPathFromURI(Uri.parse(medium.path)) ?: "" medium.path = context.getRealPathFromURI(Uri.parse(medium.path)) ?: ""
subsamplingView = view.photo_view subsamplingView = view.photo_view
if (medium.isGif) { if (medium.isGif()) {
subsamplingView.visibility = View.GONE subsamplingView.visibility = View.GONE
view.gif_view.apply { view.gif_view.apply {
visibility = View.VISIBLE visibility = View.VISIBLE

View file

@ -5,6 +5,10 @@ import com.simplemobiletools.gallery.SORT_BY_NAME
import com.simplemobiletools.gallery.SORT_DESCENDING 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<Directory> { class Directory(val path: String, val thumbnail: String, val name: String, var mediaCnt: Int, val timestamp: Long, var size: Long) : Comparable<Directory> {
companion object {
var sorting: Int = 0
}
fun addSize(bytes: Long) { fun addSize(bytes: Long) {
size += bytes 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) { if (sorting and SORT_BY_NAME != 0) {
res = name.toLowerCase().compareTo(other.name.toLowerCase()) res = name.toLowerCase().compareTo(other.name.toLowerCase())
} else if (sorting and SORT_BY_DATE != 0) { } 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 { } 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) { 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}" override fun toString() = "Directory {path=$path, thumbnail=$thumbnail, name=$name, mediaCnt=$mediaCnt, timestamp=$timestamp, size $size}"
companion object {
var sorting: Int = 0
}
} }

View file

@ -6,11 +6,14 @@ import com.simplemobiletools.gallery.SORT_DESCENDING
import java.io.Serializable import java.io.Serializable
class Medium(val name: String, var path: String, val isVideo: Boolean, val timestamp: Long, val size: Long) : Serializable, Comparable<Medium> { class Medium(val name: String, var path: String, val isVideo: Boolean, val timestamp: Long, val size: Long) : Serializable, Comparable<Medium> {
val isGif: Boolean companion object {
get() = path.toLowerCase().endsWith(".gif") private val serialVersionUID = -6553149466975455L
var sorting: Int = 0
}
val isImage: Boolean fun isGif() = path.toLowerCase().endsWith(".gif")
get() = !isGif && !isVideo
fun isImage() = !isGif() && !isVideo
fun getMimeType() = if (isVideo) "video/*" else "image/*" 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}" override fun toString() = "Medium {name=$name, path=$path, isVideo=$isVideo, timestamp=$timestamp, size=$size}"
companion object {
private val serialVersionUID = -6553149466975455L
var sorting: Int = 0
}
} }