Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.prof18.feedflow.android.feedsourcelist

import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.window.PopupProperties
import com.prof18.feedflow.core.model.FeedSource
import com.prof18.feedflow.shared.ui.components.ConfirmationDialog
import com.prof18.feedflow.shared.ui.utils.LocalFeedFlowStrings
import kotlinx.collections.immutable.ImmutableList

@Composable
internal fun CategoryHeaderContextMenu(
showMenu: Boolean,
feedSources: ImmutableList<FeedSource>,
hideMenu: () -> Unit,
onDeleteAllFeedsClick: (ImmutableList<FeedSource>) -> Unit,
) {
var showConfirmation by remember { mutableStateOf(false) }

DropdownMenu(
expanded = showMenu,
onDismissRequest = hideMenu,
properties = PopupProperties(
focusable = true,
dismissOnBackPress = true,
dismissOnClickOutside = true,
),
) {
DropdownMenuItem(
text = {
Text(LocalFeedFlowStrings.current.deleteAllFeedsInCategory)
},
onClick = {
hideMenu()
showConfirmation = true
},
)
}

if (showConfirmation) {
ConfirmationDialog(
title = LocalFeedFlowStrings.current.deleteAllFeedsConfirmationTitle,
message = LocalFeedFlowStrings.current.deleteAllFeedsConfirmationMessage,
onConfirm = {
onDeleteAllFeedsClick(feedSources)
},
onDismiss = {
showConfirmation = false
},
isDestructive = true,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.compose.animation.core.VisibilityThreshold
import androidx.compose.animation.core.spring
import androidx.compose.animation.expandVertically
import androidx.compose.animation.shrinkVertically
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -81,6 +80,7 @@ internal fun FeedSourcesWithCategoryList(
onRenameFeedSourceClick: (FeedSource, String) -> Unit,
onPinFeedClick: (FeedSource) -> Unit,
onOpenWebsite: (String) -> Unit,
onDeleteAllFeedsInCategory: (List<FeedSource>) -> Unit,
modifier: Modifier = Modifier,
) {
val layoutDir = LocalLayoutDirection.current
Expand All @@ -104,6 +104,8 @@ internal fun FeedSourcesWithCategoryList(

items(feedSourceState.feedSourcesWithCategory) { feedSourceState ->
Column {
var showCategoryMenu by remember { mutableStateOf(false) }

@Suppress("MagicNumber")
val degrees by conditionalAnimateFloatAsState(
targetValue = if (feedSourceState.isExpanded) {
Expand All @@ -116,9 +118,14 @@ internal fun FeedSourcesWithCategoryList(
Row(
modifier = Modifier
.clip(MaterialTheme.shapes.medium)
.clickable {
onExpandClicked(feedSourceState.categoryId)
}
.singleAndLongClickModifier(
onClick = {
onExpandClicked(feedSourceState.categoryId)
},
onLongClick = {
showCategoryMenu = true
},
)
.fillMaxWidth()
.padding(vertical = Spacing.regular),
horizontalArrangement = Arrangement.SpaceBetween,
Expand All @@ -141,6 +148,13 @@ internal fun FeedSourcesWithCategoryList(
)
}

CategoryHeaderContextMenu(
showMenu = showCategoryMenu,
feedSources = feedSourceState.feedSources,
hideMenu = { showCategoryMenu = false },
onDeleteAllFeedsClick = onDeleteAllFeedsInCategory,
)

FeedSourcesListWithCategorySelector(
feedSourceState = feedSourceState,
onDeleteFeedSourceClick = onDeleteFeedSourceClick,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fun FeedSourceListContent(
onPinFeedClick: (FeedSource) -> Unit,
onOpenWebsite: (String) -> Unit,
modifier: Modifier = Modifier,
onDeleteAllFeedsInCategory: (List<FeedSource>) -> Unit = {},
snackbarHost: @Composable () -> Unit = {},
) {
Scaffold(
Expand Down Expand Up @@ -52,6 +53,7 @@ fun FeedSourceListContent(
onEditFeedClick = onEditFeedSourceClick,
onPinFeedClick = onPinFeedClick,
onOpenWebsite = onOpenWebsite,
onDeleteAllFeedsInCategory = onDeleteAllFeedsInCategory,
paddingValues = paddingValues,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,8 @@ fun FeedSourceListScreen(
SnackbarHost(snackbarHostState)
},
onOpenWebsite = { url -> browserManager.openUrlWithFavoriteBrowser(url, context) },
onDeleteAllFeedsInCategory = { feedSources ->
viewModel.deleteAllFeedsInCategory(feedSources)
},
)
}
3 changes: 3 additions & 0 deletions i18n/src/commonMain/resources/locale/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@
<string name="delete_feed_confirmation_title">Delete feed?</string>
<string name="delete_feed_confirmation_message">Are you sure you want to delete this feed? This action cannot be undone.</string>
<string name="delete_feed_button">Delete feed</string>
<string name="delete_all_feeds_in_category">Delete all feeds</string>
<string name="delete_all_feeds_confirmation_title">Delete all feeds in category?</string>
<string name="delete_all_feeds_confirmation_message">Are you sure you want to delete all feeds in this category? This action cannot be undone.</string>
<string name="feed_fetch_failed_tooltip">Feed update failed. Please check if the site is working</string>
<string name="feed_fetch_failed_tooltip_short">Feed update failed</string>
<string name="support_the_project">Support the project</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ class FeedSourceListViewModel internal constructor(
}
}

fun deleteAllFeedsInCategory(feedSources: List<FeedSource>) {
viewModelScope.launch {
setExpandedCategory()
for (feedSource in feedSources) {
feedSourcesRepository.deleteFeed(feedSource)
}
feedFetcherRepository.fetchFeeds()
}
}

fun expandCategory(categoryId: CategoryId?) {
feedsMutableState.update { oldState ->
val newFeedSourceStates = oldState.feedSourcesWithCategory.map { feedSourceState ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,28 @@ class FeedSourceListViewModelTest : KoinTestBase() {
assertTrue(viewModel.feedSourcesState.value.isEmpty())
}

@Test
fun `deleteAllFeedsInCategory removes all feeds in category`() = runTest(testDispatcher) {
val techCategory = FeedSourceCategory(id = "tech", title = "Tech")
val newsCategory = FeedSourceCategory(id = "news", title = "News")
val techSource1 = createFeedSource(id = "tech-1", title = "Tech Source 1", category = techCategory)
val techSource2 = createFeedSource(id = "tech-2", title = "Tech Source 2", category = techCategory)
val newsSource = createFeedSource(id = "news-1", title = "News Source", category = newsCategory)

insertFeedSources(databaseHelper, techSource1, techSource2, newsSource)
advanceUntilIdle()

val stateBefore = viewModel.feedSourcesState.value
assertEquals(2, stateBefore.feedSourcesWithCategory.size)

viewModel.deleteAllFeedsInCategory(listOf(techSource1, techSource2))
advanceUntilIdle()

val stateAfter = viewModel.feedSourcesState.value
val remainingIds = stateAfter.feedSourcesWithCategory.flatMap { it.feedSources.map { fs -> fs.id } }
assertEquals(listOf("news-1"), remainingIds)
}

@Test
fun `errorState emits mapped errors`() = runTest(testDispatcher) {
viewModel.errorState.test {
Expand Down
Loading