File search: improve handling of launcher theme and launcher backup file types

This commit is contained in:
MM20 2023-10-02 11:30:23 +02:00
parent 9d909e718c
commit e516848f4f
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
8 changed files with 26 additions and 9 deletions

View File

@ -42,7 +42,7 @@ fun CreateBackupSheet(
val backupLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.CreateDocument("application/vendor.de.mm20.launcher2.backup"),
contract = ActivityResultContracts.CreateDocument("application/vnd.de.mm20.launcher2.backup"),
onResult = {
if (it != null) viewModel.createBackup(it)
}

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M20.54,5.23l-1.39,-1.68C18.88,3.21 18.47,3 18,3H6c-0.47,0 -0.88,0.21 -1.16,0.55L3.46,5.23C3.17,5.57 3,6.02 3,6.5V19c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2V6.5c0,-0.48 -0.17,-0.93 -0.46,-1.27zM12,17.5L6.5,12H10v-2h4v2h3.5L12,17.5zM5.12,5l0.81,-1h12l0.94,1H5.12z"/>
</vector>

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,2C6.49,2 2,6.49 2,12s4.49,10 10,10c1.38,0 2.5,-1.12 2.5,-2.5c0,-0.61 -0.23,-1.2 -0.64,-1.67c-0.08,-0.1 -0.13,-0.21 -0.13,-0.33c0,-0.28 0.22,-0.5 0.5,-0.5H16c3.31,0 6,-2.69 6,-6C22,6.04 17.51,2 12,2zM17.5,13c-0.83,0 -1.5,-0.67 -1.5,-1.5c0,-0.83 0.67,-1.5 1.5,-1.5s1.5,0.67 1.5,1.5C19,12.33 18.33,13 17.5,13zM14.5,9C13.67,9 13,8.33 13,7.5C13,6.67 13.67,6 14.5,6S16,6.67 16,7.5C16,8.33 15.33,9 14.5,9zM5,11.5C5,10.67 5.67,10 6.5,10S8,10.67 8,11.5C8,12.33 7.33,13 6.5,13S5,12.33 5,11.5zM11,7.5C11,8.33 10.33,9 9.5,9S8,8.33 8,7.5C8,6.67 8.67,6 9.5,6S11,6.67 11,7.5z"/>
</vector>

View File

@ -145,6 +145,8 @@
<string name="file_type_form">Form</string>
<!-- Launcher backup, %1$s: app name -->
<string name="file_type_launcherbackup">%1$s backup</string>
<!-- Launcher backup, %1$s: app name -->
<string name="file_type_launchertheme">%1$s theme</string>
<!-- Generic file , %1$s is the file extension -->
<string name="file_type_generic">%1$s file</string>
<!-- Warning message that is shown when a user attempts to delete a directory -->

View File

@ -51,7 +51,7 @@ class LocalFileDeserializer(
if (!java.io.File(path).exists()) return null
val directory = java.io.File(path).isDirectory
val id = cursor.getLong(0)
val mimeType = cursor.getStringOrNull(3)
val mimeType = cursor.getStringOrNull(3).takeIf { it != "application/octet-stream" }
?: if (directory) "resource/folder" else LocalFile.getMimetypeByFileExtension(
path.substringAfterLast(
'.'

View File

@ -44,7 +44,7 @@ internal class LocalFileProvider(
val path = cursor.getString(3)
if (!java.io.File(path).exists()) continue
val directory = java.io.File(path).isDirectory
val mimeType = (cursor.getStringOrNull(4)
val mimeType = (cursor.getStringOrNull(4).takeIf { it != "application/octet-stream" }
?: if (directory) "resource/folder" else LocalFile.getMimetypeByFileExtension(
path.substringAfterLast(
'.'

View File

@ -49,6 +49,8 @@ interface File : SavableSearchable {
"application/vnd.android.package-archive" -> R.drawable.ic_file_android to R.color.lightgreen
"application/vnd.google-apps.form" -> R.drawable.ic_file_form to R.color.deeppurple
"application/vnd.google-apps.drawing" -> R.drawable.ic_file_picture to R.color.teal
"application/vnd.de.mm20.launcher2.backup" -> R.drawable.ic_file_backup to R.color.brown
"application/vnd.de.mm20.launcher2.theme" -> R.drawable.ic_file_theme to R.color.amber
else -> R.drawable.ic_file_generic to R.color.bluegrey
}
}
@ -64,12 +66,18 @@ interface File : SavableSearchable {
fun getFileType(context: Context): String {
if (isDirectory) return context.getString(R.string.file_type_directory)
if (mimeType == "application/vendor.de.mm20.launcher2.backup") {
if (mimeType == "application/vnd.de.mm20.launcher2.backup") {
return context.getString(
R.string.file_type_launcherbackup,
context.getString(R.string.app_name)
)
}
if (mimeType == "application/vnd.de.mm20.launcher2.theme") {
return context.getString(
R.string.file_type_launchertheme,
context.getString(R.string.app_name)
)
}
val resource = when (mimeType) {
"application/zip",
"application/x-zip-compressed",
@ -118,10 +126,6 @@ interface File : SavableSearchable {
}
if (resource == R.string.file_type_none && label.matches(Regex(".+\\..+"))) {
val extension = label.substringAfterLast(".").uppercase(Locale.getDefault())
if (extension == "kvaesitso") return context.getString(
R.string.file_type_launcherbackup,
context.getString(R.string.app_name)
)
return context.getString(R.string.file_type_generic, extension)
}
return context.getString(resource)

View File

@ -223,7 +223,8 @@ data class LocalFile(
"ogg" -> "audio/ogg"
"wav" -> "audio/wav"
"mp4" -> "video/mp4"
"kvaesitso" -> "application/vendor.de.mm20.launcher2.backup"
"kvaesitso" -> "application/vnd.de.mm20.launcher2.backup"
"kvtheme" -> "application/vnd.de.mm20.launcher2.theme"
else -> "application/octet-stream"
}
}