-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBaseActivity.kt
75 lines (65 loc) · 2.79 KB
/
BaseActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Infomaniak Mail - Android
* Copyright (C) 2022-2024 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.infomaniak.mail.ui
import android.os.Bundle
import androidx.annotation.IdRes
import androidx.appcompat.app.AppCompatActivity
import com.infomaniak.lib.applock.LockActivity
import com.infomaniak.lib.applock.Utils.isKeyguardSecure
import com.infomaniak.mail.MatomoMail.trackScreen
import com.infomaniak.mail.data.LocalSettings
import com.infomaniak.mail.utils.AccountUtils
import com.infomaniak.mail.utils.extensions.getMainApplication
import io.sentry.Sentry
import kotlinx.coroutines.runBlocking
open class BaseActivity : AppCompatActivity() {
// TODO: Try to replace this with a dependency injection.
// Currently, it crashes because the lateinit value isn't initialized when the `MainActivity.onCreate()` calls its super.
protected val localSettings by lazy { LocalSettings.getInstance(context = this) }
override fun onCreate(savedInstanceState: Bundle?) {
setTheme(localSettings.accentColor.theme)
if (AccountUtils.currentUser == null) runBlocking {
AccountUtils.requestCurrentUser()
if (AccountUtils.currentUser == null) {
Sentry.captureMessage("BaseActivity> the current user is null") { scope ->
scope.setExtra("has been fixed", "false")
}
}
}
super.onCreate(savedInstanceState)
trackScreen()
}
override fun onResume() {
super.onResume()
if (localSettings.isAppLocked && isKeyguardSecure()) with(getMainApplication()) {
lastAppClosingTime?.let {
LockActivity.lockAfterTimeout(
context = this@BaseActivity,
destinationClass = this::class.java,
lastAppClosingTime = it,
primaryColor = localSettings.accentColor.getPrimary(this),
)
}
resetLastAppClosing()
}
}
fun getCurrentFragment(@IdRes fragmentContainerViewId: Int) = supportFragmentManager
.findFragmentById(fragmentContainerViewId)
?.childFragmentManager
?.primaryNavigationFragment
}