Fix open local files in file manager apps
Known to work with: - Material Files - Solid Explorer
This commit is contained in:
parent
56c8e056ad
commit
fc320251f6
@ -1,6 +1,7 @@
|
|||||||
package de.mm20.launcher2.files
|
package de.mm20.launcher2.files
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.provider.DocumentsContract
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import androidx.core.database.getStringOrNull
|
import androidx.core.database.getStringOrNull
|
||||||
import de.mm20.launcher2.ktx.jsonObjectOf
|
import de.mm20.launcher2.ktx.jsonObjectOf
|
||||||
@ -51,7 +52,7 @@ class LocalFileDeserializer(
|
|||||||
val directory = java.io.File(path).isDirectory
|
val directory = java.io.File(path).isDirectory
|
||||||
val id = cursor.getLong(0)
|
val id = cursor.getLong(0)
|
||||||
val mimeType = cursor.getStringOrNull(3)
|
val mimeType = cursor.getStringOrNull(3)
|
||||||
?: if (directory) "inode/directory" else LocalFile.getMimetypeByFileExtension(
|
?: if (directory) "resource/folder" else LocalFile.getMimetypeByFileExtension(
|
||||||
path.substringAfterLast(
|
path.substringAfterLast(
|
||||||
'.'
|
'.'
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package de.mm20.launcher2.files.providers
|
package de.mm20.launcher2.files.providers
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.provider.DocumentsContract
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import androidx.core.database.getStringOrNull
|
import androidx.core.database.getStringOrNull
|
||||||
import de.mm20.launcher2.permissions.PermissionGroup
|
import de.mm20.launcher2.permissions.PermissionGroup
|
||||||
@ -44,7 +45,7 @@ internal class LocalFileProvider(
|
|||||||
if (!java.io.File(path).exists()) continue
|
if (!java.io.File(path).exists()) continue
|
||||||
val directory = java.io.File(path).isDirectory
|
val directory = java.io.File(path).isDirectory
|
||||||
val mimeType = (cursor.getStringOrNull(4)
|
val mimeType = (cursor.getStringOrNull(4)
|
||||||
?: if (directory) "inode/directory" else LocalFile.getMimetypeByFileExtension(
|
?: if (directory) "resource/folder" else LocalFile.getMimetypeByFileExtension(
|
||||||
path.substringAfterLast(
|
path.substringAfterLast(
|
||||||
'.'
|
'.'
|
||||||
)
|
)
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import android.graphics.drawable.BitmapDrawable
|
|||||||
import android.location.Geocoder
|
import android.location.Geocoder
|
||||||
import android.media.MediaMetadataRetriever
|
import android.media.MediaMetadataRetriever
|
||||||
import android.media.ThumbnailUtils
|
import android.media.ThumbnailUtils
|
||||||
import android.os.Build
|
import android.net.Uri
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.text.format.DateUtils
|
import android.text.format.DateUtils
|
||||||
import android.util.Size
|
import android.util.Size
|
||||||
@ -18,7 +18,6 @@ import de.mm20.launcher2.files.R
|
|||||||
import de.mm20.launcher2.icons.LauncherIcon
|
import de.mm20.launcher2.icons.LauncherIcon
|
||||||
import de.mm20.launcher2.ktx.formatToString
|
import de.mm20.launcher2.ktx.formatToString
|
||||||
import de.mm20.launcher2.media.ThumbnailUtilsCompat
|
import de.mm20.launcher2.media.ThumbnailUtilsCompat
|
||||||
import de.mm20.launcher2.preferences.Settings
|
|
||||||
import de.mm20.launcher2.preferences.Settings.IconSettings.LegacyIconBackground
|
import de.mm20.launcher2.preferences.Settings.IconSettings.LegacyIconBackground
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@ -41,7 +40,11 @@ open class LocalFile(
|
|||||||
|
|
||||||
override val isStoredInCloud = false
|
override val isStoredInCloud = false
|
||||||
|
|
||||||
override suspend fun loadIcon(context: Context, size: Int, legacyIconBackground: LegacyIconBackground): LauncherIcon? {
|
override suspend fun loadIcon(
|
||||||
|
context: Context,
|
||||||
|
size: Int,
|
||||||
|
legacyIconBackground: LegacyIconBackground
|
||||||
|
): LauncherIcon? {
|
||||||
if (!JavaIOFile(path).exists()) return null
|
if (!JavaIOFile(path).exists()) return null
|
||||||
when {
|
when {
|
||||||
mimeType.startsWith("image/") -> {
|
mimeType.startsWith("image/") -> {
|
||||||
@ -126,10 +129,14 @@ open class LocalFile(
|
|||||||
|
|
||||||
|
|
||||||
override fun getLaunchIntent(context: Context): Intent? {
|
override fun getLaunchIntent(context: Context): Intent? {
|
||||||
val uri = FileProvider.getUriForFile(
|
val uri = if (isDirectory) {
|
||||||
context,
|
Uri.parse(path)
|
||||||
context.applicationContext.packageName + ".fileprovider", JavaIOFile(path)
|
} else {
|
||||||
)
|
FileProvider.getUriForFile(
|
||||||
|
context,
|
||||||
|
context.applicationContext.packageName + ".fileprovider", JavaIOFile(path)
|
||||||
|
)
|
||||||
|
}
|
||||||
return Intent(Intent.ACTION_VIEW)
|
return Intent(Intent.ACTION_VIEW)
|
||||||
.setDataAndType(uri, mimeType)
|
.setDataAndType(uri, mimeType)
|
||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
@ -152,13 +159,13 @@ open class LocalFile(
|
|||||||
context.contentResolver.delete(
|
context.contentResolver.delete(
|
||||||
MediaStore.Files.getContentUri("external"),
|
MediaStore.Files.getContentUri("external"),
|
||||||
"${MediaStore.Files.FileColumns._ID} = ?",
|
"${MediaStore.Files.FileColumns._ID} = ?",
|
||||||
arrayOf(id.toString()))
|
arrayOf(id.toString())
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
companion object : KoinComponent {
|
||||||
companion object: KoinComponent {
|
|
||||||
internal fun getMimetypeByFileExtension(extension: String): String {
|
internal fun getMimetypeByFileExtension(extension: String): String {
|
||||||
return when (extension) {
|
return when (extension) {
|
||||||
"apk" -> "application/vnd.android.package-archive"
|
"apk" -> "application/vnd.android.package-archive"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user