Skip to content

Commit cc74810

Browse files
committed
Handle file not found in index
1 parent fe5d59c commit cc74810

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

sample/src/main/java/dev/arkbuilders/sample/ScoreActivity.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.arkbuilders.sample
22

33
import android.os.Bundle
4+
import android.widget.Toast
45
import androidx.appcompat.app.AppCompatActivity
56
import androidx.compose.foundation.layout.padding
67
import androidx.compose.ui.Modifier
@@ -49,7 +50,6 @@ class ScoreActivity : AppCompatActivity() {
4950
this,
5051
customRequestKey = PICK_RESOURCE_KEY
5152
) { resourcePath ->
52-
btnPickResource.text = resourcePath.name
5353
rootFolder?.let {
5454
onResourcePicked(root = it, resourcePath)
5555
}
@@ -78,7 +78,19 @@ class ScoreActivity : AppCompatActivity() {
7878
) = lifecycleScope.launch {
7979
val (index, scoreStorage) = setupIndexAndScoreStorage(root)
8080
val id = index.allPaths().toList()
81-
.find { it.second == resourcePath }!!.first
81+
.find { it.second == resourcePath }?.first
82+
83+
id ?: let {
84+
Toast.makeText(
85+
this@ScoreActivity,
86+
"File does not belong to root",
87+
Toast.LENGTH_SHORT
88+
).show()
89+
return@launch
90+
}
91+
92+
findViewById<MaterialButton>(R.id.btn_pick_resource).text = resourcePath.name
93+
8294
val scoreWidgetController = ScoreWidgetController(
8395
lifecycleScope,
8496
getCurrentId = { id },

0 commit comments

Comments
 (0)