Merge branch 'release/2.2.4'

This commit is contained in:
Mikołaj Pich 2023-10-27 14:49:46 +02:00
commit aba08e6aa9
9 changed files with 76 additions and 90 deletions

View File

@ -27,8 +27,8 @@ android {
testApplicationId "io.github.tests.wulkanowy" testApplicationId "io.github.tests.wulkanowy"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 34 targetSdkVersion 34
versionCode 135 versionCode 136
versionName "2.2.3" versionName "2.2.4"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
resValue "string", "app_name", "Wulkanowy" resValue "string", "app_name", "Wulkanowy"
@ -162,7 +162,7 @@ play {
track = 'production' track = 'production'
releaseStatus = ReleaseStatus.IN_PROGRESS releaseStatus = ReleaseStatus.IN_PROGRESS
userFraction = 0.01d userFraction = 0.01d
updatePriority = 3 updatePriority = 0
enabled.set(false) enabled.set(false)
} }
@ -192,7 +192,7 @@ ext {
} }
dependencies { dependencies {
implementation 'io.github.wulkanowy:sdk:2.2.3' implementation 'io.github.wulkanowy:sdk:2.2.4'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3' coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3'
@ -253,10 +253,10 @@ dependencies {
playImplementation 'com.google.firebase:firebase-messaging:' playImplementation 'com.google.firebase:firebase-messaging:'
playImplementation 'com.google.firebase:firebase-crashlytics:' playImplementation 'com.google.firebase:firebase-crashlytics:'
playImplementation 'com.google.firebase:firebase-config-ktx' playImplementation 'com.google.firebase:firebase-config-ktx'
playImplementation 'com.google.android.play:core:1.10.3'
playImplementation 'com.google.android.play:core-ktx:1.8.1'
playImplementation 'com.google.android.gms:play-services-ads:22.4.0' playImplementation 'com.google.android.gms:play-services-ads:22.4.0'
playImplementation "com.google.android.play:integrity:1.2.0" playImplementation "com.google.android.play:integrity:1.2.0"
playImplementation 'com.google.android.play:app-update-ktx:2.1.0'
playImplementation 'com.google.android.play:review-ktx:2.0.1'
hmsImplementation 'com.huawei.hms:hianalytics:6.12.0.300' hmsImplementation 'com.huawei.hms:hianalytics:6.12.0.300'
hmsImplementation 'com.huawei.agconnect:agconnect-crash:1.9.1.301' hmsImplementation 'com.huawei.agconnect:agconnect-crash:1.9.1.301'

View File

@ -0,0 +1,13 @@
package io.github.wulkanowy.utils
import android.view.View
import javax.inject.Inject
class InAppUpdateHelper @Inject constructor() {
lateinit var messageContainer: View
fun checkAndInstallUpdates() {}
fun onResume() {}
}

View File

@ -1,17 +0,0 @@
package io.github.wulkanowy.utils
import android.app.Activity
import android.view.View
import javax.inject.Inject
@Suppress("UNUSED_PARAMETER")
class UpdateHelper @Inject constructor() {
lateinit var messageContainer: View
fun checkAndInstallUpdates(activity: Activity) {}
fun onActivityResult(requestCode: Int, resultCode: Int) {}
fun onResume(activity: Activity) {}
}

View File

@ -0,0 +1,13 @@
package io.github.wulkanowy.utils
import android.view.View
import javax.inject.Inject
class InAppUpdateHelper @Inject constructor() {
lateinit var messageContainer: View
fun checkAndInstallUpdates() {}
fun onResume() {}
}

View File

@ -1,17 +0,0 @@
package io.github.wulkanowy.utils
import android.app.Activity
import android.view.View
import javax.inject.Inject
@Suppress("UNUSED_PARAMETER")
class UpdateHelper @Inject constructor() {
lateinit var messageContainer: View
fun checkAndInstallUpdates(activity: Activity) {}
fun onActivityResult(requestCode: Int, resultCode: Int) {}
fun onResume(activity: Activity) {}
}

View File

@ -23,7 +23,7 @@ import io.github.wulkanowy.ui.modules.login.symbol.LoginSymbolFragment
import io.github.wulkanowy.ui.modules.main.MainActivity import io.github.wulkanowy.ui.modules.main.MainActivity
import io.github.wulkanowy.ui.modules.notifications.NotificationsFragment import io.github.wulkanowy.ui.modules.notifications.NotificationsFragment
import io.github.wulkanowy.utils.AppInfo import io.github.wulkanowy.utils.AppInfo
import io.github.wulkanowy.utils.UpdateHelper import io.github.wulkanowy.utils.InAppUpdateHelper
import javax.inject.Inject import javax.inject.Inject
@AndroidEntryPoint @AndroidEntryPoint
@ -33,7 +33,7 @@ class LoginActivity : BaseActivity<LoginPresenter, ActivityLoginBinding>(), Logi
override lateinit var presenter: LoginPresenter override lateinit var presenter: LoginPresenter
@Inject @Inject
lateinit var updateHelper: UpdateHelper lateinit var inAppUpdateHelper: InAppUpdateHelper
@Inject @Inject
lateinit var appInfo: AppInfo lateinit var appInfo: AppInfo
@ -47,10 +47,10 @@ class LoginActivity : BaseActivity<LoginPresenter, ActivityLoginBinding>(), Logi
setContentView(ActivityLoginBinding.inflate(layoutInflater).apply { binding = this }.root) setContentView(ActivityLoginBinding.inflate(layoutInflater).apply { binding = this }.root)
setSupportActionBar(binding.loginToolbar) setSupportActionBar(binding.loginToolbar)
messageContainer = binding.loginContainer messageContainer = binding.loginContainer
updateHelper.messageContainer = binding.loginContainer inAppUpdateHelper.messageContainer = binding.loginContainer
presenter.onAttachView(this) presenter.onAttachView(this)
updateHelper.checkAndInstallUpdates(this) inAppUpdateHelper.checkAndInstallUpdates()
if (savedInstanceState == null) { if (savedInstanceState == null) {
openFragment(LoginFormFragment.newInstance(), clearBackStack = true) openFragment(LoginFormFragment.newInstance(), clearBackStack = true)
@ -117,14 +117,6 @@ class LoginActivity : BaseActivity<LoginPresenter, ActivityLoginBinding>(), Logi
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
updateHelper.onResume(this) inAppUpdateHelper.onResume()
}
//https://developer.android.com/guide/playcore/in-app-updates#status_callback
@Deprecated("Deprecated in Java")
@Suppress("DEPRECATION")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
updateHelper.onActivityResult(requestCode, resultCode)
} }
} }

