-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathComposeActivity.kt
More file actions
87 lines (80 loc) · 3.32 KB
/
ComposeActivity.kt
File metadata and controls
87 lines (80 loc) · 3.32 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Mask-Android
*
* Copyright (C) 2022 DimensionDev and Contributors
*
* This file is part of Mask-Android.
*
* Mask-Android is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Mask-Android 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Mask-Android. If not, see <http://www.gnu.org/licenses/>.
*/
package com.dimension.maskbook
import android.content.Intent
import android.os.Bundle
import android.view.WindowManager
import androidx.compose.runtime.CompositionLocalProvider
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsControllerCompat
import coil.compose.LocalImageLoader
import com.dimension.maskbook.common.gecko.PromptFeatureDelegate
import com.dimension.maskbook.common.gecko.WebContentController
import com.dimension.maskbook.common.manager.ImageLoaderManager
import com.dimension.maskbook.common.ui.widget.LocalWindowInsetsController
import com.dimension.maskbook.entry.ui.App
import com.google.accompanist.insets.ProvideWindowInsets
import moe.tlaster.precompose.lifecycle.PreComposeActivity
import moe.tlaster.precompose.lifecycle.setContent
import org.koin.android.ext.android.get
import org.koin.android.ext.android.inject
class ComposeActivity : PreComposeActivity() {
private lateinit var promptFeature: PromptFeatureDelegate
private val imageLoaderManager: ImageLoaderManager by inject()
private val windowInsetsControllerCompat by lazy {
WindowInsetsControllerCompat(window, window.decorView)
}
override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
promptFeature = get<WebContentController>().createPromptFeature(this)
setContent {
CompositionLocalProvider(
LocalImageLoader provides imageLoaderManager.imageLoader,
LocalWindowInsetsController provides windowInsetsControllerCompat,
) {
ProvideWindowInsets(
windowInsetsAnimationsEnabled = true
) {
App(
onInitialized = {
promptFeature.start()
},
)
}
}
}
}
override fun onBackPressed() {
if (!promptFeature.onBackPressed()) {
super.onBackPressed()
}
}
@Deprecated("Deprecated in Java")
@Suppress("DEPRECATION")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
promptFeature.onActivityResult(requestCode, data, resultCode)
}
}