Browse Source

fix crash when login, homescreen(res not found), added fonts on loginscreen..

Khubaib 1 year ago
parent
commit
b2f1298897

+ 1 - 0
app/build.gradle.kts

@@ -74,6 +74,7 @@ dependencies {
     implementation("androidx.navigation:navigation-compose:2.7.7")
     implementation("androidx.compose.material:material-icons-extended:1.6.1")
     implementation("androidx.compose.ui:ui-text-google-fonts:1.6.1")
+    implementation("androidx.compose.foundation:foundation:1.4.0-alpha04")
 
     // Retrofit
     implementation("com.squareup.retrofit2:retrofit:2.9.0")

+ 53 - 24
app/src/main/java/com/vpn/fastestvpnservice/screens/LoginScreen.kt

@@ -49,6 +49,7 @@ import androidx.compose.material3.CircularProgressIndicator
 import androidx.compose.material3.ElevatedButton
 import androidx.compose.material3.Icon
 import androidx.compose.material3.IconButton
+import androidx.compose.material3.MaterialTheme
 import androidx.compose.material3.Text
 import androidx.compose.material3.TextField
 import androidx.compose.material3.TextFieldColors
@@ -99,6 +100,7 @@ import com.vpn.fastestvpnservice.beans.themesList
 import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
 import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.AddText
 import com.vpn.fastestvpnservice.sealedClass.Screen
+import com.vpn.fastestvpnservice.ui.theme.outfitFontFamily
 import com.vpn.fastestvpnservice.viewmodels.LoginViewModel
 import kotlinx.coroutines.delay
 import kotlin.coroutines.coroutineContext
@@ -165,14 +167,20 @@ fun Login(navHostController: NavHostController) {
             Spacer(modifier = Modifier.height(50.dp))
 
             TextMsg(
-                fontSize = 28.sp,
                 text = "Welcome Back!",
-                color = Color.White
+                color = Color.White,
+                style = MaterialTheme.typography.displayLarge
             )
+            Spacer(modifier = Modifier.height(8.dp))
             TextMsg(
-                fontSize = 14.sp,
                 text = "Please login to your account.",
-                color = colorResource(id = R.color.light_grey)
+                color = colorResource(id = R.color.light_grey),
+                style = TextStyle(
+                    fontFamily = outfitFontFamily,
+                    fontWeight = FontWeight.Normal,
+                    fontSize = 14.sp,
+                    lineHeight = 30.sp,
+                )
             )
 
             Spacer(modifier = Modifier.height(20.dp))
@@ -183,11 +191,13 @@ fun Login(navHostController: NavHostController) {
                     textChanged = it
                 },
                 readOnly = readOnly!!,
-
                 textStyle = TextStyle(
-                    fontSize = 20.sp,
                     color = colorResource(id = R.color.white),
-
+                    fontFamily = outfitFontFamily,
+                    fontWeight = FontWeight.Normal,
+                    fontSize = 14.sp,
+                    lineHeight = 22.sp,
+                    letterSpacing = 0.21.sp
                 ),
                 modifier = Modifier
                     .padding(start = 15.dp, end = 15.dp)
@@ -208,7 +218,10 @@ fun Login(navHostController: NavHostController) {
                 label = {
                     Text(text = "Email",
                         style = TextStyle(
-                            colorResource(id = R.color.white))
+                            colorResource(id = R.color.white)),
+                        fontFamily = outfitFontFamily,
+                        fontWeight = FontWeight.Medium,
+                        fontSize = 12.sp,
                         )
                 },
                 leadingIcon = {
@@ -254,9 +267,12 @@ fun Login(navHostController: NavHostController) {
                 readOnly = readOnly,
 
                 textStyle = TextStyle(
-                    fontSize = 20.sp,
                     color = colorResource(id = R.color.white),
-
+                    fontFamily = outfitFontFamily,
+                    fontWeight = FontWeight.Normal,
+                    fontSize = 14.sp,
+                    lineHeight = 22.sp,
+                    letterSpacing = 0.21.sp
                     ),
                 modifier = Modifier
                     .padding(start = 15.dp, end = 15.dp)
@@ -279,7 +295,10 @@ fun Login(navHostController: NavHostController) {
                 label = {
                     Text(text = "Password",
                         style = TextStyle(
-                            colorResource(id = R.color.white))
+                            colorResource(id = R.color.white)),
+                        fontFamily = outfitFontFamily,
+                        fontWeight = FontWeight.Normal,
+                        fontSize = 16.sp,
                     )
                 },
                 leadingIcon = {
@@ -349,7 +368,7 @@ fun Login(navHostController: NavHostController) {
                 }
                 )
 
-            Spacer(modifier = Modifier.height(15.dp))
+            Spacer(modifier = Modifier.height(20.dp))
             ClickableText(
                 onClick = {
                     if (!readOnly) {
@@ -362,7 +381,9 @@ fun Login(navHostController: NavHostController) {
                     .align(Alignment.End),
                 style = TextStyle(
                     fontSize = 16.sp,
+                    fontFamily = outfitFontFamily,
                     fontWeight = FontWeight.Normal,
+                    textAlign = TextAlign.Right,
                     color = colorResource(id = R.color.yellow_text),
                 ),
                 text = AnnotatedString("Forgot Password"),
@@ -419,11 +440,15 @@ fun RowScope.TextMsgSignUp(
         Text(
             modifier = Modifier
                 .padding(0.dp),
-            fontSize = 14.sp,
-            fontWeight = FontWeight.Normal,
-            fontStyle = FontStyle.Normal,
             text = "Don't have an account? ",
-            color = Color.White,
+            style = TextStyle(
+                color = Color.White,
+                fontSize = 14.sp,
+                fontFamily = outfitFontFamily,
+                fontWeight = FontWeight.Normal,
+                lineHeight = 30.sp,
+                textAlign = TextAlign.Right
+            ),
         )
         ClickableText(
             onClick = {
@@ -434,9 +459,12 @@ fun RowScope.TextMsgSignUp(
             modifier = Modifier
                 .padding(0.dp),
             style = TextStyle(
-                fontSize = 14.sp,
-                fontStyle = FontStyle.Normal,
                 color = colorResource(id = R.color.yellow_text),
+                fontSize = 14.sp,
+                fontFamily = outfitFontFamily,
+                fontWeight = FontWeight.Normal,
+                lineHeight = 30.sp,
+                textAlign = TextAlign.Right
             ),
             text = AnnotatedString(" Sign Up"),
         )
@@ -515,9 +543,7 @@ fun BoxScope.SignInButton(
     )
     {
         Text(text = "Sign In",
-            fontSize = 18.sp,
-            fontWeight = FontWeight.Medium,
-            fontStyle = FontStyle.Normal
+            style = MaterialTheme.typography.titleMedium
         )
 
         val loginData by loginViewModel.liveDataUserResponse.observeAsState()
@@ -566,13 +592,16 @@ fun BoxScope.SignInButton(
 }
 
 @Composable
-fun ColumnScope.TextMsg(fontSize: TextUnit, text: String, color: Color) {
+fun ColumnScope.TextMsg(
+    text: String,
+    color: Color,
+    style: TextStyle
+) {
     Text(
         modifier = Modifier
             .padding(start = 15.dp)
             .align(Alignment.Start),
-        fontSize = fontSize,
-        fontWeight = FontWeight.Normal,
+        style = style,
         text = text,
         color = color,
     )

+ 32 - 11
app/src/main/java/com/vpn/fastestvpnservice/screens/StartedScreen.kt

@@ -37,6 +37,7 @@ import androidx.compose.ui.text.TextStyle
 import androidx.compose.ui.text.font.FontFamily
 import androidx.compose.ui.text.font.FontStyle
 import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.text.style.TextAlign
 import androidx.compose.ui.tooling.preview.Preview
 import androidx.compose.ui.tooling.preview.UiMode
 import androidx.compose.ui.unit.TextUnit
@@ -91,26 +92,32 @@ fun Started(navHostController: NavHostController) {
                 Text(
                     modifier = Modifier
                         .padding(start = 0.dp),
-                    fontSize = 14.sp,
-                    fontWeight = FontWeight.Normal,
                     text = "Top-notch security, blazing speed,",
-                    color = colorResource(id = R.color.light_grey),
+                    style = TextStyle(
+                        fontSize = 14.sp,
+                        fontWeight = FontWeight.Normal,
+                        color = colorResource(id = R.color.light_grey),
+                    ),
                 )
                 Text(
                     modifier = Modifier
                         .padding(start = 0.dp),
-                    fontSize = 14.sp,
-                    fontWeight = FontWeight.Normal,
                     text = "Unwavering stability. Your digital world,",
-                    color = colorResource(id = R.color.light_grey),
+                    style = TextStyle(
+                        fontSize = 14.sp,
+                        fontWeight = FontWeight.Normal,
+                        color = colorResource(id = R.color.light_grey),
+                        ),
                 )
                 Text(
                     modifier = Modifier
                         .padding(start = 0.dp),
-                    fontSize = 14.sp,
-                    fontWeight = FontWeight.Normal,
                     text = "Protected.",
-                    color = colorResource(id = R.color.light_grey),
+                    style = TextStyle(
+                        fontSize = 14.sp,
+                        fontWeight = FontWeight.Normal,
+                        color = colorResource(id = R.color.light_grey),
+                    )
                 )
             }
 
@@ -143,7 +150,14 @@ fun Started(navHostController: NavHostController) {
                     ),
                 )
                 {
-                    Text(text = "Sign In", fontSize = 20.sp)
+                    Text(text = "Sign In",
+                        style = TextStyle(
+                            fontFamily = outfitFontFamily,
+                            fontWeight = FontWeight.Medium,
+                            fontSize = 16.sp,
+                            textAlign = TextAlign.Center
+                        )
+                    )
                     Log.d("test_button", "RowScope")
                 }
 
@@ -171,7 +185,14 @@ fun Started(navHostController: NavHostController) {
                         colorResource(id = R.color.white))
                 )
                 {
-                    Text(text = "Sign Up", fontSize = 20.sp)
+                    Text(text = "Sign Up",
+                        style = TextStyle(
+                            fontFamily = outfitFontFamily,
+                            fontWeight = FontWeight.Medium,
+                            fontSize = 16.sp,
+                            textAlign = TextAlign.Center
+                        )
+                    )
                     Log.d("test_button", "RowScope")
                 }
             }

+ 29 - 24
app/src/main/java/com/vpn/fastestvpnservice/screens/bottomNavBarScreens/HomeScreen.kt

@@ -332,18 +332,20 @@ fun Home(navHostController: NavHostController, activity: ComponentActivity) {
             ) {
                 if (isConnect) {
                     val image = Utils.getDrawable(context, serverObj?.iso)
-                    Image(
-                        painter = painterResource(id = image),
-                        contentDescription = "Country",
-                        modifier = Modifier
-                            .padding(end = 6.dp)
-                            .size(20.dp)
-                            .clip(CircleShape)
-                            .paint(
-                                painter = painterResource(id = image),
-                                contentScale = ContentScale.FillHeight
-                            )
-                    )
+                    if (image != 0) {
+                        Image(
+                            painter = painterResource(id = image),
+                            contentDescription = "Country",
+                            modifier = Modifier
+                                .padding(end = 6.dp)
+                                .size(20.dp)
+                                .clip(CircleShape)
+                                .paint(
+                                    painter = painterResource(id = image),
+                                    contentScale = ContentScale.FillHeight
+                                )
+                        )
+                    }
                     AddText(
                         text = "${serverObj?.server_name}, ${serverObj?.country}",
                         size = 16.sp,
@@ -351,18 +353,21 @@ fun Home(navHostController: NavHostController, activity: ComponentActivity) {
                     )
                 } else {
                     val image = Utils.getDrawable(context, serverDis?.countryCode)
-                    Image(
-                        painter = painterResource(id = image),
-                        contentDescription = "Server",
-                        modifier = Modifier
-                            .padding(end = 6.dp)
-                            .size(20.dp)
-                            .clip(CircleShape)
-                            .paint(
-                                painter = painterResource(id = image),
-                                contentScale = ContentScale.FillHeight
-                            )
-                    )
+                    Log.d("image_logo", "$image ${serverDis?.countryCode}")
+                    if (image != 0) {
+                        Image(
+                            painter = painterResource(id = image),
+                            contentDescription = "Server",
+                            modifier = Modifier
+                                .padding(end = 6.dp)
+                                .size(20.dp)
+                                .clip(CircleShape)
+                                .paint(
+                                    painter = painterResource(id = image),
+                                    contentScale = ContentScale.FillHeight
+                                )
+                        )
+                    }
                     AddText(
                         text = "${serverDis?.city}, ${serverDis?.country}",
                         size = 16.sp,

+ 2 - 0
app/src/main/java/com/vpn/fastestvpnservice/utils/Utils.kt

@@ -2,6 +2,7 @@ package com.vpn.fastestvpnservice.utils
 
 import android.content.Context
 import android.graphics.drawable.Drawable
+import android.util.Log
 import androidx.compose.runtime.Composable
 import androidx.compose.runtime.DisposableEffect
 import androidx.compose.runtime.rememberUpdatedState
@@ -17,6 +18,7 @@ class Utils {
 
         fun getDrawable(context: Context, name: String?): Int {
             val iso = name?.toLowerCase().toString()
+            Log.d("image_logo", "iso => $iso")
             return context.resources.getIdentifier(iso, "drawable", context.packageName)
         }