123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- package com.vpn.fastestvpnservice
- import android.content.Context
- import android.content.Intent
- import android.content.pm.ActivityInfo
- import android.content.pm.PackageManager
- import android.net.Uri
- import android.os.Build
- import android.os.Bundle
- import android.util.Log
- import android.view.WindowInsets
- import android.view.WindowInsetsController
- import android.view.WindowManager
- 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.SplashActivity
- 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.screens.helpScreensAll.fileChooserCallback
- import com.vpn.fastestvpnservice.ui.theme.FastestVPNTheme
- import com.vpn.fastestvpnservice.utils.StaticMethods
- import com.vpn.fastestvpnservice.viewmodels.LoginViewModel
- import com.vpn.fastestvpnservice.viewmodels.SplashViewModel
- import de.blinkt.openvpn.core.App
- open class MainActivity : DockActivity(), ConnectivityReceiver.ConnectivityReceiverListener {
- val loginViewModel: LoginViewModel by viewModels()
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- 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);
- }
- }
- 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()
- } 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)
- }
- 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)
- Log.d("test_file_chat", "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
- }
- override fun getContainerId(): Int {
- return R.id.mainFrameLayout
- }
- // 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
- }
- 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
- // )
- // }
|