adding a helper function for assembling FileDirItem content uri manually

This commit is contained in:
tibbi 2022-06-15 14:11:15 +02:00
parent 4b3acbca86
commit edb96519a7

View file

@ -2,6 +2,7 @@ package com.simplemobiletools.commons.models
import android.content.Context
import android.net.Uri
import android.provider.MediaStore
import com.bumptech.glide.signature.ObjectKey
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
@ -21,7 +22,8 @@ open class FileDirItem(
var sorting = 0
}
override fun toString() = "FileDirItem(path=$path, name=$name, isDirectory=$isDirectory, children=$children, size=$size, modified=$modified, mediaStoreId=$mediaStoreId)"
override fun toString() =
"FileDirItem(path=$path, name=$name, isDirectory=$isDirectory, children=$children, size=$size, modified=$modified, mediaStoreId=$mediaStoreId)"
override fun compareTo(other: FileDirItem): Int {
return if (isDirectory && !other.isDirectory) {
@ -143,4 +145,14 @@ open class FileDirItem(
}
fun getKey() = ObjectKey(getSignature())
fun assembleContentUri(): Uri {
val uri = when {
path.isImageFast() -> MediaStore.Images.Media.EXTERNAL_CONTENT_URI
path.isVideoFast() -> MediaStore.Video.Media.EXTERNAL_CONTENT_URI
else -> MediaStore.Files.getContentUri("external")
}
return Uri.withAppendedPath(uri, mediaStoreId.toString())
}
}