From ab9d185b2d910681ca9481da75fc84724034aad7 Mon Sep 17 00:00:00 2001 From: jacobrein Date: Thu, 14 Nov 2024 07:44:11 -0700 Subject: [PATCH] - Feat: Implement 'Save for Later' Functionality in Details View This commit introduces a new "Save for Later" feature to the Details View. - When an item is not saved, a "Save for Later" button is added to the FAB menu. - Clicking this button adds the item to the saved items list and updates the button to "Remove from Saved". - When the item is saved, the button removes the item from the saved items list. - The functionality is implemented by adding new `addToSaved` and `isSaved` parameters to the Details View composable function. - Updates related icons and text for the "Save for Later" functionality. - Saves the item to the notification database. This allows users to easily save items for later viewing or updates. --- .../uiviews/details/DetailsUtils.kt | 10 +++++++++ .../uiviews/details/DetailsView.kt | 21 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/details/DetailsUtils.kt b/UIViews/src/main/java/com/programmersbox/uiviews/details/DetailsUtils.kt index 9c70e9d64..bb55d593c 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/details/DetailsUtils.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/details/DetailsUtils.kt @@ -421,6 +421,7 @@ fun DetailFloatingActionButtonMenu( onShowLists: () -> Unit, info: InfoModel, removeFromSaved: () -> Unit, + addToSaved: () -> Unit, isSaved: Boolean, canNotify: Boolean, notifyAction: () -> Unit, @@ -474,6 +475,15 @@ fun DetailFloatingActionButtonMenu( icon = { Icon(Icons.Default.BookmarkRemove, contentDescription = null) }, text = { Text(text = "Remove from Saved") }, ) + } else { + FloatingActionButtonMenuItem( + onClick = { + fabMenuExpanded = false + addToSaved() + }, + icon = { Icon(Icons.Default.Save, null) }, + text = { Text(stringResource(id = R.string.save_for_later)) }, + ) } FloatingActionButtonMenuItem( diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/details/DetailsView.kt b/UIViews/src/main/java/com/programmersbox/uiviews/details/DetailsView.kt index 6b3570e41..9b2f40f4e 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/details/DetailsView.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/details/DetailsView.kt @@ -63,6 +63,7 @@ import androidx.compose.ui.zIndex import androidx.core.graphics.ColorUtils import com.kmpalette.palette.graphics.Palette import com.programmersbox.favoritesdatabase.ChapterWatched +import com.programmersbox.favoritesdatabase.NotificationItem import com.programmersbox.helpfulutils.notificationManager import com.programmersbox.models.ChapterModel import com.programmersbox.models.InfoModel @@ -313,6 +314,26 @@ fun DetailsView( } }, isSaved = isSaved, + addToSaved = { + scope.launch(Dispatchers.IO) { + dao.insertNotification( + NotificationItem( + id = info.hashCode(), + url = info.url, + summaryText = context + .getString( + R.string.hadAnUpdate, + info.title, + info.chapters.firstOrNull()?.name.orEmpty() + ), + notiTitle = info.title, + imageUrl = info.imageUrl, + source = info.source.serviceName, + contentTitle = info.title + ) + ) + } + }, canNotify = canNotify, notifyAction = notifyAction, isFavorite = isFavorite,