Skip to content

Commit

Permalink
feat: add new notification entity
Browse files Browse the repository at this point in the history
  • Loading branch information
aleixo-dev committed Oct 28, 2024
1 parent 55047d9 commit 01c66e4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.nicolas.picstream.data.local.database

import androidx.room.Database
import androidx.room.RoomDatabase
import com.nicolas.picstream.data.local.dao.NotificationDao
import com.nicolas.picstream.data.local.dao.PhotoDao
import com.nicolas.picstream.data.local.entity.NotificationEntity
import com.nicolas.picstream.data.local.entity.PhotoEntity

@Database(
entities = [
PhotoEntity::class,
NotificationEntity::class
],
version = 1,
exportSchema = false
)
abstract class ApplicationDatabase : RoomDatabase() {

abstract fun photoDao(): PhotoDao
abstract fun notificationDao(): NotificationDao

}

This file was deleted.

35 changes: 29 additions & 6 deletions app/src/main/java/com/nicolas/picstream/ui/home/HomeRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Clear
import androidx.compose.material.icons.rounded.Notifications
import androidx.compose.material.icons.rounded.NotificationsActive
import androidx.compose.material.icons.rounded.Search
import androidx.compose.material.icons.rounded.Settings
import androidx.compose.material3.CircularProgressIndicator
Expand Down Expand Up @@ -68,13 +69,16 @@ fun HomeRoute(
onNavigateNotifications: () -> Unit
) {

val context = LocalContext.current

val state by viewModel.photoState.collectAsStateWithLifecycle()
val topics by viewModel.photoTopics.collectAsStateWithLifecycle()
val searchPhotoPagingItems = viewModel.photoQueryState.collectAsLazyPagingItems()
val photosPagingItems = viewModel.photoLocalPagingFlow.collectAsLazyPagingItems()
val networkStatus = viewModel.networkConnectivityState.collectAsState()
val topicPhotos = viewModel.photoTopicFilter.collectAsLazyPagingItems()
val hideKeyboard by viewModel.hideKeyboard.collectAsStateWithLifecycle()
val popUpNotification by viewModel.isDownloadNotification.collectAsStateWithLifecycle()

LaunchedEffect(Unit) { viewModel.getTopics() }

Expand All @@ -90,7 +94,17 @@ fun HomeRoute(
topicPhotos = topicPhotos,
hideKeyboard = hideKeyboard,
onNavigateOptions = onNavigateOptions,
onNavigateNotifications = onNavigateNotifications
onNavigateNotifications = {
onNavigateNotifications()
viewModel.readAllDownloadNotification()
},
onDownloadImage = {
viewModel.saveDownloadNotification(
title = context.getString(R.string.local_notification),
photoDescription = it
)
},
popUpNotification = popUpNotification
)
}

Expand All @@ -107,7 +121,9 @@ fun HomeScreen(
topicPhotos: LazyPagingItems<Photo>,
hideKeyboard: Boolean,
onNavigateOptions: () -> Unit,
onNavigateNotifications: () -> Unit
onNavigateNotifications: () -> Unit,
onDownloadImage: (String) -> Unit,
popUpNotification: Boolean
) {

ReportDrawnWhen {
Expand Down Expand Up @@ -144,7 +160,9 @@ fun HomeScreen(
topicPhotos = topicPhotos,
hideKeyboard = hideKeyboard,
onNavigateOptions = onNavigateOptions,
onNavigateNotifications = onNavigateNotifications
onNavigateNotifications = onNavigateNotifications,
onDownloadImage = onDownloadImage,
popUpNotification = popUpNotification
)
}
}
Expand All @@ -163,7 +181,9 @@ fun SectionDefaultPhoto(
topicPhotos: LazyPagingItems<Photo>,
hideKeyboard: Boolean,
onNavigateOptions: () -> Unit,
onNavigateNotifications: () -> Unit
onNavigateNotifications: () -> Unit,
onDownloadImage: (String) -> Unit,
popUpNotification: Boolean
) {

val context = LocalContext.current
Expand Down Expand Up @@ -244,9 +264,11 @@ fun SectionDefaultPhoto(
modifier = Modifier
.size(26.dp)
.clickable { onNavigateNotifications.invoke() },
imageVector = Icons.Rounded.Notifications,
imageVector = if (popUpNotification)
Icons.Rounded.NotificationsActive else Icons.Rounded.Notifications,
contentDescription = null,
tint = MaterialTheme.colorScheme.onSurfaceVariant
tint = if (popUpNotification)
MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.onSurfaceVariant
)
Icon(
modifier = Modifier
Expand Down Expand Up @@ -299,6 +321,7 @@ fun SectionDefaultPhoto(
topicPhotos
} else if (text.isBlank()) photos else searchPhotoPagingItems,
networkStatus = networkStatus,
onDownloadImage = onDownloadImage
)
}

Expand Down

0 comments on commit 01c66e4

Please sign in to comment.