View File

@ -45,7 +45,7 @@ class MainActivity : BaseActivity<MainPresenter, ActivityMainBinding>(), MainVie
lateinit var analytics: AnalyticsHelper lateinit var analytics: AnalyticsHelper
@Inject @Inject
lateinit var updateHelper: UpdateHelper lateinit var inAppUpdateHelper: InAppUpdateHelper
@Inject @Inject
lateinit var inAppReviewHelper: InAppReviewHelper lateinit var inAppReviewHelper: InAppReviewHelper
@ -100,7 +100,7 @@ class MainActivity : BaseActivity<MainPresenter, ActivityMainBinding>(), MainVie
this.savedInstanceState = savedInstanceState this.savedInstanceState = savedInstanceState
messageContainer = binding.mainMessageContainer messageContainer = binding.mainMessageContainer
messageAnchor = binding.mainMessageContainer messageAnchor = binding.mainMessageContainer
updateHelper.messageContainer = binding.mainFragmentContainer inAppUpdateHelper.messageContainer = binding.mainFragmentContainer
onBackCallback = onBackPressedDispatcher.addCallback(this, enabled = false) { onBackCallback = onBackPressedDispatcher.addCallback(this, enabled = false) {
presenter.onBackPressed() presenter.onBackPressed()
} }
@ -109,19 +109,12 @@ class MainActivity : BaseActivity<MainPresenter, ActivityMainBinding>(), MainVie
?.takeIf { savedInstanceState == null } ?.takeIf { savedInstanceState == null }
presenter.onAttachView(this, destination) presenter.onAttachView(this, destination)
updateHelper.checkAndInstallUpdates(this) inAppUpdateHelper.checkAndInstallUpdates()
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
updateHelper.onResume(this) inAppUpdateHelper.onResume()
}
//https://developer.android.com/guide/playcore/in-app-updates#status_callback
@Deprecated("Deprecated in Java")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
updateHelper.onActivityResult(requestCode, resultCode)
} }
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {

View File

@ -1,4 +1,4 @@
Wersja 2.2.3 Wersja 2.2.4
— ułatwiliśmy przełączenie dnia na weekend w planie lekcji przy użyciu strzałek — ułatwiliśmy przełączenie dnia na weekend w planie lekcji przy użyciu strzałek
— poprawiliśmy wsparcie dla statystyk ocen z systemem punktowym — poprawiliśmy wsparcie dla statystyk ocen z systemem punktowym

View File

@ -3,12 +3,15 @@ package io.github.wulkanowy.utils
import android.app.Activity import android.app.Activity
import android.app.Activity.RESULT_OK import android.app.Activity.RESULT_OK
import android.content.Context import android.content.Context
import android.content.IntentSender
import android.view.View import android.view.View
import android.widget.Toast import android.widget.Toast
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import com.google.android.play.core.appupdate.AppUpdateInfo import com.google.android.play.core.appupdate.AppUpdateInfo
import com.google.android.play.core.appupdate.AppUpdateManagerFactory import com.google.android.play.core.appupdate.AppUpdateManagerFactory
import com.google.android.play.core.appupdate.AppUpdateOptions
import com.google.android.play.core.install.InstallStateUpdatedListener import com.google.android.play.core.install.InstallStateUpdatedListener
import com.google.android.play.core.install.model.AppUpdateType.FLEXIBLE import com.google.android.play.core.install.model.AppUpdateType.FLEXIBLE
import com.google.android.play.core.install.model.AppUpdateType.IMMEDIATE import com.google.android.play.core.install.model.AppUpdateType.IMMEDIATE
@ -20,15 +23,16 @@ import com.google.android.play.core.ktx.isFlexibleUpdateAllowed
import com.google.android.play.core.ktx.isImmediateUpdateAllowed import com.google.android.play.core.ktx.isImmediateUpdateAllowed
import com.google.android.play.core.ktx.updatePriority import com.google.android.play.core.ktx.updatePriority
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.android.scopes.ActivityScoped
import io.github.wulkanowy.R import io.github.wulkanowy.R
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton
@Singleton @ActivityScoped
class UpdateHelper @Inject constructor( class InAppUpdateHelper @Inject constructor(
@ApplicationContext private val context: Context, @ApplicationContext private val context: Context,
private val analyticsHelper: AnalyticsHelper, private val analyticsHelper: AnalyticsHelper,
activity: Activity
) { ) {
lateinit var messageContainer: View lateinit var messageContainer: View
@ -39,6 +43,7 @@ class UpdateHelper @Inject constructor(
when (state.installStatus()) { when (state.installStatus()) {
PENDING -> Toast.makeText(context, R.string.update_download_started, Toast.LENGTH_SHORT) PENDING -> Toast.makeText(context, R.string.update_download_started, Toast.LENGTH_SHORT)
.show() .show()
DOWNLOADED -> popupSnackBarForCompleteUpdate() DOWNLOADED -> popupSnackBarForCompleteUpdate()
else -> Timber.d("Update state: ${state.installStatus()}") else -> Timber.d("Update state: ${state.installStatus()}")
} }
@ -70,35 +75,46 @@ class UpdateHelper @Inject constructor(
return updateAvailability() == UPDATE_AVAILABLE && isFlexibleUpdateAllowed && isUpdatePriorityAllowUpdate return updateAvailability() == UPDATE_AVAILABLE && isFlexibleUpdateAllowed && isUpdatePriorityAllowUpdate
} }
fun checkAndInstallUpdates(activity: Activity) { private val activityResultLauncher = (activity as AppCompatActivity).registerForActivityResult(
ActivityResultContracts.StartIntentSenderForResult(),
::onActivityResult
)
fun checkAndInstallUpdates() {
Timber.d("Checking for updates...") Timber.d("Checking for updates...")
appUpdateManager.appUpdateInfo.addOnSuccessListener { appUpdateInfo -> appUpdateManager.appUpdateInfo.addOnSuccessListener { appUpdateInfo ->
when { when {
appUpdateInfo.isImmediateUpdateAvailable -> { appUpdateInfo.isImmediateUpdateAvailable -> {
startUpdate(activity, appUpdateInfo, IMMEDIATE) startUpdate(appUpdateInfo, IMMEDIATE)
} }
appUpdateInfo.isFlexibleUpdateAvailable -> { appUpdateInfo.isFlexibleUpdateAvailable -> {
appUpdateManager.registerListener(flexibleUpdateListener) appUpdateManager.registerListener(flexibleUpdateListener)
startUpdate(activity, appUpdateInfo, FLEXIBLE) startUpdate(appUpdateInfo, FLEXIBLE)
} }
else -> Timber.d("No update available") else -> Timber.d("No update available")
} }
} }
} }
private fun startUpdate(activity: Activity, appUpdateInfo: AppUpdateInfo, updateType: Int) { private fun startUpdate(appUpdateInfo: AppUpdateInfo, updateType: Int) {
Timber.d("Start update ($updateType): $appUpdateInfo") Timber.d("Start update ($updateType): $appUpdateInfo")
try { try {
appUpdateManager.startUpdateFlowForResult( appUpdateManager.startUpdateFlowForResult(
appUpdateInfo, updateType, activity, IN_APP_UPDATE_REQUEST_CODE appUpdateInfo,
activityResultLauncher,
AppUpdateOptions.defaultOptions(updateType)
) )
} catch (e: IntentSender.SendIntentException) { } catch (e: Exception) {
Timber.i("Update failed! Duplicated PendingIntent") Timber.e(e, "Update failed!")
} }
} }
fun onActivityResult(requestCode: Int, resultCode: Int) { private fun onActivityResult(activityResult: ActivityResult) {
if (requestCode == IN_APP_UPDATE_REQUEST_CODE) { val resultCode = activityResult.resultCode
if (resultCode != RESULT_OK) { if (resultCode != RESULT_OK) {
Timber.i("Update failed! Result code: $resultCode") Timber.i("Update failed! Result code: $resultCode")
Toast.makeText(context, R.string.update_failed, Toast.LENGTH_LONG).show() Toast.makeText(context, R.string.update_failed, Toast.LENGTH_LONG).show()
@ -106,9 +122,8 @@ class UpdateHelper @Inject constructor(
analyticsHelper.logEvent("inapp_update", "code" to resultCode) analyticsHelper.logEvent("inapp_update", "code" to resultCode)
} }
}
fun onResume(activity: Activity) { fun onResume() {
appUpdateManager.appUpdateInfo.addOnSuccessListener { info -> appUpdateManager.appUpdateInfo.addOnSuccessListener { info ->
Timber.d("InAppUpdate.onResume() listener: $info") Timber.d("InAppUpdate.onResume() listener: $info")
@ -116,7 +131,6 @@ class UpdateHelper @Inject constructor(
DOWNLOADED == info.installStatus() -> popupSnackBarForCompleteUpdate() DOWNLOADED == info.installStatus() -> popupSnackBarForCompleteUpdate()
DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS == info.updateAvailability() -> { DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS == info.updateAvailability() -> {
startUpdate( startUpdate(
activity = activity,
appUpdateInfo = info, appUpdateInfo = info,
updateType = if (info.isImmediateUpdateAvailable) IMMEDIATE else FLEXIBLE updateType = if (info.isImmediateUpdateAvailable) IMMEDIATE else FLEXIBLE
) )
@ -139,9 +153,4 @@ class UpdateHelper @Inject constructor(
show() show()
} }
} }
private companion object {
private const val IN_APP_UPDATE_REQUEST_CODE = 1721
}
} }