Fix crash when default volume gets deleted

This commit is contained in:
Matéo Duparc 2023-04-18 13:53:40 +02:00
parent eb4e13af46
commit 24215a8b31
Signed by: hardcoresushi
GPG Key ID: AFE384344A45E13A

View File

@ -118,16 +118,16 @@ class MainActivity : BaseActivity(), VolumeAdapter.Listener {
volumeOpener.defaultVolumeName?.let { name -> volumeOpener.defaultVolumeName?.let { name ->
val state = savedInstanceState?.getBoolean(OPEN_DEFAULT_VOLUME) val state = savedInstanceState?.getBoolean(OPEN_DEFAULT_VOLUME)
if (state == true || state == null) { if (state == true || state == null) {
try {
val volumeData = volumeAdapter.volumes.first { it.name == name } val volumeData = volumeAdapter.volumes.first { it.name == name }
if (!volumeManager.isOpen(volumeData)) { if (!volumeManager.isOpen(volumeData)) {
try {
openVolume(volumeData) openVolume(volumeData)
}
} catch (e: NoSuchElementException) { } catch (e: NoSuchElementException) {
unsetDefaultVolume() unsetDefaultVolume()
} }
} }
} }
}
Intent(this, FileOperationService::class.java).also { Intent(this, FileOperationService::class.java).also {
bindService(it, object : ServiceConnection { bindService(it, object : ServiceConnection {
override fun onServiceConnected(className: ComponentName, service: IBinder) { override fun onServiceConnected(className: ComponentName, service: IBinder) {