2023-08-23 00:03:42 +03:00
|
|
|
package com.x8bit.bitwarden
|
|
|
|
|
2023-10-03 22:34:51 +03:00
|
|
|
import android.content.Intent
|
2023-08-23 00:03:42 +03:00
|
|
|
import android.os.Bundle
|
|
|
|
import androidx.activity.compose.setContent
|
2023-10-03 22:34:51 +03:00
|
|
|
import androidx.activity.viewModels
|
2024-01-13 00:43:18 +03:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
|
import androidx.appcompat.app.AppCompatDelegate
|
2024-01-17 02:41:34 +03:00
|
|
|
import androidx.compose.runtime.getValue
|
2024-01-13 00:43:18 +03:00
|
|
|
import androidx.core.os.LocaleListCompat
|
2023-09-28 22:18:03 +03:00
|
|
|
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
2024-01-17 02:41:34 +03:00
|
|
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
2024-01-13 00:43:18 +03:00
|
|
|
import com.x8bit.bitwarden.data.platform.repository.SettingsRepository
|
2023-09-05 21:13:26 +03:00
|
|
|
import com.x8bit.bitwarden.ui.platform.feature.rootnav.RootNavScreen
|
|
|
|
import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
|
2023-08-23 00:03:42 +03:00
|
|
|
import dagger.hilt.android.AndroidEntryPoint
|
2024-01-13 00:43:18 +03:00
|
|
|
import javax.inject.Inject
|
2023-08-23 00:03:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Primary entry point for the application.
|
|
|
|
*/
|
|
|
|
@AndroidEntryPoint
|
2024-01-13 00:43:18 +03:00
|
|
|
class MainActivity : AppCompatActivity() {
|
2023-10-03 22:34:51 +03:00
|
|
|
|
|
|
|
private val mainViewModel: MainViewModel by viewModels()
|
|
|
|
|
2024-01-13 00:43:18 +03:00
|
|
|
@Inject
|
|
|
|
lateinit var settingsRepository: SettingsRepository
|
|
|
|
|
2023-08-23 00:03:42 +03:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
2023-09-28 22:18:03 +03:00
|
|
|
var shouldShowSplashScreen = true
|
|
|
|
installSplashScreen().setKeepOnScreenCondition { shouldShowSplashScreen }
|
2023-08-23 00:03:42 +03:00
|
|
|
super.onCreate(savedInstanceState)
|
2024-01-20 00:01:43 +03:00
|
|
|
|
2024-01-21 20:35:39 +03:00
|
|
|
if (savedInstanceState == null) {
|
|
|
|
mainViewModel.trySendAction(
|
|
|
|
MainAction.ReceiveFirstIntent(
|
|
|
|
intent = intent,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
2024-01-20 00:01:43 +03:00
|
|
|
|
2024-01-13 00:43:18 +03:00
|
|
|
// Within the app the language will change dynamically and will be managed
|
|
|
|
// by the OS, but we need to ensure we properly set the language when
|
|
|
|
// upgrading from older versions that handle this differently.
|
|
|
|
settingsRepository.appLanguage.localeName?.let { localeName ->
|
|
|
|
val localeList = LocaleListCompat.forLanguageTags(localeName)
|
|
|
|
AppCompatDelegate.setApplicationLocales(localeList)
|
|
|
|
}
|
2023-08-29 17:43:15 +03:00
|
|
|
setContent {
|
2024-01-17 02:41:34 +03:00
|
|
|
val state by mainViewModel.stateFlow.collectAsStateWithLifecycle()
|
|
|
|
BitwardenTheme(
|
|
|
|
theme = state.theme,
|
|
|
|
) {
|
2023-09-28 22:18:03 +03:00
|
|
|
RootNavScreen(
|
|
|
|
onSplashScreenRemoved = { shouldShowSplashScreen = false },
|
|
|
|
)
|
2023-08-29 17:43:15 +03:00
|
|
|
}
|
|
|
|
}
|
2023-08-23 00:03:42 +03:00
|
|
|
}
|
2023-10-03 22:34:51 +03:00
|
|
|
|
|
|
|
override fun onNewIntent(intent: Intent) {
|
|
|
|
super.onNewIntent(intent)
|
2024-01-17 02:41:34 +03:00
|
|
|
mainViewModel.trySendAction(
|
2023-10-03 22:34:51 +03:00
|
|
|
action = MainAction.ReceiveNewIntent(
|
|
|
|
intent = intent,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
2023-08-23 00:03:42 +03:00
|
|
|
}
|