package com.vpn.fastestvpnservice import android.content.Context import android.content.Intent import android.content.pm.ActivityInfo import android.content.pm.PackageManager import android.content.res.Configuration import android.net.Uri import android.os.Build import android.os.Bundle import android.provider.Settings import android.util.Log import android.view.WindowInsets import android.view.WindowInsetsController import android.view.WindowManager import android.widget.Toast import androidx.activity.compose.setContent import androidx.activity.viewModels import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.colorResource import androidx.core.app.ActivityCompat import androidx.core.view.WindowCompat import androidx.fragment.app.FragmentManager import androidx.navigation.compose.rememberNavController import com.vpn.fastestvpnservice.activities.DockActivity import com.vpn.fastestvpnservice.activities.SplashActivity2 import com.vpn.fastestvpnservice.beans.isDarkTheme import com.vpn.fastestvpnservice.beans.themesList import com.vpn.fastestvpnservice.broadcasts.ConnectivityReceiver import com.vpn.fastestvpnservice.constants.AppEnum import com.vpn.fastestvpnservice.fragments.LoginFragment import com.vpn.fastestvpnservice.fragments.TvHomeFragment import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper import com.vpn.fastestvpnservice.interfaces.CallBacks import com.vpn.fastestvpnservice.interfaces.OnBackPressedOnTV import com.vpn.fastestvpnservice.interfaces.UpdateServersOnProtocol import com.vpn.fastestvpnservice.interfaces.VPNConnectionCallBacks import com.vpn.fastestvpnservice.navigation.SetUpNavGraph import com.vpn.fastestvpnservice.navigation.SetUpNavGraphTV import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.Settings import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.isSwitch import com.vpn.fastestvpnservice.screens.helpScreensAll.fileChooserCallback import com.vpn.fastestvpnservice.ui.theme.FastestVPNTheme import com.vpn.fastestvpnservice.utils.StaticMethods import com.vpn.fastestvpnservice.viewmodels.LoginViewModel import de.blinkt.openvpn.core.App open class MainActivity : DockActivity(), ConnectivityReceiver.ConnectivityReceiverListener { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // if (Thread.getDefaultUncaughtExceptionHandler() !is CustomExceptionHandler) { // Thread.setDefaultUncaughtExceptionHandler( // CustomExceptionHandler(this,"112","newverson","minhaj")); // } requestedOrientation = if (App.isAndroidTvBox) { /* This for Android-TV,Box APK */ ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE } else { /* This for Normal APK */ if (StaticMethods.isTV(this)) { ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE } else { ActivityInfo.SCREEN_ORIENTATION_PORTRAIT } } // setContentView(R.layout.activity_main) val basePreferenceHelper = BasePreferenceHelper(baseContext) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { if (ActivityCompat.checkSelfPermission( this, android.Manifest.permission.POST_NOTIFICATIONS ) != PackageManager.PERMISSION_GRANTED ) { requestPermissions(arrayOf(android.Manifest.permission.POST_NOTIFICATIONS), 1); } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && Settings.canDrawOverlays(this)) { isSwitch.value = true basePreferenceHelper.saveLaunchState(true) } WindowCompat.setDecorFitsSystemWindows(window, false) setContent { val context = LocalContext.current // val basePreferenceHelper = BasePreferenceHelper(context) val selectedTheme = basePreferenceHelper.getTheme() val isSystemInDarkTheme = isSystemInDarkTheme() val systemTheme by remember { mutableStateOf(isSystemInDarkTheme) } if (selectedTheme == themesList[0]) { isDarkTheme.value = systemTheme } else { isDarkTheme.value = selectedTheme == themesList[2] } if (StaticMethods.isTV(baseContext)) { Log.d("test_platform_android", "TV") // val intent = Intent(context, SplashActivity::class.java) // context.startActivity(intent) // finish() FastestVPNTheme(isDarkTheme.value) { // window.statusBarColor = colorResource(id = R.color.blue_text).toArgb() val navController = rememberNavController() SetUpNavGraphTV(navHostController = navController, this) } } else { Log.d("test_platform_android", "Mobile") FastestVPNTheme(isDarkTheme.value) { window.statusBarColor = colorResource(id = R.color.blue_text).toArgb() val navController = rememberNavController() SetUpNavGraph(navHostController = navController, this) } } } // hideSystemUI() // val bundle = intent.extras // bundle.let { // it?.getString(AppEnum.SCREEN_NAME.key).let { // it?.let { // Log.d("test_nav_tv", "bundle $it") // initFragment(it) // } // } // ?: kotlin.run { // basePreferenceHelper?.getUser()?.let { // Log.d("test_nav_tv", "kotlin.run") // initFragment(AppEnum.HOME_SCREEN.key) // } // } // } FragmentManager.enableDebugLogging(true) } // override fun onBackPressed() { // super.onBackPressed() // Toast.makeText( // baseContext, "onBackPressed()", Toast.LENGTH_SHORT // ).show() // } fun hideSystemUI() { //Hides the ugly action bar at the top actionBar?.hide() //Hide the status bars WindowCompat.setDecorFitsSystemWindows(window, false) if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN) } else { window.insetsController?.apply { hide(WindowInsets.Type.statusBars()) systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE } } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == 0) { // Log.d("test_file_chat", "onActivityResult: ${fileChooserCallback.toString()}") fileChooserCallback?.onReceiveValue(null) } else { fileChooserCallback?.onReceiveValue(arrayOf(Uri.parse(data?.dataString))) } fileChooserCallback = null if (requestCode == SCREEN_OVERLAY) { val basePreferenceHelper = BasePreferenceHelper(this) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && Settings.canDrawOverlays(this)) { isSwitch.value = true basePreferenceHelper.saveLaunchState(true) } } } override fun getContainerId(): Int { return R.id.mainFrameLayout } // override fun onConfigurationChanged(newConfig: Configuration) { // super.onConfigurationChanged(newConfig) // Toast.makeText(baseContext, "onConfigurationChanged", Toast.LENGTH_SHORT).show() // } // override fun getContainerId(): Int { // return 0 // } override fun onDestroy() { super.onDestroy() val basePreferenceHelper = BasePreferenceHelper(baseContext) if (!StaticMethods.isTV(this)) { basePreferenceHelper.clearServerObject() } Log.d("test_conn_ser_obj", "onDestroy() called") } fun getCallingIntent(_context: Context?): Intent { return Intent(_context, MainActivity::class.java) } fun initFragment(key: String) { Log.d("test_nav_tv", "initFragment() => $key") // val fragmentNavigator: FragmentNavigator = FragmentNavigator() when (key) { AppEnum.LOGIN_SCREEN.key -> { // val i = Intent(this, SplashActivity2::class.java) // startActivity(i) fragmentNavigator.replaceFragmentWithBackStack(LoginFragment.newInstance()) } AppEnum.HOME_SCREEN.key -> { // fragmentNavigator.clearAllFragments() if (App.isAndroidTvBox) { /* Android-TV,Box APK */ fragmentNavigator.replaceFragmentWithBackStackTv( TvHomeFragment.newInstance(), "tv_home" ) } else { /* Normal APK*/ if (StaticMethods.isTV(this)) { Log.d("test_nav_tv", "isTV =>") val i = Intent(this, SplashActivity2::class.java) startActivity(i) // fragmentNavigator.replaceFragmentWithBackStackTv(TvHomeFragment.newInstance(), "tv_home") } else { fragmentNavigator.replaceFragmentWithBackStack(TvHomeFragment.newInstance()) } } } // AppEnum.SIGNUP_SCREEN.key -> { // fragmentNavigator.replaceFragment(SignUpFragment.newInstance()) // } AppEnum.HELP_SCREEN.key -> { // fragmentNavigator.replaceFragment( // WebViewFragment.newInstance( // AppConstant.FAQ_WEBVIEW_URL, getString(R.string.help_faq) // ) // ) } } } companion object { var isWGDown: Boolean = true var isAutoEnabled: Boolean = false var isSnrNotify: Boolean = false var isSelectedServersShown: Boolean = false var vpnConnectionCallBacks: VPNConnectionCallBacks? = null var isStopSubscriptionNavigation: Boolean = true var updateServersOnProtocol: UpdateServersOnProtocol? = null var callBacks: CallBacks? = null var onBackPressedOnTV: OnBackPressedOnTV? = null val SCREEN_OVERLAY = 12345 } override fun onNetworkConnectionChanged(isConnected: Boolean) { } // override fun onBackPressed() { // super.onBackPressed() // // if (StaticMethods.isTV(this)) // { // Log.d("test_backTV", "TV Back!!") //// this@MainActivity.finishAffinity() // } // } } // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) // commenting now... // { // ActivityCompat.requestPermissions(this, // arrayOf( // android.Manifest.permission.ACCESS_FINE_LOCATION, // android.Manifest.permission.ACCESS_COARSE_LOCATION // ), // PackageManager.PERMISSION_GRANTED // ) // } // else { // ActivityCompat.requestPermissions(this, // arrayOf(android.Manifest.permission.ACCESS_FINE_LOCATION, // android.Manifest.permission.ACCESS_COARSE_LOCATION // ), // PackageManager.PERMISSION_GRANTED // ) // }