Skip to content

Commit

Permalink
Update bunch of libs (#53)
Browse files Browse the repository at this point in the history
Update several libraries
  • Loading branch information
cmorigaki authored Aug 14, 2024
1 parent 4afb79a commit e81e927
Show file tree
Hide file tree
Showing 14 changed files with 292 additions and 206 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ out/
# Gradle files
.gradle/
build/
.kotlin/

# Local configuration file (sdk path, etc)
local.properties
Expand All @@ -45,6 +46,8 @@ captures/
.idea/dictionaries
.idea/libraries
.idea/misc.xml
.idea/deploymentTargetSelector.xml
.idea/other.xml
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
Expand Down
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

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

1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.ksp) apply false
alias(libs.plugins.easylauncher) apply false
alias(libs.plugins.compose) apply false
alias(libs.plugins.gradle.deps.update)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
package br.com.recipebook.inappupdate

import android.content.Intent
import android.os.Bundle
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import br.com.recipebook.utilityandroid.view.putSafeArgs
import br.com.recipebook.utilityandroid.view.safeArgs
import com.google.android.play.core.appupdate.AppUpdateManagerFactory
import com.google.android.play.core.appupdate.AppUpdateOptions
import com.google.android.play.core.install.model.UpdateAvailability
import com.google.android.play.core.ktx.startUpdateFlowForResult
import kotlinx.coroutines.CompletableDeferred

