浏览代码

Compose_TV working...

Khubaib 1 年之前
父节点
当前提交
5c187d4d8e

+ 14 - 1
.idea/deploymentTargetDropDown.xml

@@ -6,7 +6,20 @@
         <State />
       </entry>
       <entry key="app">
-        <State />
+        <State>
+          <runningDeviceTargetSelectedWithDropDown>
+            <Target>
+              <type value="RUNNING_DEVICE_TARGET" />
+              <deviceKey>
+                <Key>
+                  <type value="VIRTUAL_DEVICE_PATH" />
+                  <value value="$USER_HOME$/.android/avd/Television_1080p_API_31.avd" />
+                </Key>
+              </deviceKey>
+            </Target>
+          </runningDeviceTargetSelectedWithDropDown>
+          <timeTargetWasSelectedWithDropDown value="2024-04-25T15:03:42.462350525Z" />
+        </State>
       </entry>
     </value>
   </component>

+ 4 - 0
app/build.gradle.kts

@@ -127,6 +127,10 @@ dependencies {
     implementation("androidx.constraintlayout:constraintlayout-compose:1.0.1")
 
 
+    // android view
+    implementation("androidx.constraintlayout:constraintlayout:2.0.4")
+
+
     testImplementation("junit:junit:4.13.2")
     androidTestImplementation("androidx.test.ext:junit:1.1.5")
     androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")

+ 23 - 1
app/src/main/AndroidManifest.xml

@@ -2,6 +2,13 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools">
 
+    <uses-feature
+        android:name="android.software.leanback"
+        android:required="false" />
+    <uses-feature
+        android:name="android.hardware.touchscreen"
+        android:required="false" />
+
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
@@ -27,6 +34,7 @@
         android:allowBackup="true"
         android:dataExtractionRules="@xml/data_extraction_rules"
         android:fullBackupContent="@xml/backup_rules"
+        android:banner="@drawable/logo_banner"
         android:icon="@drawable/app_logo_square"
         android:label="@string/app_name"
         android:roundIcon="@drawable/app_logo_round"
@@ -39,15 +47,29 @@
             android:name=".MainActivity"
             android:exported="true"
             android:label="@string/app_name"
-            android:screenOrientation="portrait"
             android:theme="@style/Theme.FastestVPN">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
 
                 <category android:name="android.intent.category.LAUNCHER" />
+                <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
+            </intent-filter>
+        </activity>
+
+        <activity
+            android:name=".activities.SplashActivity"
+            android:exported="true">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.DEFAULT" />
+
+                <!--                <category android:name="android.intent.category.LAUNCHER" />-->
+<!--                <category android:name="android.intent.category.LEANBACK_LAUNCHER" />-->
             </intent-filter>
         </activity>
 
+
         <activity
             android:name="org.strongswan.android.ui.VpnProfileControlActivity"
             android:excludeFromRecents="true"

+ 34 - 20
app/src/main/java/com/vpn/fastestvpnservice/MainActivity.kt

@@ -1,5 +1,6 @@
 package com.vpn.fastestvpnservice
 
+import android.content.Context
 import android.content.Intent
 import android.content.pm.PackageManager
 import android.net.Uri
@@ -32,6 +33,7 @@ import androidx.lifecycle.ViewModelProvider
 import androidx.lifecycle.get
 import androidx.lifecycle.viewmodel.compose.viewModel
 import androidx.navigation.compose.rememberNavController
+import com.vpn.fastestvpnservice.activities.SplashActivity
 import de.blinkt.openvpn.core.App
 import com.vpn.fastestvpnservice.beans.isDarkTheme
 import com.vpn.fastestvpnservice.beans.selectedtheme
@@ -42,12 +44,13 @@ import com.vpn.fastestvpnservice.navigation.SetUpNavGraph
 import com.vpn.fastestvpnservice.screens.helpScreensAll.fileChooserCallback
 import com.vpn.fastestvpnservice.sealedClass.Screen
 import com.vpn.fastestvpnservice.ui.theme.FastestVPNTheme
+import com.vpn.fastestvpnservice.utils.StaticMethods
 import com.vpn.fastestvpnservice.viewmodels.BillingViewModel
 import com.vpn.fastestvpnservice.viewmodels.LoginViewModel
 import com.vpn.fastestvpnservice.viewmodels.SplashViewModel
 import com.vpn.fastestvpnservice.viewmodels.SubscriptionViewModel
 
-class MainActivity : ComponentActivity() {
+open class MainActivity : ComponentActivity() {
     val loginViewModel: LoginViewModel by viewModels()
 
 
@@ -83,26 +86,34 @@ class MainActivity : ComponentActivity() {
 //            )
 //        }
 
-        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(this, SplashActivity::class.java)
+            startActivity(intent)
+        } else {
+            Log.d("test_platform_android", "Mobile")
+            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]
+                }
+
+                FastestVPNTheme(isDarkTheme.value) {
+                    window.statusBarColor = colorResource(id = R.color.blue_text).toArgb()
+                    val navController = rememberNavController()
+                    SetUpNavGraph(navHostController = navController, this)
+                }
 
-            FastestVPNTheme(isDarkTheme.value) {
-                window.statusBarColor = colorResource(id = R.color.blue_text).toArgb()
-                val navController = rememberNavController()
-                SetUpNavGraph(navHostController = navController, this)
             }
 
         }
@@ -130,6 +141,9 @@ class MainActivity : ComponentActivity() {
 
     }
 
+    fun getCallingIntent(_context: Context?): Intent {
+        return Intent(_context, MainActivity::class.java)
+    }
     companion object {
         var isWGDown: Boolean = true
         var isAutoEnabled: Boolean = false

+ 102 - 0
app/src/main/java/com/vpn/fastestvpnservice/activities/SplashActivity.kt

@@ -0,0 +1,102 @@
+package com.vpn.fastestvpnservice.activities
+
+import android.os.Bundle
+import android.os.Handler
+import android.view.View
+import android.view.animation.AnimationUtils
+import com.vpn.fastestvpnservice.MainActivity
+import com.vpn.fastestvpnservice.R
+import com.vpn.fastestvpnservice.constants.AppEnum
+import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
+import com.vpn.fastestvpnservice.helpers.UIHelper
+import com.vpn.fastestvpnservice.utils.StaticMethods
+import com.vpn.fastestvpnservice.viewmodels.LoginViewModel
+import com.vpn.fastestvpnservice.viewmodels.SplashViewModel
+import de.blinkt.openvpn.core.App
+
+class SplashActivity : MainActivity() {
+
+    lateinit var splashViewModel: SplashViewModel
+    lateinit var prefHelper: BasePreferenceHelper
+
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+        setContentView(R.layout.activity_splash)
+
+//        prefHelper = BasePreferenceHelper(baseContext)
+//        splashViewModel = SplashViewModel(this)
+//
+//        window.decorView.systemUiVisibility =
+//            View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+//
+//        loginViewModel.mutableLiveDataUserResponse.observe(this, androidx.lifecycle.Observer {
+//
+//            it?.let {
+//                if (it.status) {
+//
+//                    it.data?.let {
+//
+//                        it.servers?.let {
+//                            prefHelper?.saveServerData(it)
+//                        }
+//                        it.wireguard?.let {
+//                            prefHelper?.saveWireGuard(it)
+//                        }
+//                        it.available_protocols.let {
+//                            prefHelper?.saveAvailableProtocols(it)
+//                        }
+//                        it.enabled_protocols.let {
+//                            prefHelper?.saveEnabledProtocols(it)
+//                        }
+//
+//                        startActivity(
+//                            getCallingIntent(this@SplashActivity).putExtra(
+//                                AppEnum.SCREEN_NAME.key, AppEnum.HOME_SCREEN.key
+//                            )
+//                        )
+//                        finish()
+//
+//                    }
+//                } else {
+//                    UIHelper.showToast(it.message)
+//                }
+//            }
+//        })
+//        moveToLogin()
+
+    }
+
+    private fun moveToLogin() {
+        if (prefHelper.getUser() == null) {
+
+            if (App.isAndroidTvBox) {
+                /* Since this for specific android-tvbox, so only login_fragment*/
+                startActivity(
+                    getCallingIntent(this).putExtra(
+                        AppEnum.SCREEN_NAME.key,
+                        AppEnum.LOGIN_SCREEN.key
+                    )
+                )
+            }
+            else {
+                if (StaticMethods.isTV(this)) {
+                    startActivity(
+                        getCallingIntent(this).putExtra(
+                            AppEnum.SCREEN_NAME.key,
+                            AppEnum.LOGIN_SCREEN.key
+                        )
+                    )
+                }
+            }
+
+        } else {
+            splashViewModel.serverDataApi()
+            startActivity(
+                getCallingIntent(this@SplashActivity).putExtra(
+                    AppEnum.SCREEN_NAME.key, AppEnum.HOME_SCREEN.key
+                )
+            )
+            finish()
+        }
+    }
+}

+ 5 - 0
app/src/main/java/com/vpn/fastestvpnservice/utils/StaticMethods.java

@@ -21,6 +21,11 @@ public class StaticMethods {
         return uiModeManager != null && uiModeManager.getCurrentModeType() == UI_MODE_TYPE_TELEVISION;
     }
 
+    public static boolean isTV(Context context) {
+        UiModeManager uiModeManager = (UiModeManager) context.getSystemService(UI_MODE_SERVICE);
+        return uiModeManager != null && uiModeManager.getCurrentModeType() == UI_MODE_TYPE_TELEVISION;
+    }
+
     public static boolean isPhone(Activity activity) {
         return activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
     }

二进制
app/src/main/res/drawable-v24/logo_banner.png


+ 48 - 0
app/src/main/res/layout-land/activity_splash.xml

@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto">
+
+    <androidx.constraintlayout.widget.ConstraintLayout
+        android:id="@+id/activity_main"
+        android:layout_width="match_parent"
+        android:padding="@dimen/x10dp"
+        android:layout_height="match_parent"
+        android:background="@drawable/bg_app">
+
+        <ImageView
+            android:id="@+id/imageView"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:src="@drawable/ic_logo"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent" />
+
+        <ImageView
+            android:id="@+id/imageView2"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginBottom="18pt"
+            android:adjustViewBounds="true"
+            android:src="@drawable/logosplash"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent" />
+
+        <FrameLayout
+            android:id="@+id/container"
+            android:layout_width="0dp"
+            android:layout_height="0dp"
+            android:clickable="true"
+            android:focusable="true"
+            android:visibility="gone"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent"
+            app:layout_constraintVertical_bias="1.0" />
+
+    </androidx.constraintlayout.widget.ConstraintLayout>
+
+</layout>

+ 48 - 0
app/src/main/res/layout/activity_splash.xml

@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto">
+
+    <androidx.constraintlayout.widget.ConstraintLayout
+        android:id="@+id/activity_main"
+        android:layout_width="match_parent"
+        android:padding="@dimen/x10dp"
+        android:layout_height="match_parent"
+        android:background="@drawable/bg_app">
+
+        <ImageView
+            android:id="@+id/imageView"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:src="@drawable/ic_logo"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent" />
+
+        <ImageView
+            android:id="@+id/imageView2"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginBottom="18pt"
+            android:adjustViewBounds="true"
+            android:src="@drawable/logosplash"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent" />
+
+        <FrameLayout
+            android:id="@+id/container"
+            android:layout_width="0dp"
+            android:layout_height="0dp"
+            android:clickable="true"
+            android:focusable="true"
+            android:visibility="gone"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent"
+            app:layout_constraintVertical_bias="1.0" />
+
+    </androidx.constraintlayout.widget.ConstraintLayout>
+
+</layout>