Selaa lähdekoodia

Added notificaton screen on TV, implemented notification API, set UI of screens.

Khubaib 9 kuukautta sitten
vanhempi
commit
1114534b6d

+ 30 - 0
app/src/main/java/com/vpn/fastestvpnservice/customItems/NotificationItem.kt

@@ -53,6 +53,36 @@ fun NotificationItem(item: Notification) {
     }
 }
 
+@Composable
+fun NotificationItemTV(item: Notification) {
+    Box(modifier = Modifier
+        .background(colorResource(id = R.color.background_color_gray))
+        .fillMaxWidth()
+    ) {
+        Column() {
+            Text(
+                text = item.title,
+                color = colorResource(id = R.color.dark_blue_gray_text),
+                style = MaterialTheme.typography.labelMedium,
+                textAlign = TextAlign.Start,
+                modifier = Modifier
+                    .padding(start = 16.dp, bottom = 5.dp, end = 4.dp)
+                    .fillMaxWidth(),
+                maxLines = 2
+            )
+            Text(
+                text = item.html,
+                color = colorResource(id = R.color.dark_blue_gray_text),
+                style = MaterialTheme.typography.labelMedium,
+                textAlign = TextAlign.Start,
+                modifier = Modifier
+                    .padding(start = 16.dp, bottom = 0.dp, end = 4.dp)
+                    .fillMaxWidth(),
+                maxLines = 2
+            )
+        }
+    }
+}
 @Preview
 @Composable
 fun NotificationItemPreview() {

+ 4 - 0
app/src/main/java/com/vpn/fastestvpnservice/navigation/BottomBarNavGraphTV.kt

@@ -15,6 +15,7 @@ import androidx.navigation.compose.composable
 import com.vpn.fastestvpnservice.screensTV.AccountTV
 import com.vpn.fastestvpnservice.screensTV.HelpTV
 import com.vpn.fastestvpnservice.screensTV.HomeTV
+import com.vpn.fastestvpnservice.screensTV.NotificationsTV
 import com.vpn.fastestvpnservice.screensTV.ServerListTV
 import com.vpn.fastestvpnservice.screensTV.SettingsTV
 import com.vpn.fastestvpnservice.screensTV.SplitTunnelingTV
@@ -64,6 +65,9 @@ fun BottomBarNavGraphTV(navHostController: NavHostController,
         composable(route = ScreenTV.SplitTunnelingTV.route) {
             SplitTunnelingTV(navHostController = navHostController)
         }
+        composable(route = ScreenTV.NotificationTV.route) {
+            NotificationsTV(navHostController = navHostController)
+        }
 
         /* Again declare for login because of different -> navHostController */
 //        composable(route = Screen.Login.route) {

+ 0 - 8
app/src/main/java/com/vpn/fastestvpnservice/screens/settingsScreenAll/NotificationsScreen.kt

@@ -2,7 +2,6 @@ package com.vpn.fastestvpnservice.screens.settingsScreenAll
 
 import android.app.Activity
 import androidx.compose.foundation.background
-import androidx.compose.foundation.gestures.detectTapGestures
 import androidx.compose.foundation.layout.Box
 import androidx.compose.foundation.layout.BoxScope
 import androidx.compose.foundation.layout.Column
@@ -17,8 +16,6 @@ import androidx.compose.material.Icon
 import androidx.compose.material.IconButton
 import androidx.compose.material.Surface
 import androidx.compose.material.Text
-import androidx.compose.material.icons.Icons
-import androidx.compose.material.icons.automirrored.filled.ArrowBack
 import androidx.compose.material3.MaterialTheme
 import androidx.compose.runtime.Composable
 import androidx.compose.runtime.livedata.observeAsState
@@ -26,16 +23,11 @@ import androidx.compose.ui.Alignment
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.graphics.Color
 import androidx.compose.ui.graphics.toArgb
-import androidx.compose.ui.input.pointer.pointerInput
 import androidx.compose.ui.platform.LocalView
 import androidx.compose.ui.res.colorResource
 import androidx.compose.ui.res.painterResource
-import androidx.compose.ui.text.TextStyle
-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.unit.dp
-import androidx.compose.ui.unit.sp
 import androidx.lifecycle.viewmodel.compose.viewModel
 import androidx.navigation.NavHostController
 import androidx.navigation.compose.rememberNavController

+ 107 - 0
app/src/main/java/com/vpn/fastestvpnservice/screensTV/NotificationScreenTV.kt

@@ -0,0 +1,107 @@
+package com.vpn.fastestvpnservice.screensTV
+
+import android.widget.Toast
+import androidx.compose.foundation.background
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.BoxScope
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.fillMaxHeight
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.foundation.lazy.items
+import androidx.compose.material.Icon
+import androidx.compose.material.IconButton
+import androidx.compose.material.Surface
+import androidx.compose.material.Text
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.livedata.observeAsState
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.res.colorResource
+import androidx.compose.ui.res.painterResource
+import androidx.compose.ui.unit.dp
+import androidx.lifecycle.viewmodel.compose.viewModel
+import androidx.navigation.NavHostController
+import com.vpn.fastestvpnservice.R
+import com.vpn.fastestvpnservice.customItems.NotificationItem
+import com.vpn.fastestvpnservice.customItems.NotificationItemTV
+import com.vpn.fastestvpnservice.screens.settingsScreenAll.HeaderRowNS
+import com.vpn.fastestvpnservice.viewmodels.NotificationViewModel
+
+@Composable
+fun NotificationsTV(navHostController: NavHostController) {
+    val notificationViewModel: NotificationViewModel = viewModel()
+    val context = LocalContext.current
+    Box(
+        modifier = Modifier
+            .fillMaxSize()
+            .background(
+                color = colorResource(id = R.color.background_color_gray)
+            )
+    ) {
+        LaunchedEffect(key1 = Unit) {
+            notificationViewModel.getNotifications()
+        }
+        HeaderRowNSTV(navHostController = navHostController)
+
+        Column(
+            modifier = Modifier
+                .padding(top = 60.dp)
+                .fillMaxSize()
+        ) {
+            val notifications = notificationViewModel.liveDataNotification.observeAsState().value
+
+            LazyColumn() {
+
+                notifications?.let {
+                    items(it) { item ->
+                        NotificationItemTV(item = item)
+                    }
+                }
+
+            }
+        }
+    }
+}
+
+@Composable
+fun BoxScope.HeaderRowNSTV(navHostController: NavHostController) {
+//    IconButton(
+//        onClick = {
+//            navHostController.popBackStack()
+////                    navHostController.navigate(BottomBarScreen.Help.route)
+//        },
+//        modifier = Modifier
+//            .align(Alignment.TopStart)
+//            .padding(top = 50.dp)
+//            .padding(start = 16.dp)
+//            .size(30.dp, 32.dp)
+//    ) {
+//        Icon(
+//            painter = painterResource(id = R.drawable.backarrow3x),
+//            contentDescription = "Arrow-Back",
+//            tint = MaterialTheme.colorScheme.primary,
+//            modifier = Modifier.size(18.dp, 12.dp)
+//        )
+//    }
+    Surface(
+        modifier = Modifier
+            .padding(start = 14.dp, top = 16.dp)
+            .height(32.dp)
+            .align(Alignment.TopStart),
+        color = colorResource(id = R.color.transparent)
+    ) {
+        Text(text = "Notifications",
+            color = MaterialTheme.colorScheme.primary,
+            style = MaterialTheme.typography.bodyMedium,
+            modifier = Modifier.fillMaxHeight()
+
+        )
+    }
+}

+ 1 - 1
app/src/main/java/com/vpn/fastestvpnservice/screensTV/SettingsScreenTV.kt

@@ -234,7 +234,7 @@ fun SettingsTV(navHostController: NavHostController) {
                 AddRowSettingsTV(
                     icon = R.drawable.notification3x,
                     text = "Notifications",
-                    onClick = { navHostController.navigate(Screen.Notifications.route) },
+                    onClick = { navHostController.navigate(ScreenTV.NotificationTV.route) },
                     isLastRow = true
                 )
 //                AddRowDarkLightThemeTV(

+ 2 - 2
app/src/main/java/com/vpn/fastestvpnservice/screensTV/SplitTunnelingTV.kt

@@ -185,9 +185,9 @@ fun BoxScope.HeaderRowSTTV(navHostController: NavHostController) {
 fun ColumnScope.ShowSplitTunnelListTV(list: List<SelectApplicationEntry>) {
 
     Box(modifier = Modifier
-        .padding(top = 5.dp)
+        .padding(top = 5.dp, bottom = 0.dp)
         .fillMaxSize()
-        .background(Color.Transparent)
+        .background(Color.LightGray)
     ) {
         LazyColumn() {
             itemsIndexed(items = list) {position, app ->

+ 1 - 0
app/src/main/java/com/vpn/fastestvpnservice/sealedClass/ScreenTV.kt

@@ -7,4 +7,5 @@ sealed class ScreenTV(val route: String) {
     data object BottomBarTV : ScreenTV("bottom_bar_tv")
     data object ServerListTV : ScreenTV("server_list_route")
     data object SplitTunnelingTV : ScreenTV("split_tunneling_tv")
+    data object NotificationTV : ScreenTV("notification_tv")
 }