Skip to content

Commit

Permalink
refactor(PR): Apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianDevel committed Dec 6, 2023
1 parent 3edf913 commit 207058a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Core
18 changes: 3 additions & 15 deletions app/src/main/java/com/infomaniak/mail/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import com.infomaniak.lib.core.utils.SentryLog
import com.infomaniak.lib.core.utils.Utils
import com.infomaniak.lib.core.utils.Utils.toEnumOrThrow
import com.infomaniak.lib.core.utils.UtilsUi.openUrl
import com.infomaniak.lib.stores.StoreUtils.checkStalledUpdate
import com.infomaniak.lib.stores.StoreUtils.checkUpdateIsAvailable
import com.infomaniak.lib.stores.StoreUtils.initAppUpdateManager
import com.infomaniak.lib.stores.StoreUtils.launchInAppReview
Expand Down Expand Up @@ -327,7 +326,7 @@ class MainActivity : BaseActivity() {
super.onResume()
playServicesUtils.checkPlayServices(this)

checkAppUpdateStatus()
mainViewModel.checkAppUpdateStatus()

if (binding.drawerLayout.isOpen) colorSystemBarsWithMenuDrawer()
}
Expand Down Expand Up @@ -464,14 +463,8 @@ class MainActivity : BaseActivity() {
private fun initAppUpdateManager() {
initAppUpdateManager(
context = this,
onUpdateDownloaded = {
mainViewModel.canInstallUpdate.value = true
localSettings.hasAppUpdateDownloaded = true
},
onUpdateInstalled = {
mainViewModel.canInstallUpdate.value = false
localSettings.hasAppUpdateDownloaded = false
},
onUpdateDownloaded = { mainViewModel.toggleAppUpdateStatus(isUpdateDownloaded = true) },
onUpdateInstalled = { mainViewModel.toggleAppUpdateStatus(isUpdateDownloaded = false) },
)
}

Expand All @@ -488,11 +481,6 @@ class MainActivity : BaseActivity() {
}
}

private fun checkAppUpdateStatus() {
mainViewModel.canInstallUpdate.value = localSettings.hasAppUpdateDownloaded
checkStalledUpdate()
}

private fun showSyncDiscovery() = with(localSettings) {
if (showSyncDiscoveryBottomSheet && appLaunches > 5 && !isUserAlreadySynchronized()) {
showSyncDiscoveryBottomSheet = false
Expand Down
17 changes: 15 additions & 2 deletions app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ import com.infomaniak.lib.core.models.ApiResponse
import com.infomaniak.lib.core.utils.ApiErrorCode.Companion.translateError
import com.infomaniak.lib.core.utils.SentryLog
import com.infomaniak.lib.core.utils.SingleLiveEvent
import com.infomaniak.lib.stores.StoreUtils
import com.infomaniak.mail.MatomoMail.trackMultiSelectionEvent
import com.infomaniak.mail.R
import com.infomaniak.mail.data.LocalSettings
import com.infomaniak.mail.data.api.ApiRepository
import com.infomaniak.mail.data.cache.RealmDatabase
import com.infomaniak.mail.data.cache.mailboxContent.*
import com.infomaniak.mail.data.cache.mailboxContent.RefreshController.*
import com.infomaniak.mail.data.cache.mailboxContent.RefreshController.RefreshCallbacks
import com.infomaniak.mail.data.cache.mailboxContent.RefreshController.RefreshMode
import com.infomaniak.mail.data.cache.mailboxInfo.MailboxController
import com.infomaniak.mail.data.cache.mailboxInfo.PermissionsController
import com.infomaniak.mail.data.cache.mailboxInfo.QuotasController
Expand All @@ -40,7 +43,6 @@ import com.infomaniak.mail.data.models.MoveResult
import com.infomaniak.mail.data.models.correspondent.Recipient
import com.infomaniak.mail.data.models.mailbox.Mailbox
import com.infomaniak.mail.data.models.message.Message
import com.infomaniak.mail.data.models.message.Message.*
import com.infomaniak.mail.data.models.thread.Thread
import com.infomaniak.mail.data.models.thread.Thread.ThreadFilter
import com.infomaniak.mail.di.IoDispatcher
Expand Down Expand Up @@ -72,6 +74,7 @@ class MainViewModel @Inject constructor(
private val addressBookController: AddressBookController,
private val draftController: DraftController,
private val folderController: FolderController,
private val localSettings: LocalSettings,
private val mailboxContentRealm: RealmDatabase.MailboxContent,
private val mailboxController: MailboxController,
private val mergedContactController: MergedContactController,
Expand Down Expand Up @@ -1014,6 +1017,16 @@ class MainViewModel @Inject constructor(
}
}

fun checkAppUpdateStatus() {
canInstallUpdate.value = localSettings.hasAppUpdateDownloaded
StoreUtils.checkStalledUpdate()
}

fun toggleAppUpdateStatus(isUpdateDownloaded: Boolean) {
canInstallUpdate.value = isUpdateDownloaded
localSettings.hasAppUpdateDownloaded = isUpdateDownloaded
}

companion object {
private val TAG: String = MainViewModel::class.java.simpleName
private val DEFAULT_SELECTED_FOLDER = FolderRole.INBOX
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[versions]
androidGradlePlugin = "8.1.4"
concurrentFuturesKtx = "1.1.0"
dotsindicator = "5.0"
dragdropswipeRecyclerview = "1.2.0"
firebaseMessagingKtx = "23.3.1"
Expand All @@ -20,6 +19,7 @@ realmKotlin = "1.12.0"
sentryAndroidFragment = "6.29.0"
testRunner = "1.5.2"
webkit = "1.8.0"
workConcurrentFutures = "1.1.0"
workRuntimeKtx = "2.8.1"

[libraries]
Expand All @@ -40,7 +40,7 @@ navigation-safeargs = { module = "androidx.navigation:navigation-safe-args-gradl
realm-kotlin-base = { module = "io.realm.kotlin:library-base", version.ref = "realmKotlin" }
sentry-android-fragment = { module = "io.sentry:sentry-android-fragment", version.ref = "sentryAndroidFragment" }
webkit = { module = "androidx.webkit:webkit", version.ref = "webkit" }
work-concurrent-futures = { module = "androidx.concurrent:concurrent-futures-ktx", version.ref = "concurrentFuturesKtx" }
work-concurrent-futures = { module = "androidx.concurrent:concurrent-futures-ktx", version.ref = "workConcurrentFutures" }
work-runtime-ktx = { module = "androidx.work:work-runtime-ktx", version.ref = "workRuntimeKtx" }
# Unit tests
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junitJupiterEngine" }
Expand Down

0 comments on commit 207058a

Please sign in to comment.