Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ fun updateFailed(e: Throwable)
Effective within the `IMMEDIATE` update flow to report a critical update error. Within the immediate update flow this is
considered critical and you may want to terminate application.

#### updateDownloadProgress (optional)
```kotlin
fun updateDownloadProgress(bytesLoaded: Long, bytesTotal: Long)
```
Called in flexible flow to report that update download progress. You may display a progress bar or something.

- bytesLoaded - number of bytes downloaded
- bytesTotal - total number of bytes to download

#### updateChecking (optional)
```kotlin
fun updateChecking()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ interface AppUpdateView {
*/
fun updateDownloadStarts() = Unit

/**
* Called when update download progress changes
* @param bytesLoaded Bytes loaded
* @param bytesTotal Total bytes to load
*/
fun updateDownloadProgress(bytesLoaded: Long, bytesTotal: Long) = Unit

/**
* Reports update is downloaded and ready to be installed
* When ready to proceed call [AppUpdateState.userConfirmedUpdate]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ internal sealed class FlexibleUpdateState : AppUpdateState(), Tagged {
markUserCancelTime()
complete()
}
DOWNLOADING -> withUpdateView {
updateDownloadProgress(
state.bytesDownloaded(),
state.totalBytesToDownload()
)
}
DOWNLOADED -> installConsent()
INSTALLING -> completeUpdate()
FAILED -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ import com.google.android.play.core.install.model.ActivityResult
import com.google.android.play.core.install.model.AppUpdateType.FLEXIBLE
import com.google.android.play.core.install.model.InstallStatus
import com.google.android.play.core.install.model.UpdateAvailability
import com.nhaarman.mockitokotlin2.*
import com.nhaarman.mockitokotlin2.any
import com.nhaarman.mockitokotlin2.argumentCaptor
import com.nhaarman.mockitokotlin2.check
import com.nhaarman.mockitokotlin2.doReturn
import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.never
import com.nhaarman.mockitokotlin2.times
import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.whenever
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.Shadows.shadowOf
Expand Down Expand Up @@ -261,6 +269,27 @@ internal class FlexibleUpdateStateTest: BaseAppUpdateStateTest() {
shadowOf(getMainLooper()).idle()
}

@Test
@LooperMode(LooperMode.Mode.PAUSED)
fun downloadingStateWillUpdateProgress() {
updateManager.setUpdateAvailable(100500)
updateManager.withInfo {
startUpdateFlowForResult(it, FLEXIBLE, activity, 100)
assertTrue(isConfirmationDialogVisible)
userAcceptsUpdate()
downloadStarts()
setTotalBytesToDownload(100)

val state = FlexibleUpdateState.Downloading().init()
state.onResume()
shadowOf(getMainLooper()).idle()

setBytesDownloaded(50)
verify(view).updateDownloadProgress(50, 100)
}
shadowOf(getMainLooper()).idle()
}

@Test
@LooperMode(LooperMode.Mode.PAUSED)
fun downloadingStateWillSetInstallConsentWhenDownloaded() {
Expand Down
Loading