internal class InAppUpdateHeadlessFragment : Fragment() {
private val safeArgs by safeArgs<InAppUpdateSafeArgs>()

lateinit var completableDeferred: CompletableDeferred<InAppUpdateResult>

/**
* This launcher needs to be registered before "start" lifecycle state.
*/
private val activityResultLauncher = registerForActivityResult(
ActivityResultContracts.StartIntentSenderForResult()
) { result ->
if (result.resultCode != AppCompatActivity.RESULT_OK) {
// If the update is cancelled or fails,
// you can request to start the update again.
completeAndRemoveFragment(InAppUpdateResult.UpdateFailed)
} else {
completeAndRemoveFragment(InAppUpdateResult.UpdateCompleted)
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
checkInAppUpdate()
}

override fun onResume() {
super.onResume()
checkInAppUpdate()
Expand All @@ -35,9 +56,8 @@ internal class InAppUpdateHeadlessFragment : Fragment() {
// Request the update.
appUpdateManager.startUpdateFlowForResult(
appUpdateInfo,
safeArgs.appUpdateType,
this,
safeArgs.requestCode
activityResultLauncher,
AppUpdateOptions.newBuilder(safeArgs.appUpdateType).build(),
)
} else {
completeAndRemoveFragment(InAppUpdateResult.UpdateNotAvailable)
Expand All @@ -50,23 +70,6 @@ internal class InAppUpdateHeadlessFragment : Fragment() {
updateAvailability == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS
}

override fun onActivityResult(
requestCode: Int,
resultCode: Int,
data: Intent?
) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == safeArgs.requestCode) {
if (resultCode != AppCompatActivity.RESULT_OK) {
// If the update is cancelled or fails,
// you can request to start the update again.
completeAndRemoveFragment(InAppUpdateResult.UpdateFailed)
} else {
completeAndRemoveFragment(InAppUpdateResult.UpdateCompleted)
}
}
}

private fun completeAndRemoveFragment(result: InAppUpdateResult) {
if (::completableDeferred.isInitialized) {
completableDeferred.complete(result)
Expand All @@ -90,12 +93,10 @@ internal class InAppUpdateHeadlessFragment : Fragment() {
companion object {
fun newInstance(
appUpdateType: Int,
requestCode: Int
) = InAppUpdateHeadlessFragment()
.putSafeArgs(
InAppUpdateSafeArgs(
appUpdateType = appUpdateType,
requestCode = requestCode,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ private const val TAG = "InAppUpdateManager"

suspend fun FragmentActivity.requestInAppUpdate(
appUpdateType: Int,
requestCode: Int
): InAppUpdateResult {
val fragment = supportFragmentManager.findFragmentByTag(TAG) as? InAppUpdateHeadlessFragment
return if (fragment == null) {
val inAppUpdate = InAppUpdateHeadlessFragment.newInstance(
appUpdateType = appUpdateType,
requestCode = requestCode
).apply {
completableDeferred = CompletableDeferred()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ import kotlinx.parcelize.Parcelize
@Parcelize
data class InAppUpdateSafeArgs(
val appUpdateType: Int,
val requestCode: Int,
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ import br.com.recipebook.inappupdate.domain.InAppUpdater
import br.com.recipebook.inappupdate.requestInAppUpdate
import com.google.android.play.core.install.model.AppUpdateType

private const val RequestCode = 1292

internal class InAppUpdaterImpl(
private val activityProvider: ActivityProvider,
) : InAppUpdater {
override suspend fun invoke(): InAppUpdateResult {
return (activityProvider.activeActivity as? FragmentActivity)?.requestInAppUpdate(
appUpdateType = AppUpdateType.IMMEDIATE,
requestCode = RequestCode
) ?: InAppUpdateResult.UpdateFailed
}
}
38 changes: 19 additions & 19 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,61 +1,60 @@
[versions]
gradleplugin = "8.2.2"
kotlin = "1.9.0"
ksp = "1.9.0-1.0.13"
gradleplugin = "8.5.2"
kotlin = "2.0.0"
ksp = "2.0.0-1.0.24"
minSdk = "23"
compileSdk = "34"
compose = "1.5.2"

[libraries]
# Kotlin
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
kotlin-jdk = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" }
coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version = "1.8.0" }
coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version = "1.8.1" }
kotlin-result = { module = "com.michael-bull.kotlin-result:kotlin-result", version = "1.1.18" }

# Debug
leak-canary = { module = "com.squareup.leakcanary:leakcanary-android", version = "2.13" }

# Compose
compose-bom = { module = "androidx.compose:compose-bom", version = "2024.02.01" }
compose-bom = { module = "androidx.compose:compose-bom", version = "2024.06.00" }
compose-ui = { module = "androidx.compose.ui:ui" }
compose-foundation = { module = "androidx.compose.foundation:foundation" }
compose-material = { module = "androidx.compose.material:material" }
compose-materialIcons = { module = "androidx.compose.material:material-icons-core" }
compose-materialIconsExt = { module = "androidx.compose.material:material-icons-extended" }
compose-tooling = { module = "androidx.compose.ui:ui-tooling" }
compose-activity = { module = "androidx.activity:activity-compose", version = "1.8.2" }
compose-activity = { module = "androidx.activity:activity-compose", version = "1.9.1" }
compose-swipeRefresh = { module = "com.google.accompanist:accompanist-swiperefresh", version = "0.34.0" }
compose-collapsingToolbar = { module = "me.onebone:toolbar-compose", version = "2.3.5" }

# Network related libraries
retrofit = { module = "com.squareup.retrofit2:retrofit", version = "2.9.0" }
retrofit = { module = "com.squareup.retrofit2:retrofit", version = "2.11.0" }
okhttp = { module = "com.squareup.okhttp3:okhttp", version = "4.12.0" }
moshi-converter = { module = "com.squareup.retrofit2:converter-moshi", version = "2.9.0" }
moshi-converter = { module = "com.squareup.retrofit2:converter-moshi", version = "2.11.0" }
moshi-codegen = { module = "com.squareup.moshi:moshi-kotlin-codegen", version = "1.15.1" }
moshi = { module = "com.squareup.moshi:moshi", version = "1.15.1" }

# Android components
appCompat = { module = "androidx.appcompat:appcompat", version = "1.6.1" }
viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version = "2.7.0" }
fragment = { module = "androidx.fragment:fragment-ktx", version = "1.6.2" }
material = { module = "com.google.android.material:material", version = "1.11.0" }
appCompat = { module = "androidx.appcompat:appcompat", version = "1.7.0" }
viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version = "2.8.4" }
fragment = { module = "androidx.fragment:fragment-ktx", version = "1.8.2" }
material = { module = "com.google.android.material:material", version = "1.12.0" }

# Android utilities
play-core = { module = "com.google.android.play:core", version = "1.10.3" } # For in-App update
play-core-extensions = { module = "com.google.android.play:core-ktx", version = "1.8.1" }
play-core = { module = "com.google.android.play:app-update", version = "2.1.0" } # For in-App update
play-core-extensions = { module = "com.google.android.play:app-update-ktx", version = "2.1.0" }

# DI
koin-bom = { module = "io.insert-koin:koin-bom", version = "3.5.3" }
koin-core = { module = "io.insert-koin:koin-core" }
koin-android = { module = "io.insert-koin:koin-android" }

# Image download library
coil = { module = "io.coil-kt:coil", version = "2.5.0" }
coil-compose = { module = "io.coil-kt:coil-compose", version = "2.5.0" }
coil = { module = "io.coil-kt:coil", version = "2.7.0" }
coil-compose = { module = "io.coil-kt:coil-compose", version = "2.7.0" }

# Crash reporting library
sentry = { module = "io.sentry:sentry-android", version = "7.4.0" }
sentry = { module = "io.sentry:sentry-android", version = "7.9.0" }

# Analytics
amplitude = { module = "com.amplitude:android-sdk", version = "3.35.1" }
Expand All @@ -66,7 +65,7 @@ timber = { module = "com.jakewharton.timber:timber", version = "5.0.1" }
# Testing
junit = { module = "junit:junit", version = "4.13.2"}
mockk = { module = "io.mockk:mockk", version = "1.13.9"}
coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version = "1.8.0"}
coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version = "1.8.1"}

[bundles]

Expand All @@ -78,3 +77,4 @@ kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
easylauncher = { id = "com.starter.easylauncher", version = "6.2.0" }
gradle-deps-update = { id = "com.github.ben-manes.versions", version = "0.51.0" }
compose = { id = "org.jetbrains.kotlin.plugin.compose", version = "2.0.0" }
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 4 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Tue Feb 14 16:12:35 BRT 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit e81e927

Please sign in to comment.