Reuse search result item viewmodels
This commit is contained in:
@@ -129,6 +129,11 @@ interface File : SavableSearchable {
|
||||
|
||||
val isDeletable: Boolean
|
||||
get() = false
|
||||
|
||||
val canShare: Boolean
|
||||
get() = false
|
||||
|
||||
fun share(context: Context) {}
|
||||
suspend fun delete(context: Context) {}
|
||||
|
||||
}
|
||||
@@ -335,4 +335,20 @@ data class LocalFile(
|
||||
return metaData
|
||||
}
|
||||
}
|
||||
|
||||
override val canShare: Boolean
|
||||
get() = !isDirectory
|
||||
|
||||
override fun share(context: Context) {
|
||||
val shareIntent = Intent(Intent.ACTION_SEND)
|
||||
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
val uri = FileProvider.getUriForFile(
|
||||
context,
|
||||
context.applicationContext.packageName + ".fileprovider",
|
||||
java.io.File(path)
|
||||
)
|
||||
shareIntent.putExtra(Intent.EXTRA_STREAM, uri)
|
||||
shareIntent.type = mimeType
|
||||
context.startActivity(Intent.createChooser(shareIntent, null))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user