Skip to content

feat(storage-ktx): destructure ListResult and TaskSnapshots #1644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Aug 17, 2020

Conversation

thatfiredev
Copy link
Member

This is actually a Feature Request. It should add Kotlin destructuring declarations to the classes: FileDownloadTask.TaskSnapshot, StreamDownloadTask.TaskSnapshot, UploadTask.TaskSnapshot and ListResult.

With the destructuring declarations, instead of:

fileDownloadTask.addOnSuccessListener { taskSnapshot ->
    val bytesTransferred = taskSnapshot.bytesTransferred
    val totalCount = taskSnapshot.totalByteCount
    val progress = bytesTransferred * 100 / totalCount
}

Kotlin developers will be able to use:

fileDownloadTask.addOnSuccessListener { (bytesTransferred, totalCount) ->
    val progress = bytesTransferred * 100 / totalCount
}

Here's a full list of all the declarations added in this PR:

Class Destructured
FileDownloadTask.TaskSnapshot (bytesTransferred, totalByteCount)
StreamDownloadTask.TaskSnapshot (bytesTransferred, totalByteCount, stream)
UploadTask.TaskSnapshot (bytesTransferred, totalByteCount, metadata, uploadSessionUri)
ListResult (items, prefixes, pageToken)

I should also point out that these arguments are optional, so for example, if a developer wishes to only get ListResult.items and not ListResult.prefixes or ListResult.pageToken, he may omit them:

storageRef.listAll().addOnSuccessListener { (items) ->
    // handle results
}

@google-oss-bot
Copy link
Contributor

Hi @rosariopfernandes. Thanks for your PR.

I'm waiting for a firebase member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@rlazo
Copy link
Collaborator

rlazo commented Jul 6, 2020

Hi @rosariopfernandes thanks for the proposal. I like the idea of adding destructure here! We'll evaluate this through our internal API review process. I'll keep you posted.

@rlazo rlazo self-requested a review July 6, 2020 11:01
…-sdk into rpf-storage-ktx-desctructure

� Conflicts:
�	firebase-storage/ktx/src/main/kotlin/com/google/firebase/storage/ktx/Storage.kt
…-sdk into rpf-storage-ktx-desctructure

� Conflicts:
�	firebase-storage/ktx/src/main/kotlin/com/google/firebase/storage/ktx/Storage.kt
…to rpf-storage-ktx-desctructure

# Conflicts:
#	firebase-storage/ktx/src/main/kotlin/com/google/firebase/storage/ktx/Storage.kt
@vkryachko
Copy link
Member

/ok-to-test

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jul 13, 2020

Coverage Report

Affected SDKs

  • firebase-storage

    SDK overall coverage changed from ? (a2dae12) to 85.44% (02fdf45d) by ?.

    Click to show coverage changes in 45 files.
    Filename Base (a2dae12) Head (02fdf45d) Diff
    ActivityLifecycleListener.java ? 74.14% ?
    AdaptiveStreamBuffer.java ? 84.62% ?
    CancelException.java ? 100.00% ?
    CancellableTask.java ? 100.00% ?
    ControllableTask.java ? 100.00% ?
    DeleteNetworkRequest.java ? 100.00% ?
    DeleteStorageTask.java ? 100.00% ?
    ExponentialBackoffSender.java ? 86.05% ?
    FileDownloadTask.java ? 77.60% ?
    FirebaseStorage.java ? 84.34% ?
    FirebaseStorageComponent.java ? 100.00% ?
    GetDownloadUrlTask.java ? 96.67% ?
    GetMetadataNetworkRequest.java ? 100.00% ?
    GetMetadataTask.java ? 84.62% ?
    GetNetworkRequest.java ? 100.00% ?
    HttpURLConnectionFactory.java ? 0.00% ?
    HttpURLConnectionFactoryImpl.java ? 50.00% ?
    ListNetworkRequest.java ? 100.00% ?
    ListResult.java ? 100.00% ?
    ListTask.java ? 85.19% ?
    NetworkRequest.java ? 89.29% ?
    OnPausedListener.java ? 0.00% ?
    OnProgressListener.java ? 0.00% ?
    ResumableNetworkRequest.java ? 100.00% ?
    ResumableUploadByteRequest.java ? 90.91% ?
    ResumableUploadCancelRequest.java ? 100.00% ?
    ResumableUploadQueryRequest.java ? 100.00% ?
    ResumableUploadStartRequest.java ? 95.00% ?
    Slashes.java ? 82.35% ?
    Sleeper.java ? 0.00% ?
    SleeperImpl.java ? 33.33% ?
    SmartHandler.java ? 87.50% ?
    StorageException.java ? 65.45% ?
    StorageMetadata.java ? 86.34% ?
    StorageReference.java ? 89.88% ?
    StorageRegistrar.java ? 100.00% ?
    StorageTask.java ? 84.29% ?
    StorageTaskManager.java ? 100.00% ?
    StorageTaskScheduler.java ? 100.00% ?
    StreamDownloadTask.java ? 88.89% ?
    TaskListenerImpl.java ? 100.00% ?
    UpdateMetadataNetworkRequest.java ? 100.00% ?
    UpdateMetadataTask.java ? 80.00% ?
    UploadTask.java ? 79.85% ?
    Util.java ? 65.57% ?

