tv: show volume descriptions for file picker

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2020-09-24 11:29:03 +02:00
parent 4bf34c49b7
commit e729c5dc51

View File

@ -204,9 +204,9 @@ class TvMainActivity : AppCompatActivity() {
val storageManager: StorageManager = getSystemService() ?: return@withContext list
list.addAll(storageManager.storageVolumes.mapNotNull { volume ->
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
volume.directory?.let { KeyedFile(it.canonicalPath) }
volume.directory?.let { KeyedFile(it.canonicalPath, volume.getDescription(this@TvMainActivity)) }
} else {
KeyedFile((StorageVolume::class.java.getMethod("getPathFile").invoke(volume) as File).canonicalPath)
KeyedFile((StorageVolume::class.java.getMethod("getPathFile").invoke(volume) as File).canonicalPath, volume.getDescription(this@TvMainActivity))
}
})
} else {
@ -319,9 +319,9 @@ class TvMainActivity : AppCompatActivity() {
}
}
class KeyedFile(pathname: String) : File(pathname), Keyed<String> {
class KeyedFile(pathname: String, private val forcedKey: String? = null) : File(pathname), Keyed<String> {
override val key: String
get() = if (isDirectory) "$name/" else name
get() = forcedKey ?: if (isDirectory) "$name/" else name
}
companion object {