Skip to content

Commit

Permalink
- Feat: Implement 'Save for Later' Functionality in Details View
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jacobrein committed Nov 14, 2024
1 parent e074ae6 commit ab9d185
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ fun DetailFloatingActionButtonMenu(
onShowLists: () -> Unit,
info: InfoModel,
removeFromSaved: () -> Unit,
addToSaved: () -> Unit,
isSaved: Boolean,
canNotify: Boolean,
notifyAction: () -> Unit,
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ab9d185

Please sign in to comment.