forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainActivity.kt
More file actions
124 lines (108 loc) · 4.56 KB
/
MainActivity.kt
File metadata and controls
124 lines (108 loc) · 4.56 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package com.expensify.chat
import android.content.Intent
import android.content.pm.ActivityInfo
import android.os.Bundle
import android.util.Log
import android.view.KeyEvent
import android.view.View
import android.view.WindowInsets
import com.expensify.chat.bootsplash.BootSplash
import com.expensify.chat.intenthandler.IntentHandlerFactory
import com.expensify.reactnativekeycommand.KeyCommandModule
import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
import com.facebook.react.defaults.DefaultReactActivityDelegate
import expo.modules.ReactActivityDelegateWrapper
class MainActivity : ReactActivity() {
companion object {
private const val APP_START_TIME_PREFERENCES = "AppStartTime"
}
/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
*/
override fun getMainComponentName() = "NewExpensify"
var wasAppRelaunchedFromIcon: Boolean = false
/**
* Returns the instance of the [ReactActivityDelegate]. Here we use a util class [ ] which allows you to easily enable Fabric and Concurrent React
* (aka React 18) with two boolean flags.
*/
override fun createReactActivityDelegate() = ReactActivityDelegateWrapper(this, BuildConfig.IS_NEW_ARCHITECTURE_ENABLED, DefaultReactActivityDelegate(
this,
mainComponentName, // If you opted-in for the New Architecture, we enable the Fabric Renderer.
fabricEnabled
))
override fun onCreate(savedInstanceState: Bundle?) {
getSharedPreferences(APP_START_TIME_PREFERENCES, MODE_PRIVATE)
.edit()
.putLong(APP_START_TIME_PREFERENCES, System.currentTimeMillis())
.apply()
BootSplash.init(this)
super.onCreate(null)
// Sets translucent status bar. This code is based on what the react-native StatusBar
// module does, but we need to do it here to avoid the splash screen jumping on app start.
val decorView = window.decorView
decorView.setOnApplyWindowInsetsListener { v: View, insets: WindowInsets? ->
val defaultInsets = v.onApplyWindowInsets(insets)
defaultInsets.replaceSystemWindowInsets(
defaultInsets.systemWindowInsetLeft,
0,
defaultInsets.systemWindowInsetRight,
defaultInsets.systemWindowInsetBottom
)
}
if (intent != null) {
handleIntent(intent)
}
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
if (intent.hasCategory(Intent.CATEGORY_LAUNCHER)
&& intent.getAction() != null
&& intent.getAction().equals(Intent.ACTION_MAIN)) {
wasAppRelaunchedFromIcon = true
}
setIntent(intent) // Must store the new intent unless getIntent() will return the old one
handleIntent(intent)
}
private fun handleIntent(intent: Intent) {
try {
val intenthandler = IntentHandlerFactory.getIntentHandler(this, intent.type, intent.toString())
intenthandler?.handle(intent)
} catch (exception: Exception) {
Log.e("handleIntentException", exception.toString())
}
}
/**
* This method is called when a key down event has occurred.
* Forwards the event to the KeyCommandModule
*/
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
// Disabling hardware ESCAPE support which is handled by Android
if (event.keyCode == KeyEvent.KEYCODE_ESCAPE) {
return false
}
KeyCommandModule.getInstance().onKeyDownEvent(keyCode, event)
return super.onKeyDown(keyCode, event)
}
override fun onKeyLongPress(keyCode: Int, event: KeyEvent): Boolean {
// Disabling hardware ESCAPE support which is handled by Android
if (event.keyCode == KeyEvent.KEYCODE_ESCAPE) {
return false
}
KeyCommandModule.getInstance().onKeyDownEvent(keyCode, event)
return super.onKeyLongPress(keyCode, event)
}
override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
// Disabling hardware ESCAPE support which is handled by Android
if (event.keyCode == KeyEvent.KEYCODE_ESCAPE) {
return false
}
KeyCommandModule.getInstance().onKeyDownEvent(keyCode, event)
return super.onKeyUp(keyCode, event)
}
override fun onStart() {
super.onStart()
}
}