diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 85b3280..e048432 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME +zipStoreBase=GRADLE_USER_HOME \ No newline at end of file diff --git a/android/src/main/kotlin/de/ffuf/in_app_update/InAppUpdatePlugin.kt b/android/src/main/kotlin/de/ffuf/in_app_update/InAppUpdatePlugin.kt index aced01c..bbe758b 100644 --- a/android/src/main/kotlin/de/ffuf/in_app_update/InAppUpdatePlugin.kt +++ b/android/src/main/kotlin/de/ffuf/in_app_update/InAppUpdatePlugin.kt @@ -80,12 +80,17 @@ class InAppUpdatePlugin : FlutterPlugin, MethodCallHandler, private var appUpdateInfo: AppUpdateInfo? = null private var appUpdateManager: AppUpdateManager? = null + private var flexibleUpdateProgress: Long = 0L + private var flexibleUpdateSize: Long = 0L + override fun onMethodCall(call: MethodCall, result: Result) { when (call.method) { "checkForUpdate" -> checkForUpdate(result) "performImmediateUpdate" -> performImmediateUpdate(result) "startFlexibleUpdate" -> startFlexibleUpdate(result) "completeFlexibleUpdate" -> completeFlexibleUpdate(result) + "flexibleUpdateProgress" -> getFlexibleUpdateProgress(result) + "flexibleUpdateSize" -> getFlexibleUpdateSize(result) else -> result.notImplemented() } } @@ -227,7 +232,14 @@ class InAppUpdatePlugin : FlutterPlugin, MethodCallHandler, appUpdateManager?.registerListener { state -> addState(state.installStatus()) - if (state.installStatus() == InstallStatus.DOWNLOADED) { + if (state.installStatus() == InstallStatus.DOWNLOADING) { + val bytesDownloaded = state.bytesDownloaded() + val totalBytesToDownload = state.totalBytesToDownload() + flexibleUpdateSize = totalBytesToDownload + flexibleUpdateProgress = (bytesDownloaded * 100) / totalBytesToDownload + // Show update progress bar. + } else if (state.installStatus() == InstallStatus.DOWNLOADED) { + flexibleUpdateProgress = 100 updateResult?.success(null) updateResult = null } else if (state.installErrorCode() != InstallErrorCode.NO_ERROR) { @@ -241,6 +253,14 @@ class InAppUpdatePlugin : FlutterPlugin, MethodCallHandler, } } + private fun getFlexibleUpdateProgress(result: Result) = checkAppState(result) { + result.success(flexibleUpdateProgress) + } + + private fun getFlexibleUpdateSize(result: Result) = checkAppState(result) { + result.success(flexibleUpdateSize) + } + private fun completeFlexibleUpdate(result: Result) = checkAppState(result) { appUpdateManager?.completeUpdate() } diff --git a/lib/in_app_update.dart b/lib/in_app_update.dart index 292e001..3e211e3 100644 --- a/lib/in_app_update.dart +++ b/lib/in_app_update.dart @@ -149,6 +149,16 @@ class InAppUpdate { } } + // App update progress in percentage (0 - 100) + static Future getFlexibleUpdateProgress() async { + return await _channel.invokeMethod('flexibleUpdateProgress'); + } + + // App update size in bytes + static Future getFlexibleUpdateSize() async { + return await _channel.invokeMethod('flexibleUpdateSize'); + } + /// Installs the update downloaded via [startFlexibleUpdate]. /// /// [startFlexibleUpdate] has to be completed successfully. diff --git a/pubspec.lock b/pubspec.lock index 850d1d1..587cf81 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -162,4 +162,4 @@ packages: version: "0.1.4-beta" sdks: dart: ">=3.1.0-185.0.dev <4.0.0" - flutter: ">=1.20.0" + flutter: ">=1.20.0" \ No newline at end of file