Skip to content

Commit

Permalink
Add Open In feed parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinokuni committed Dec 7, 2024
1 parent cf75fc9 commit ef9111c
Show file tree
Hide file tree
Showing 18 changed files with 355 additions and 202 deletions.
43 changes: 36 additions & 7 deletions app/src/main/java/com/readrops/app/feeds/FeedScreenModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.readrops.app.util.components.dialog.TextFieldDialogState
import com.readrops.db.Database
import com.readrops.db.entities.Feed
import com.readrops.db.entities.Folder
import com.readrops.db.entities.OpenIn
import com.readrops.db.filters.MainFilter
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -69,12 +70,22 @@ class FeedScreenModel(
}
.collect { foldersAndFeeds ->
_feedState.update { state ->
val dialog = if (state.dialog is DialogState.FeedSheet) {
val feed = foldersAndFeeds.values.flatten()
.first { it.id == state.dialog.feed.id }
state.dialog.copy(feed = feed)
} else {
state.dialog
val dialog = when (state.dialog) {
is DialogState.FeedSheet -> {
val feed = foldersAndFeeds.values.flatten()
.first { it.id == state.dialog.feed.id }
state.dialog.copy(feed = feed)
}

is DialogState.UpdateFeedOpenInSetting -> {
val feed = foldersAndFeeds.values.flatten()
.first { it.id == state.dialog.feed.id }
state.dialog.copy(feed = feed)
}

else -> {
state.dialog
}
}

state.copy(
Expand Down Expand Up @@ -137,7 +148,19 @@ class FeedScreenModel(
else -> {}
}

_feedState.update { it.copy(dialog = null) }
if (dialog is DialogState.UpdateFeedOpenInSetting) {
_feedState.update {
it.copy(
dialog = DialogState.FeedSheet(
feed = dialog.feed,
folder = null,
config = currentAccount!!.config
)
)
}
} else {
_feedState.update { it.copy(dialog = null) }
}
}

fun openDialog(state: DialogState) {
Expand Down Expand Up @@ -342,4 +365,10 @@ class FeedScreenModel(
database.feedDao().updateFeedNotificationState(feedId, isEnabled)
}
}

fun updateFeedOpenInSetting(feedId: Int, openIn: OpenIn) {
screenModelScope.launch(dispatcher) {
database.feedDao().updateOpenInSetting(feedId, openIn)
}
}
}
1 change: 1 addition & 0 deletions app/src/main/java/com/readrops/app/feeds/FeedState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ sealed interface DialogState {
class DeleteFolder(val folder: Folder) : DialogState
class UpdateFeed(val feed: Feed, val folder: Folder?) : DialogState
class UpdateFolder(val folder: Folder) : DialogState
data class UpdateFeedOpenInSetting(val feed: Feed) : DialogState

data class FeedSheet(
val feed: Feed,
Expand Down
101 changes: 3 additions & 98 deletions app/src/main/java/com/readrops/app/feeds/FeedTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
Expand All @@ -29,7 +28,6 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
Expand All @@ -46,14 +44,13 @@ import cafe.adriel.voyager.navigator.tab.Tab
import cafe.adriel.voyager.navigator.tab.TabOptions
import com.readrops.app.MainActivity
import com.readrops.app.R
import com.readrops.app.feeds.dialogs.FeedModalBottomSheet
import com.readrops.app.feeds.dialogs.UpdateFeedDialog
import com.readrops.app.feeds.components.FeedItem
import com.readrops.app.feeds.components.FolderExpandableItem
import com.readrops.app.feeds.dialogs.FeedDialogs
import com.readrops.app.feeds.newfeed.NewFeedScreen
import com.readrops.app.util.components.CenteredProgressIndicator
import com.readrops.app.util.components.ErrorMessage
import com.readrops.app.util.components.Placeholder
import com.readrops.app.util.components.dialog.TextFieldDialog
import com.readrops.app.util.components.dialog.TwoChoicesDialog
import com.readrops.app.util.theme.spacing
import com.readrops.db.entities.Feed
import kotlinx.coroutines.channels.Channel
Expand Down Expand Up @@ -260,98 +257,6 @@ object FeedTab : Tab {
}
}

@Composable
private fun FeedDialogs(state: FeedState, screenModel: FeedScreenModel) {
val uriHandler = LocalUriHandler.current

val folderState by screenModel.folderState.collectAsStateWithLifecycle()

when (val dialog = state.dialog) {
is DialogState.DeleteFeed -> {
TwoChoicesDialog(
title = stringResource(R.string.delete_feed),
text = stringResource(R.string.delete_feed_question, dialog.feed.name!!),
icon = rememberVectorPainter(image = Icons.Default.Delete),
confirmText = stringResource(R.string.delete),
dismissText = stringResource(R.string.cancel),
onDismiss = { screenModel.closeDialog() },
onConfirm = {
screenModel.deleteFeed(dialog.feed)
screenModel.closeDialog()
}
)
}

is DialogState.FeedSheet -> {
FeedModalBottomSheet(
feed = dialog.feed,
accountNotificationsEnabled = state.isAccountNotificationsEnabled,
onDismissRequest = { screenModel.closeDialog() },
onOpen = {
uriHandler.openUri(dialog.feed.siteUrl!!)
screenModel.closeDialog()
},
onUpdate = {
screenModel.openDialog(DialogState.UpdateFeed(dialog.feed, dialog.folder))
},
onDelete = { screenModel.openDialog(DialogState.DeleteFeed(dialog.feed)) },
onUpdateNotifications = {
screenModel.updateFeedNotifications(dialog.feed.id, it)
},
canUpdateFeed = dialog.config.canUpdateFeed,
canDeleteFeed = dialog.config.canDeleteFeed
)
}

is DialogState.UpdateFeed -> {
UpdateFeedDialog(
viewModel = screenModel,
onDismissRequest = { screenModel.closeDialog(dialog) }
)
}

DialogState.AddFolder -> {
TextFieldDialog(
title = stringResource(id = R.string.add_folder),
icon = painterResource(id = R.drawable.ic_new_folder),
label = stringResource(id = R.string.name),
state = folderState,
onValueChange = { screenModel.setFolderName(it) },
onValidate = { screenModel.folderValidate() },
onDismiss = { screenModel.closeDialog(DialogState.AddFolder) }
)
}

is DialogState.DeleteFolder -> {
TwoChoicesDialog(
title = stringResource(R.string.delete_folder),
text = stringResource(R.string.delete_folder_question, dialog.folder.name!!),
icon = rememberVectorPainter(image = Icons.Default.Delete),
confirmText = stringResource(R.string.delete),
dismissText = stringResource(R.string.cancel),
onDismiss = { screenModel.closeDialog() },
onConfirm = {
screenModel.deleteFolder(dialog.folder)
screenModel.closeDialog()
}
)
}

is DialogState.UpdateFolder -> {
TextFieldDialog(
title = stringResource(id = R.string.edit_folder),
icon = painterResource(id = R.drawable.ic_folder_grey),
label = stringResource(id = R.string.name),
state = folderState,
onValueChange = { screenModel.setFolderName(it) },
onValidate = { screenModel.folderValidate(updateFolder = true) },
onDismiss = { screenModel.closeDialog(DialogState.UpdateFolder(dialog.folder)) }
)
}

null -> {}
}
}

suspend fun openAddFeedDialog(url: String) {
addFeedDialogChannel.send(url)
Expand Down
111 changes: 111 additions & 0 deletions app/src/main/java/com/readrops/app/feeds/components/FeedBanner.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.readrops.app.feeds.components

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.blur
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import coil3.compose.AsyncImage
import com.readrops.app.R
import com.readrops.app.util.theme.MediumSpacer
import com.readrops.app.util.theme.VeryShortSpacer
import com.readrops.app.util.theme.spacing
import com.readrops.db.entities.Feed

@Composable
fun FeedBanner(feed: Feed) {
Column {
Box(
modifier = Modifier.fillMaxWidth()
) {
if (feed.imageUrl != null) {
AsyncImage(
model = feed.imageUrl,
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier
.matchParentSize()
.drawWithContent {
drawContent()
drawRect(
color = Color.Black.copy(alpha = 0.65f)
)
}
.blur(2.5.dp)
)
}

Row(
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(
top = MaterialTheme.spacing.largeSpacing,
start = MaterialTheme.spacing.largeSpacing,
end = MaterialTheme.spacing.largeSpacing,
bottom = MaterialTheme.spacing.mediumSpacing
)
) {
AsyncImage(
model = feed.iconUrl,
contentDescription = feed.name!!,
placeholder = painterResource(id = R.drawable.ic_rss_feed_grey),
error = painterResource(id = R.drawable.ic_rss_feed_grey),
modifier = Modifier.size(MaterialTheme.spacing.veryLargeSpacing)
)

MediumSpacer()

Column {
Text(
text = feed.name!!,
style = MaterialTheme.typography.titleLarge,
color = if (feed.imageUrl != null) {
Color.White
} else {
MaterialTheme.colorScheme.onBackground
},
maxLines = 1,
overflow = TextOverflow.Ellipsis
)

if (feed.description != null) {
VeryShortSpacer()

Text(
text = feed.description!!,
style = MaterialTheme.typography.bodyMedium,
color = if (feed.imageUrl != null) {
Color.White
} else {
MaterialTheme.colorScheme.onSurfaceVariant
},
maxLines = 2,
overflow = TextOverflow.Ellipsis
)
}
}
}
}

if (feed.imageUrl == null) {
HorizontalDivider(
modifier = Modifier.padding(horizontal = MaterialTheme.spacing.mediumSpacing)
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.readrops.app.feeds
package com.readrops.app.feeds.components

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.combinedClickable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.readrops.app.feeds
package com.readrops.app.feeds.components

import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.LinearOutSlowInEasing
Expand Down
Loading

0 comments on commit ef9111c

Please sign in to comment.