瀏覽代碼

Showing new notifications from API along with heading on multi lingual

Khubaib 6 月之前
父節點
當前提交
4cc30d9fd8

+ 7 - 0
app/src/main/java/com/vpn/fastestvpnservice/beans/DataResponse.kt

@@ -18,6 +18,13 @@ data class DataResponseServers<T>(
     @SerializedName("data") var data: T? = null
 )
 
+data class DataResponseNotification<T>(
+    @SerializedName("status") var status: Boolean,
+    @SerializedName("message") var message: String? = null,
+    @SerializedName("heading") var heading: String? = null,
+    @SerializedName("data") var data: T? = null
+)
+
 data class DataResponseToken(
     @SerializedName("status") var status: Boolean,
     @SerializedName("message") var message: String? = null,

+ 8 - 3
app/src/main/java/com/vpn/fastestvpnservice/customItems/NotificationItem.kt

@@ -3,8 +3,10 @@ package com.vpn.fastestvpnservice.customItems
 import androidx.compose.foundation.background
 import androidx.compose.foundation.layout.Box
 import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Spacer
 import androidx.compose.foundation.layout.fillMaxSize
 import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
 import androidx.compose.foundation.layout.padding
 import androidx.compose.material.Text
 import androidx.compose.material3.MaterialTheme
@@ -19,6 +21,7 @@ import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
 import com.vpn.fastestvpnservice.R
 import com.vpn.fastestvpnservice.beans.Notification
+import com.vpn.fastestvpnservice.ui.theme.customTypography2
 
 @Composable
 fun NotificationItem(item: Notification) {
@@ -32,12 +35,14 @@ fun NotificationItem(item: Notification) {
             Text(
                 text = item.title,
                 color = MaterialTheme.colorScheme.primary,
-                style = MaterialTheme.typography.labelMedium,
+                style = MaterialTheme.typography.displayLarge.copy(
+                    color = MaterialTheme.colorScheme.primary,
+                    fontSize = 18.sp
+                ),
                 textAlign = TextAlign.Start,
                 modifier = Modifier
                     .padding(start = 16.dp, bottom = 5.dp, end = 4.dp)
                     .fillMaxWidth(),
-                maxLines = 2
             )
             Text(
                 text = item.html,
@@ -47,8 +52,8 @@ fun NotificationItem(item: Notification) {
                 modifier = Modifier
                     .padding(start = 16.dp, bottom = 0.dp, end = 4.dp)
                     .fillMaxWidth(),
-                maxLines = 2
             )
+            Spacer(modifier = Modifier.height(20.dp))
         }
     }
 }

+ 19 - 2
app/src/main/java/com/vpn/fastestvpnservice/screens/settingsScreenAll/NotificationsScreen.kt

@@ -5,8 +5,10 @@ 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.Spacer
 import androidx.compose.foundation.layout.fillMaxHeight
 import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
 import androidx.compose.foundation.layout.height
 import androidx.compose.foundation.layout.padding
 import androidx.compose.foundation.layout.size
@@ -28,6 +30,7 @@ import androidx.compose.ui.platform.LocalContext
 import androidx.compose.ui.platform.LocalView
 import androidx.compose.ui.res.colorResource
 import androidx.compose.ui.res.painterResource
+import androidx.compose.ui.text.style.TextAlign
 import androidx.compose.ui.tooling.preview.Preview
 import androidx.compose.ui.unit.dp
 import androidx.lifecycle.viewmodel.compose.viewModel
@@ -35,6 +38,7 @@ import androidx.navigation.NavHostController
 import androidx.navigation.compose.rememberNavController
 import com.vpn.fastestvpnservice.R
 import com.vpn.fastestvpnservice.customItems.NotificationItem
+import com.vpn.fastestvpnservice.ui.theme.customTypography2
 import com.vpn.fastestvpnservice.viewmodels.NotificationViewModel
 
 @Composable
@@ -65,9 +69,22 @@ fun Notifications(navHostController: NavHostController) {
         ) {
             val notifications = notificationViewModel.liveDataNotification.observeAsState().value
 
-            LazyColumn() {
+            notifications?.heading?.let {
+                Text(
+                    text = it,
+                    color = MaterialTheme.colorScheme.primary,
+                    style = MaterialTheme.typography.customTypography2.bodySmall,
+                    textAlign = TextAlign.Start,
+                    modifier = Modifier
+                        .padding(start = 16.dp, top = 5.dp, end = 4.dp)
+                        .fillMaxWidth(),
+                )
+            }
 
-                notifications?.let {
+            Spacer(modifier = Modifier.height(25.dp))
+
+            LazyColumn() {
+                notifications?.data?.let {
                     items(it) { item ->
                         NotificationItem(item = item)
                     }

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

@@ -53,7 +53,7 @@ fun NotificationsTV(navHostController: NavHostController) {
 
             LazyColumn() {
 
-                notifications?.let {
+                notifications?.data?.let {
                     items(it) { item ->
                         NotificationItemTV(item = item)
                     }

+ 6 - 5
app/src/main/java/com/vpn/fastestvpnservice/viewmodels/NotificationViewModel.kt

@@ -7,6 +7,7 @@ import androidx.lifecycle.ViewModel
 import com.google.gson.Gson
 import com.google.gson.reflect.TypeToken
 import com.vpn.fastestvpnservice.beans.DataResponse
+import com.vpn.fastestvpnservice.beans.DataResponseNotification
 import com.vpn.fastestvpnservice.beans.Notification
 import com.vpn.fastestvpnservice.retrofit.RetrofitNetworkHandling
 import com.vpn.fastestvpnservice.retrofit.WebServiceFactory
@@ -14,8 +15,8 @@ import retrofit2.Call
 
 class NotificationViewModel: ViewModel() {
 
-    val _mutableLiveDataNotification = MutableLiveData<List<Notification>?>()
-    val liveDataNotification: LiveData<List<Notification>?> = _mutableLiveDataNotification
+    val _mutableLiveDataNotification = MutableLiveData<DataResponseNotification<List<Notification>>?>()
+    val liveDataNotification: LiveData<DataResponseNotification<List<Notification>>?> = _mutableLiveDataNotification
 
     fun getNotifications() {
         WebServiceFactory.getInstance().getNotifications()
@@ -26,12 +27,12 @@ class NotificationViewModel: ViewModel() {
                     try {
                         val gson = Gson()
                         val jsonString = gson.toJson(response)
-                        val type = object : TypeToken<DataResponse<List<Notification>>>() {}.type
-                        val data = gson.fromJson<DataResponse<List<Notification>>>(jsonString, type)
+                        val type = object : TypeToken<DataResponseNotification<List<Notification>>>() {}.type
+                        val data = gson.fromJson<DataResponseNotification<List<Notification>>>(jsonString, type)
 
                     Log.d("test_api_response", "notification = ${data.message}")
 
-                        _mutableLiveDataNotification.value = data.data
+                        _mutableLiveDataNotification.value = data
                     } catch (ex: Exception) {
 
                     }