Skip to content

Commit

Permalink
Merge pull request #1621 from Infomaniak/Add-logs-to-inAppUpdate
Browse files Browse the repository at this point in the history
Try to fix update bug + add lots of logs for debug
  • Loading branch information
JorisBodin authored Jan 4, 2024
2 parents 41015d1 + 3784046 commit 5fe7242
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/com/infomaniak/mail/data/LocalSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.infomaniak.lib.core.utils.SentryLog
import com.infomaniak.lib.core.utils.SharedValue.sharedValue
import com.infomaniak.lib.core.utils.SharedValue.sharedValueNullable
import com.infomaniak.lib.core.utils.transaction
import com.infomaniak.lib.stores.StoreUtils.APP_UPDATE_TAG
import com.infomaniak.mail.MatomoMail.ACTION_ARCHIVE_NAME
import com.infomaniak.mail.MatomoMail.ACTION_DELETE_NAME
import com.infomaniak.mail.MatomoMail.ACTION_FAVORITE_NAME
Expand Down Expand Up @@ -71,6 +72,7 @@ class LocalSettings private constructor(context: Context) {
fun removeSettings() = sharedPreferences.transaction { clear() }

fun resetUpdateSettings() {
SentryLog.d(APP_UPDATE_TAG, "Reset update settings")
isUserWantingUpdates = false // This avoid the user being instantly reprompted to download update
hasAppUpdateDownloaded = false
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.infomaniak.lib.core.utils.DownloadManagerUtils
import com.infomaniak.lib.core.utils.SentryLog
import com.infomaniak.lib.core.utils.SingleLiveEvent
import com.infomaniak.lib.stores.StoreUtils
import com.infomaniak.lib.stores.StoreUtils.APP_UPDATE_TAG
import com.infomaniak.mail.MatomoMail.trackMultiSelectionEvent
import com.infomaniak.mail.R
import com.infomaniak.mail.data.LocalSettings
Expand Down Expand Up @@ -1023,11 +1024,16 @@ class MainViewModel @Inject constructor(
}

fun checkAppUpdateStatus() {
SentryLog.d(
tag = APP_UPDATE_TAG,
msg = "Setting canInstallUpdate value to ${localSettings.hasAppUpdateDownloaded} in checkAppUpdateStatus",
)
canInstallUpdate.value = localSettings.hasAppUpdateDownloaded
StoreUtils.checkStalledUpdate()
}

fun toggleAppUpdateStatus(isUpdateDownloaded: Boolean) {
SentryLog.d(APP_UPDATE_TAG, "Setting canInstallUpdate value to $isUpdateDownloaded in toggleAppUpdateStatus")
canInstallUpdate.value = isUpdateDownloaded
localSettings.hasAppUpdateDownloaded = isUpdateDownloaded
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import com.infomaniak.lib.core.MatomoCore.TrackerAction
import com.infomaniak.lib.core.utils.*
import com.infomaniak.lib.core.utils.Utils
import com.infomaniak.lib.stores.StoreUtils
import com.infomaniak.lib.stores.StoreUtils.APP_UPDATE_TAG
import com.infomaniak.mail.MatomoMail.trackEvent
import com.infomaniak.mail.MatomoMail.trackMenuDrawerEvent
import com.infomaniak.mail.MatomoMail.trackMultiSelectionEvent
Expand Down Expand Up @@ -566,13 +567,15 @@ class ThreadListFragment : Fragment(), SwipeRefreshLayout.OnRefreshListener {

private fun observeUpdateInstall() = with(binding) {
mainViewModel.canInstallUpdate.observe(viewLifecycleOwner) { isUpdateDownloaded ->
SentryLog.d(APP_UPDATE_TAG, "Must display update button : $isUpdateDownloaded")
installUpdateGroup.isVisible = isUpdateDownloaded
installUpdate.setOnClickListener {
SentryLog.d(APP_UPDATE_TAG, "Install downloaded Update from button")
trackEvent("inAppUpdate", "installUpdate")
mainViewModel.canInstallUpdate.value = false
localSettings.hasAppUpdateDownloaded = false

StoreUtils.installDownloadedUpdate(
onSuccess = { localSettings.hasAppUpdateDownloaded = false },
onFailure = {
Sentry.captureException(it)
localSettings.resetUpdateSettings()
Expand Down

0 comments on commit 5fe7242

Please sign in to comment.