Skip to content

Commit 642f5e5

Browse files
committed
refactor: remove !! operator from upload snippets
1 parent 7acc02b commit 642f5e5

File tree

1 file changed

+12
-12
lines changed
  • storage/app/src/main/java/com/google/firebase/referencecode/storage/kotlin

1 file changed

+12
-12
lines changed

storage/app/src/main/java/com/google/firebase/referencecode/storage/kotlin/UploadActivity.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import com.google.firebase.storage.UploadTask
1212
abstract class UploadActivity : AppCompatActivity() {
1313

1414
// storageRef was previously used to transfer data.
15-
private var storageRef: StorageReference? = null
15+
private lateinit var storageRef: StorageReference
1616
private var saved: Boolean = false
1717

1818
override fun onCreate(savedInstanceState: Bundle?) {
@@ -40,16 +40,16 @@ abstract class UploadActivity : AppCompatActivity() {
4040

4141
// Find all UploadTasks under this StorageReference (in this example, there should be one)
4242

43-
storageRef?.activeUploadTasks?.let { it ->
44-
if (it.size > 0) {
45-
// Get the task monitoring the upload
46-
val task = it[0]
43+
val tasks = storageRef.activeUploadTasks
4744

48-
// Add new listeners to the task using an Activity scope
49-
task.addOnSuccessListener(this) {
50-
// Success!
51-
// ...
52-
}
45+
if (tasks.size > 0) {
46+
// Get the task monitoring the upload
47+
val task = tasks[0]
48+
49+
// Add new listeners to the task using an Activity scope
50+
task.addOnSuccessListener(this) {
51+
// Success!
52+
// ...
5353
}
5454
}
5555
}
@@ -61,7 +61,7 @@ abstract class UploadActivity : AppCompatActivity() {
6161
var uploadTask: UploadTask
6262

6363
// [START save_before_restart]
64-
uploadTask = storageRef!!.putFile(localFile)
64+
uploadTask = storageRef.putFile(localFile)
6565
uploadTask.addOnProgressListener { taskSnapshot ->
6666
sessionUri = taskSnapshot.uploadSessionUri
6767
if (sessionUri != null && !saved) {
@@ -75,7 +75,7 @@ abstract class UploadActivity : AppCompatActivity() {
7575
// [START restore_after_restart]
7676
// resume the upload task from where it left off when the process died.
7777
// to do this, pass the sessionUri as the last parameter
78-
uploadTask = storageRef!!.putFile(localFile,
78+
uploadTask = storageRef.putFile(localFile,
7979
StorageMetadata.Builder().build(), sessionUri)
8080
// [END restore_after_restart]
8181
}

0 commit comments

Comments
 (0)