Skip to content

Commit

Permalink
Merge pull request #3 from artnest/update-dependencies
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
mgursch authored Oct 16, 2019
2 parents 2dafb3d + 2febc8b commit fd06d9c
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 46 deletions.
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
10 changes: 4 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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
}
}

Expand Down
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
18 changes: 8 additions & 10 deletions inappupdater/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down Expand Up @@ -87,6 +86,7 @@ publishing {
}
}
}

task javadoc(type: Javadoc) {
excludes = ['**/*.kt'] // Exclude all kotlin files from javadoc file.
}
Expand Down Expand Up @@ -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'
apply plugin: 'digital.wup.android-maven-publish'
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ package at.allaboutapps.inappupdater
*/
interface ForceUpdateProvider {
fun requestUpdateShouldBeImmediate(availableVersionCode: Int, doUpdate: () -> Unit)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,8 +40,6 @@ class InAppUpdateManager(private val activity: Activity, private val forceUpdate
*/
fun observeInAppUpdateStatus(): Observable<InAppUpdateStatus> {
return Observable.create { emitter ->


val updateStateListener = InstallStateUpdatedListener { state ->
if (currentInAppUpdateStatus.appUpdateState?.installStatus() != state.installStatus()) {
currentInAppUpdateStatus = currentInAppUpdateStatus.copy(appUpdateState = state)
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -77,8 +83,6 @@ class InAppUpdateManager(private val activity: Activity, private val forceUpdate
}
emitter.onNext(currentInAppUpdateStatus)
}


}
}

Expand All @@ -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(
Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@ 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(
val appUpdateInfo: AppUpdateInfo? = null,
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

Expand All @@ -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
}
}

0 comments on commit fd06d9c

Please sign in to comment.