Skip to content

Commit 3870a0c

Browse files
author
Nikolay Kochetkov
committed
Adds download progress for flexible updates
Refs: #23
1 parent fa43dbf commit 3870a0c

4 files changed

Lines changed: 52 additions & 1 deletion

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ fun updateFailed(e: Throwable)
166166
Effective within the `IMMEDIATE` update flow to report a critical update error. Within the immediate update flow this is
167167
considered critical and you may want to terminate application.
168168

169+
#### updateDownloadProgress (optional)
170+
```kotlin
171+
fun updateDownloadProgress(bytesLoaded: Long, bytesTotal: Long)
172+
```
173+
Called in flexible flow to report that update download progress. You may display a progress bar or something.
174+
175+
- bytesLoaded - number of bytes downloaded
176+
- bytesTotal - total number of bytes to download
177+
169178
#### updateChecking (optional)
170179
```kotlin
171180
fun updateChecking()

appupdatewrapper/src/main/java/com/motorro/appupdatewrapper/AppUpdateView.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ interface AppUpdateView {
5555
*/
5656
fun updateDownloadStarts() = Unit
5757

58+
/**
59+
* Called when update download progress changes
60+
* @param bytesLoaded Bytes loaded
61+
* @param bytesTotal Total bytes to load
62+
*/
63+
fun updateDownloadProgress(bytesLoaded: Long, bytesTotal: Long) = Unit
64+
5865
/**
5966
* Reports update is downloaded and ready to be installed
6067
* When ready to proceed call [AppUpdateState.userConfirmedUpdate]

appupdatewrapper/src/main/java/com/motorro/appupdatewrapper/FlexibleUpdateState.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ internal sealed class FlexibleUpdateState : AppUpdateState(), Tagged {
295295
markUserCancelTime()
296296
complete()
297297
}
298+
DOWNLOADING -> withUpdateView {
299+
updateDownloadProgress(
300+
state.bytesDownloaded(),
301+
state.totalBytesToDownload()
302+
)
303+
}
298304
DOWNLOADED -> installConsent()
299305
INSTALLING -> completeUpdate()
300306
FAILED -> {

appupdatewrapper/src/test/java/com/motorro/appupdatewrapper/FlexibleUpdateStateTest.kt

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@ import com.google.android.play.core.install.model.ActivityResult
2424
import com.google.android.play.core.install.model.AppUpdateType.FLEXIBLE
2525
import com.google.android.play.core.install.model.InstallStatus
2626
import com.google.android.play.core.install.model.UpdateAvailability
27-
import com.nhaarman.mockitokotlin2.*
27+
import com.nhaarman.mockitokotlin2.any
28+
import com.nhaarman.mockitokotlin2.argumentCaptor
29+
import com.nhaarman.mockitokotlin2.check
30+
import com.nhaarman.mockitokotlin2.doReturn
31+
import com.nhaarman.mockitokotlin2.mock
32+
import com.nhaarman.mockitokotlin2.never
33+
import com.nhaarman.mockitokotlin2.times
34+
import com.nhaarman.mockitokotlin2.verify
35+
import com.nhaarman.mockitokotlin2.whenever
2836
import org.junit.Test
2937
import org.junit.runner.RunWith
3038
import org.robolectric.Shadows.shadowOf
@@ -261,6 +269,27 @@ internal class FlexibleUpdateStateTest: BaseAppUpdateStateTest() {
261269
shadowOf(getMainLooper()).idle()
262270
}
263271

272+
@Test
273+
@LooperMode(LooperMode.Mode.PAUSED)
274+
fun downloadingStateWillUpdateProgress() {
275+
updateManager.setUpdateAvailable(100500)
276+
updateManager.withInfo {
277+
startUpdateFlowForResult(it, FLEXIBLE, activity, 100)
278+
assertTrue(isConfirmationDialogVisible)
279+
userAcceptsUpdate()
280+
downloadStarts()
281+
setTotalBytesToDownload(100)
282+
283+
val state = FlexibleUpdateState.Downloading().init()
284+
state.onResume()
285+
shadowOf(getMainLooper()).idle()
286+
287+
setBytesDownloaded(50)
288+
verify(view).updateDownloadProgress(50, 100)
289+
}
290+
shadowOf(getMainLooper()).idle()
291+
}
292+
264293
@Test
265294
@LooperMode(LooperMode.Mode.PAUSED)
266295
fun downloadingStateWillSetInstallConsentWhenDownloaded() {

0 commit comments

Comments
 (0)