diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7f71d9a --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +# Gradle +.gradle +build/ + +captures + +/local.properties + +# IntelliJ .idea folder +.idea/workspace.xml +.idea/libraries +.idea/caches +.idea/tasks.xml +.idea/modules.xml +gradle.xml +*.iml + +# General +.DS_Store +.externalNativeBuild \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 37a7509..dfd2c79 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index ea6605c..9319198 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,35 +3,36 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { - compileSdkVersion 29 + defaultConfig { applicationId "at.allaboutapps.inappupdater.demo" - minSdkVersion 16 + minSdkVersion 21 targetSdkVersion 29 versionCode 3 versionName "V1.0.2" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } + buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } } } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation project(path: ':inappupdater') + implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'com.google.android.material:material:1.1.0-alpha09' - implementation 'androidx.core:core-ktx:1.0.2' + + implementation 'androidx.core:core-ktx:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - implementation 'io.reactivex.rxjava2:rxjava:2.2.9' + implementation 'com.google.android.material:material:1.1.0-alpha09' + implementation 'io.reactivex.rxjava2:rxjava:2.2.13' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - implementation project(path: ':inappupdater') } diff --git a/build.gradle b/build.gradle index bc74cef..5f14114 100644 --- a/build.gradle +++ b/build.gradle @@ -1,17 +1,15 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - buildscript { - ext.kotlin_version = '1.3.31' + ext.kotlin_version = '1.3.50' + repositories { google() jcenter() } + dependencies { - classpath 'com.android.tools.build:gradle:3.5.0' + classpath 'com.android.tools.build:gradle:3.5.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:0.9.18" - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index bc8c40f..ca9d628 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Fri Jun 07 08:55:10 CEST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip diff --git a/inappupdater/build.gradle b/inappupdater/build.gradle index dee139b..197306e 100644 --- a/inappupdater/build.gradle +++ b/inappupdater/build.gradle @@ -13,18 +13,17 @@ apply plugin: 'kotlin-android-extensions' apply plugin: 'org.jetbrains.dokka-android' android { - compileSdkVersion 28 + compileSdkVersion 29 defaultConfig { - minSdkVersion 16 - targetSdkVersion 28 + minSdkVersion 21 + targetSdkVersion 29 versionCode 1 versionName "1.0" // the name of the artifact archivesBaseName = 'a3inappupdater' // e.g. a3webview - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles 'consumer-rules.pro' } @@ -87,6 +86,7 @@ publishing { } } } + task javadoc(type: Javadoc) { excludes = ['**/*.kt'] // Exclude all kotlin files from javadoc file. } @@ -126,16 +126,14 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'io.reactivex.rxjava2:rxjava:2.2.9' + implementation 'com.google.android.play:core:1.6.3' + implementation 'androidx.annotation:annotation:1.1.0' - implementation 'com.google.android.play:core:1.6.1' - implementation 'com.android.support:support-annotations:28.0.0' + implementation 'io.reactivex.rxjava2:rxjava:2.2.13' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - } - -apply plugin: 'digital.wup.android-maven-publish' \ No newline at end of file +apply plugin: 'digital.wup.android-maven-publish' diff --git a/inappupdater/src/main/java/at/allaboutapps/inappupdater/ForceUpdateProvider.kt b/inappupdater/src/main/java/at/allaboutapps/inappupdater/ForceUpdateProvider.kt index 17d24a1..d4d5d43 100644 --- a/inappupdater/src/main/java/at/allaboutapps/inappupdater/ForceUpdateProvider.kt +++ b/inappupdater/src/main/java/at/allaboutapps/inappupdater/ForceUpdateProvider.kt @@ -5,4 +5,4 @@ package at.allaboutapps.inappupdater */ interface ForceUpdateProvider { fun requestUpdateShouldBeImmediate(availableVersionCode: Int, doUpdate: () -> Unit) -} \ No newline at end of file +} diff --git a/inappupdater/src/main/java/at/allaboutapps/inappupdater/InAppUpdateManager.kt b/inappupdater/src/main/java/at/allaboutapps/inappupdater/InAppUpdateManager.kt index a621da8..25bac4c 100644 --- a/inappupdater/src/main/java/at/allaboutapps/inappupdater/InAppUpdateManager.kt +++ b/inappupdater/src/main/java/at/allaboutapps/inappupdater/InAppUpdateManager.kt @@ -18,7 +18,10 @@ import io.reactivex.disposables.Disposables * Usage: * TBD */ -class InAppUpdateManager(private val activity: Activity, private val forceUpdateProvider: ForceUpdateProvider? = null) { +class InAppUpdateManager( + private val activity: Activity, + private val forceUpdateProvider: ForceUpdateProvider? = null +) { companion object { const val REQUEST_CODE_IN_APP_UPDATE = 1230 @@ -37,8 +40,6 @@ class InAppUpdateManager(private val activity: Activity, private val forceUpdate */ fun observeInAppUpdateStatus(): Observable { return Observable.create { emitter -> - - val updateStateListener = InstallStateUpdatedListener { state -> if (currentInAppUpdateStatus.appUpdateState?.installStatus() != state.installStatus()) { currentInAppUpdateStatus = currentInAppUpdateStatus.copy(appUpdateState = state) @@ -49,15 +50,20 @@ class InAppUpdateManager(private val activity: Activity, private val forceUpdate } } } + // register listener appUpdateManager.registerListener(updateStateListener) // unregister listener on dispose - emitter.setDisposable(Disposables.fromAction { appUpdateManager.unregisterListener(updateStateListener) }) - + emitter.setDisposable(Disposables.fromAction { + appUpdateManager.unregisterListener( + updateStateListener + ) + }) appUpdateManager.appUpdateInfo.addOnSuccessListener { appUpdateInfo -> - currentInAppUpdateStatus = currentInAppUpdateStatus.copy(appUpdateInfo = appUpdateInfo) + currentInAppUpdateStatus = + currentInAppUpdateStatus.copy(appUpdateInfo = appUpdateInfo) // handle a forced update forceUpdateProvider?.requestUpdateShouldBeImmediate(currentInAppUpdateStatus.availableVersionCode) { @@ -68,7 +74,7 @@ class InAppUpdateManager(private val activity: Activity, private val forceUpdate if (appUpdateInfo.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) { //set state if app gets reopened with an update in progress currentInAppUpdateStatus = currentInAppUpdateStatus.copy( - appUpdateState = InstallState( + appUpdateState = InstallState.a( appUpdateInfo.installStatus(), 0, activity.packageName @@ -77,8 +83,6 @@ class InAppUpdateManager(private val activity: Activity, private val forceUpdate } emitter.onNext(currentInAppUpdateStatus) } - - } } @@ -89,10 +93,9 @@ class InAppUpdateManager(private val activity: Activity, private val forceUpdate * @param updateType set the type of the in app update */ fun startUpdate(@InAppUpdateType updateType: Int = AppUpdateType.FLEXIBLE) { - //to be save - //refetch the update status before starting the update process + // to be saved + // refetch the update status before starting the update process appUpdateManager.appUpdateInfo.addOnSuccessListener { appUpdateInfo -> - currentInAppUpdateStatus = currentInAppUpdateStatus.copy(appUpdateInfo = appUpdateInfo) appUpdateManager.startUpdateFlowForResult( @@ -120,4 +123,4 @@ class InAppUpdateManager(private val activity: Activity, private val forceUpdate @Retention(AnnotationRetention.SOURCE) @IntDef(UPDATE_TYPE_FLEXIBLE, UPDATE_TYPE_IMMEDIATE) annotation class InAppUpdateType -} \ No newline at end of file +} diff --git a/inappupdater/src/main/java/at/allaboutapps/inappupdater/InAppUpdateStatus.kt b/inappupdater/src/main/java/at/allaboutapps/inappupdater/InAppUpdateStatus.kt index 0657db7..103c99d 100644 --- a/inappupdater/src/main/java/at/allaboutapps/inappupdater/InAppUpdateStatus.kt +++ b/inappupdater/src/main/java/at/allaboutapps/inappupdater/InAppUpdateStatus.kt @@ -8,7 +8,7 @@ import com.google.android.play.core.install.model.UpdateAvailability const val NO_UPDATE = -1 /** - * This class is just a wrapper for AppupdateInfo and InstallState + * This class is just a wrapper for [AppUpdateInfo] and [InstallState] * Used by InAppUpdateManager */ data class InAppUpdateStatus( @@ -16,16 +16,15 @@ data class InAppUpdateStatus( val appUpdateState: InstallState? = null ) { - val availableVersionCode: Int get() = appUpdateInfo?.availableVersionCode() ?: NO_UPDATE + /** * Checks if an update is in progress */ val isUpdateInProgress: Boolean get() = appUpdateState != null - val isDownloading: Boolean get() = appUpdateState?.installStatus() == InstallStatus.DOWNLOADING @@ -35,11 +34,12 @@ data class InAppUpdateStatus( /** * Checks if an update is available */ - fun isUpdateAvailable() = appUpdateInfo?.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE + fun isUpdateAvailable() = + appUpdateInfo?.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE /** * Checks if an update is pending -> downloading/downloaded but not installed */ fun isUpdatePending() = appUpdateInfo?.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS -} \ No newline at end of file +}