Skip to content

Commit

Permalink
Show loader when deleting old entries
Browse files Browse the repository at this point in the history
  • Loading branch information
prof18 committed Jan 12, 2025
1 parent de59ede commit 22ab72e
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.prof18.feedflow.core.model.FeedItemUrlInfo
import com.prof18.feedflow.core.model.FeedSource
import com.prof18.feedflow.shared.presentation.HomeViewModel
import com.prof18.feedflow.shared.presentation.model.UIErrorState
import com.prof18.feedflow.shared.ui.home.components.DeleteOldFeedDialog
import com.prof18.feedflow.shared.ui.utils.LocalFeedFlowStrings
import org.koin.compose.koinInject
import org.koin.compose.viewmodel.koinViewModel
Expand All @@ -46,6 +47,11 @@ internal fun HomeScreen(
val currentFeedFilter by homeViewModel.currentFeedFilter.collectAsStateWithLifecycle()
val unReadCount by homeViewModel.unreadCountFlow.collectAsStateWithLifecycle(initialValue = 0)
val feedFontSizes by homeViewModel.feedFontSizeState.collectAsStateWithLifecycle()
val isDeleting by homeViewModel.isDeletingState.collectAsStateWithLifecycle()

if (isDeleting) {
DeleteOldFeedDialog()
}

val snackbarHostState = remember { SnackbarHostState() }
val context = LocalContext.current
Expand Down
2 changes: 1 addition & 1 deletion config/detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ complexity:
ignoreOverloaded: false
CyclomaticComplexMethod:
active: true
threshold: 15
threshold: 16
ignoreSingleWhenExpression: false
ignoreSimpleWhenEntries: false
ignoreNestingFunctions: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.prof18.feedflow.desktop.utils.WindowSizeClass
import com.prof18.feedflow.desktop.utils.WindowWidthSizeClass
import com.prof18.feedflow.shared.presentation.HomeViewModel
import com.prof18.feedflow.shared.presentation.model.UIErrorState
import com.prof18.feedflow.shared.ui.home.components.DeleteOldFeedDialog
import com.prof18.feedflow.shared.ui.utils.LocalFeedFlowStrings

@Composable
Expand All @@ -44,10 +45,15 @@ internal fun HomeScreen(
val currentFeedFilter by homeViewModel.currentFeedFilter.collectAsState()
val unReadCount by homeViewModel.unreadCountFlow.collectAsState(initial = 0)
val feedFontSizes by homeViewModel.feedFontSizeState.collectAsState()
val isDeleting by homeViewModel.isDeletingState.collectAsState()

val browserManager = DI.koin.get<BrowserManager>()
val strings = LocalFeedFlowStrings.current

if (isDeleting) {
DeleteOldFeedDialog()
}

LaunchedEffect(Unit) {
homeViewModel.errorState.collect { errorState ->
when (errorState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ expect fun String.format(vararg args: Any): String

@Suppress("UnusedPrivateProperty")
// This is a trick to be sure that KSP re-generates the strings when there's no code updates
private const val StringsVersion = 65
private const val StringsVersion = 66
1 change: 1 addition & 0 deletions i18n/src/commonMain/resources/locale/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,5 @@
<string name="settings_font_scale_subtitle_example">This is the subtitle of the article</string>
<string name="settings_font_scale_feed_source_example">Feed Name</string>
<string name="settings_feed_list_font_scale_title">Feed List Text scale</string>
<string name="deleting_feed_dialog_title">Deleting...</string>
</resources>
41 changes: 41 additions & 0 deletions iosApp/Source/Home/Components/DeleteOldFeedDialog.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import SwiftUI

struct DeleteOldFeedDialog: ViewModifier {
let isLoading: Bool
let message: String

func body(content: Content) -> some View {
ZStack {
content

if isLoading {
ZStack {
Color.black.opacity(0.3)
.ignoresSafeArea()
.allowsHitTesting(true)

VStack(spacing: Spacing.regular) {
ProgressView()
.scaleEffect(1.5)

Text(message)
.multilineTextAlignment(.center)
}
.padding(Spacing.medium)
.background {
RoundedRectangle(cornerRadius: 12)
.fill(.ultraThinMaterial)
}
.padding(Spacing.medium)
}
.transition(.opacity)
}
}
}
}

extension View {
func deletingFeedDialog(isLoading: Bool, message: String) -> some View {
modifier(DeleteOldFeedDialog(isLoading: isLoading, message: message))
}
}
9 changes: 9 additions & 0 deletions iosApp/Source/Home/HomeScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ struct HomeScreen: View {
@State
var feedFontSizes: FeedFontSizes = defaultFeedFontSizes()

@State
var isDeletingFeed: Bool = false

@Binding
var toggleListScroll: Bool

Expand Down Expand Up @@ -142,6 +145,12 @@ struct HomeScreen: View {
}
}
}
.deletingFeedDialog(isLoading: isDeletingFeed, message: feedFlowStrings.deletingFeedDialogTitle)
.task {
for await state in homeViewModel.isDeletingState {
self.isDeletingFeed = state as? Bool ?? false
}
}
.task {
for await state in homeViewModel.feedState {
self.feedState = state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class HomeViewModel internal constructor(
private val drawerMutableState = MutableStateFlow(NavDrawerState())
val navDrawerState = drawerMutableState.asStateFlow()

private val isDeletingMutableState = MutableStateFlow(false)
val isDeletingState: StateFlow<Boolean> = isDeletingMutableState.asStateFlow()

private var lastUpdateIndex = 0

val currentFeedFilter = feedRetrieverRepository.currentFeedFilter
Expand Down Expand Up @@ -207,7 +210,9 @@ class HomeViewModel internal constructor(

fun deleteOldFeedItems() {
viewModelScope.launch {
isDeletingMutableState.update { true }
feedRetrieverRepository.deleteOldFeeds()
isDeletingMutableState.update { false }
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.prof18.feedflow.shared.ui.home.components

import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import com.prof18.feedflow.shared.ui.style.Spacing
import com.prof18.feedflow.shared.ui.utils.LocalFeedFlowStrings

@Composable
fun DeleteOldFeedDialog() {
Dialog(
onDismissRequest = { },
properties = DialogProperties(
dismissOnBackPress = false,
dismissOnClickOutside = false,
),
) {
Surface(
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight(),
shape = MaterialTheme.shapes.medium,
color = MaterialTheme.colorScheme.surface,
tonalElevation = 8.dp
) {
Row(
modifier = Modifier
.padding(Spacing.regular),
verticalAlignment = androidx.compose.ui.Alignment.CenterVertically,
) {
CircularProgressIndicator()
Text(
modifier = Modifier
.padding(start = Spacing.regular),
text = LocalFeedFlowStrings.current.deletingFeedDialogTitle,
style = MaterialTheme.typography.bodyLarge,
)
}
}
}
}

0 comments on commit 22ab72e

Please sign in to comment.