Test Logs

Notes

HTML coverage reports can be produced locally with ./gradlew <product>:checkCoverage.
Report files are located at <product-build-dir>/reports/jacoco/.

Head commit (02fdf45d) is created by Prow via merging commits: a2dae12 6ead390.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jul 13, 2020

Binary Size Report

Affected SDKs

  • firebase-storage-ktx

    Type Base (a2dae12) Head (02fdf45d) Diff
    aar 6.14 kB 7.00 kB +863 B (+14.1%)
    apk (release) 1.43 MB 1.43 MB +280 B (+0.0%)

Test Logs

Notes

Head commit (02fdf45d) is created by Prow via merging commits: a2dae12 6ead390.

@schmidt-sebastian
Copy link
Contributor

schmidt-sebastian commented Jul 15, 2020

@rosariopfernandes Just wanted to chime in since I am cc'ed on this: This PR will likely sit here for a while (2-3 weeks) as we obtain internal API approval. There is nothing more we need.

@thatfiredev
Copy link
Member Author

thatfiredev commented Jul 15, 2020

@schmidt-sebastian Yes, I understand. I was just trying to fix the coverage report. Sorry for flooding your notifications inbox.

Copy link
Collaborator

@rlazo rlazo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rosariopfernandes thanks for your patience, your proposal has been approved 👍 Just address the comments below and we can merge your change. Thanks for your help!

@rlazo
Copy link
Collaborator

rlazo commented Aug 10, 2020

@rosariopfernandes check-changed is failing with

> Task :firebase-storage:ktx:compileReleaseUnitTestKotlin FAILED
w: Argument -module-name is passed multiple times. Only the last value will be used: com.google.firebase-firebase-storage-ktx
e: /home/prow/go/src/github.com/firebase/firebase-android-sdk/firebase-storage/ktx/src/test/kotlin/com/google/firebase/storage/ktx/StorageTest.kt: (29, 36): Unresolved reference: TestUtil
e: /home/prow/go/src/github.com/firebase/firebase-android-sdk/firebase-storage/ktx/src/test/kotlin/com/google/firebase/storage/ktx/StorageTest.kt: (119, 30): Unresolved reference: TestUtil
e: /home/prow/go/src/github.com/firebase/firebase-android-sdk/firebase-storage/ktx/src/test/kotlin/com/google/firebase/storage/ktx/StorageTest.kt: (119, 50): Type inference failed: Not enough information to infer parameter T in inline fun <T> listOf(): List<T>
Please specify it explicitly.

e: /home/prow/go/src/github.com/firebase/firebase-android-sdk/firebase-storage/ktx/src/test/kotlin/com/google/firebase/storage/ktx/StorageTest.kt: (119, 60): Type inference failed: Not enough information to infer parameter T in inline fun <T> listOf(): List<T>
Please specify it explicitly.

@thatfiredev
Copy link
Member Author

@rlazo Because the TestUtil class was on a different module's test directory, it was inaccessible from the -ktx module. I tried adding it to the -ktx sourceSet like this:

sourceSets {
        // ...
        test.java {
            // ...
            srcDir '../src/test/java'
        }
        // ...
}

But it would try to import all the other test classes as well, and some of them were showing errors due to the difference in package names.

As a workaround, I created a new directory (/test/kotlin/) and a new TestUtil class (still under the com.firebase.storage package) exclusively for the ktx module. Seems like it does the trick.

@rlazo
Copy link
Collaborator

rlazo commented Aug 10, 2020

Would it be possible to add it to firebase-storage/src/testUtil/java/com/google/firebase/storage ? That could eliminate the need for a new directory.

@thatfiredev
Copy link
Member Author

@rlazo I did that, but needed to make 2 additional changes:

  1. Renamed the class to KtxTestUtil, because it was conflicting with the existing TestUtil class.
  2. Added Java 8 to the ktx module, because some classes from the testUtil package use Java 8 features (e.g. Lambda functions).

@google-oss-bot
Copy link
Contributor

@rosariopfernandes: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
smoke-tests 6ead390 link /test smoke-tests

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@thatfiredev thatfiredev requested a review from rlazo August 12, 2020 12:28
@rlazo rlazo merged commit 8c187fd into firebase:master Aug 17, 2020
@thatfiredev thatfiredev deleted the rpf-storage-ktx-desctructure branch August 17, 2020 20:08
@firebase firebase locked and limited conversation to collaborators Sep 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants