Skip to content

Commit 8179a1e

Browse files
committed
Keep feed settings bundled together
1 parent 85ed324 commit 8179a1e

File tree

7 files changed

+57
-86
lines changed

7 files changed

+57
-86
lines changed

androidApp/src/main/kotlin/com/prof18/feedflow/android/editfeed/EditFeedScreen.android.kt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import androidx.compose.runtime.setValue
1818
import androidx.compose.ui.Modifier
1919
import androidx.compose.ui.platform.LocalContext
2020
import androidx.lifecycle.compose.collectAsStateWithLifecycle
21-
import com.prof18.feedflow.core.model.LinkOpeningPreference
21+
import com.prof18.feedflow.core.model.FeedSourceSettings
2222
import com.prof18.feedflow.core.utils.TestingTag
2323
import com.prof18.feedflow.shared.domain.model.FeedEditedState
2424
import com.prof18.feedflow.shared.presentation.EditFeedViewModel
@@ -36,9 +36,7 @@ internal fun EditScreen(
3636
) {
3737
val feedUrl by viewModel.feedUrlState.collectAsStateWithLifecycle()
3838
val feedName by viewModel.feedNameState.collectAsStateWithLifecycle()
39-
val linkOpeningPreference by viewModel.linkOpeningPreferenceState.collectAsStateWithLifecycle()
40-
val isHidden by viewModel.isHiddenFromTimelineState.collectAsStateWithLifecycle()
41-
val isPinned by viewModel.isPinnedState.collectAsStateWithLifecycle()
39+
val feedSourceSettings by viewModel.feedSourceSettingsState.collectAsStateWithLifecycle()
4240
var showLoading by remember { mutableStateOf(false) }
4341
var errorMessage by remember { mutableStateOf("") }
4442
var showError by remember { mutableStateOf(false) }
@@ -93,7 +91,7 @@ internal fun EditScreen(
9391
showLoading = showLoading,
9492
categoriesState = categoriesState,
9593
canEditUrl = viewModel.canEditUrl(),
96-
linkOpeningPreference = linkOpeningPreference,
94+
feedSourceSettings = feedSourceSettings,
9795
onFeedUrlUpdated = { url ->
9896
viewModel.updateFeedUrlTextFieldValue(url)
9997
},
@@ -103,11 +101,9 @@ internal fun EditScreen(
103101
onLinkOpeningPreferenceSelected = { preference ->
104102
viewModel.updateLinkOpeningPreference(preference)
105103
},
106-
isHidden = isHidden,
107104
onHiddenToggled = { hidden ->
108105
viewModel.updateIsHiddenFromTimeline(hidden)
109106
},
110-
isPinned = isPinned,
111107
onPinnedToggled = { pinned ->
112108
viewModel.updateIsPinned(pinned)
113109
},
@@ -152,20 +148,18 @@ internal fun EditScreen(
152148
private fun EditScreenPreview() {
153149
FeedFlowTheme {
154150
EditFeedContent(
155-
feedName = "Feed Name",
156151
feedUrl = "https://www.ablog.com/feed",
152+
feedName = "Feed Name",
157153
showError = false,
158154
showLoading = false,
159155
errorMessage = "",
160156
canEditUrl = true,
161157
categoriesState = categoriesExpandedState,
162-
linkOpeningPreference = LinkOpeningPreference.DEFAULT,
158+
feedSourceSettings = FeedSourceSettings(),
163159
onFeedUrlUpdated = {},
164160
onFeedNameUpdated = {},
165161
onLinkOpeningPreferenceSelected = {},
166-
isHidden = false,
167162
onHiddenToggled = {},
168-
isPinned = false,
169163
onPinnedToggled = {},
170164
editFeed = { },
171165
onExpandClick = {},
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.prof18.feedflow.core.model
2+
3+
data class FeedSourceSettings(
4+
val linkOpeningPreference: LinkOpeningPreference = LinkOpeningPreference.DEFAULT,
5+
val isHiddenFromTimeline: Boolean = false,
6+
val isPinned: Boolean = false,
7+
)

desktopApp/src/jvmMain/kotlin/com/prof18/feedflow/desktop/editfeed/EditFeedScreen.desktop.kt

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import cafe.adriel.voyager.core.screen.Screen
2222
import cafe.adriel.voyager.navigator.LocalNavigator
2323
import cafe.adriel.voyager.navigator.currentOrThrow
2424
import com.prof18.feedflow.core.model.FeedSource
25-
import com.prof18.feedflow.core.model.LinkOpeningPreference
25+
import com.prof18.feedflow.core.model.FeedSourceSettings
2626
import com.prof18.feedflow.core.utils.TestingTag
2727
import com.prof18.feedflow.desktop.desktopViewModel
2828
import com.prof18.feedflow.desktop.di.DI
@@ -48,9 +48,7 @@ internal data class EditFeedScreen(
4848

4949
val feedUrl by viewModel.feedUrlState.collectAsState()
5050
val feedName by viewModel.feedNameState.collectAsState()
51-
val linkOpeningPreference by viewModel.linkOpeningPreferenceState.collectAsState()
52-
val isHidden by viewModel.isHiddenFromTimelineState.collectAsState()
53-
val isPinned by viewModel.isPinnedState.collectAsState()
51+
val feedSourceSettings by viewModel.feedSourceSettingsState.collectAsState()
5452
var showLoading by remember { mutableStateOf(false) }
5553
var errorMessage by remember { mutableStateOf("") }
5654
var showError by remember { mutableStateOf(false) }
@@ -101,11 +99,11 @@ internal data class EditFeedScreen(
10199
feedUrl = feedUrl,
102100
feedName = feedName,
103101
showError = showError,
104-
errorMessage = errorMessage,
105102
showLoading = showLoading,
106-
categoriesState = categoriesState,
103+
errorMessage = errorMessage,
107104
canEditUrl = viewModel.canEditUrl(),
108-
linkOpeningPreference = linkOpeningPreference,
105+
categoriesState = categoriesState,
106+
feedSourceSettings = feedSourceSettings,
109107
onFeedUrlUpdated = { url ->
110108
viewModel.updateFeedUrlTextFieldValue(url)
111109
},
@@ -115,11 +113,9 @@ internal data class EditFeedScreen(
115113
onLinkOpeningPreferenceSelected = { preference ->
116114
viewModel.updateLinkOpeningPreference(preference)
117115
},
118-
isHidden = isHidden,
119116
onHiddenToggled = { hidden ->
120117
viewModel.updateIsHiddenFromTimeline(hidden)
121118
},
122-
isPinned = isPinned,
123119
onPinnedToggled = { pinned ->
124120
viewModel.updateIsPinned(pinned)
125121
},
@@ -166,21 +162,19 @@ internal data class EditFeedScreen(
166162
private fun EditScreenPreview() {
167163
FeedFlowTheme {
168164
EditFeedContent(
169-
feedName = "Feed Name",
170165
feedUrl = "https://www.ablog.com/feed",
166+
feedName = "Feed Name",
171167
showError = false,
172168
showLoading = false,
173-
canEditUrl = true,
174169
errorMessage = "",
170+
canEditUrl = true,
175171
categoriesState = categoriesExpandedState,
176-
linkOpeningPreference = LinkOpeningPreference.DEFAULT,
177-
isHidden = false,
178-
onHiddenToggled = {},
179-
isPinned = false,
180-
onPinnedToggled = {},
172+
feedSourceSettings = FeedSourceSettings(),
181173
onFeedUrlUpdated = {},
182174
onFeedNameUpdated = {},
183175
onLinkOpeningPreferenceSelected = {},
176+
onHiddenToggled = {},
177+
onPinnedToggled = {},
184178
editFeed = { },
185179
onExpandClick = {},
186180
onAddCategoryClick = {},

iosApp/FeedFlow.xcodeproj/project.pbxproj

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@
168168
7555FF78242A565900829871 /* Frameworks */,
169169
7555FF79242A565900829871 /* Resources */,
170170
7555FFB4242A642300829871 /* Embed Frameworks */,
171-
CC6E682B2A6475B1009F4A3C /* SwiftLint */,
172171
CCEA11BF2A6D2C6600C661AC /* Crashlytics */,
173172
CCEA11C12A6D454C00C661AC /* Crashlytics KMP */,
174173
);
@@ -316,25 +315,6 @@
316315
shellPath = /bin/sh;
317316
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\n\"$SRCROOT\"/.scripts/version.sh\n";
318317
};
319-
CC6E682B2A6475B1009F4A3C /* SwiftLint */ = {
320-
isa = PBXShellScriptBuildPhase;
321-
alwaysOutOfDate = 1;
322-
buildActionMask = 2147483647;
323-
files = (
324-
);
325-
inputFileListPaths = (
326-
);
327-
inputPaths = (
328-
);
329-
name = SwiftLint;
330-
outputFileListPaths = (
331-
);
332-
outputPaths = (
333-
);
334-
runOnlyForDeploymentPostprocessing = 0;
335-
shellPath = /bin/sh;
336-
shellScript = "if [[ \"$(uname -m)\" == arm64 ]]; then\n export PATH=\"/opt/homebrew/bin:$PATH\"\nfi\n\nif which swiftlint > /dev/null; then\n #echo \"\"\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download with brew install swiftlint\"\nfi\n";
337-
};
338318
CCEA11BF2A6D2C6600C661AC /* Crashlytics */ = {
339319
isa = PBXShellScriptBuildPhase;
340320
alwaysOutOfDate = 1;

iosApp/Source/Settings/EditFeed/EditFeedScreen.swift

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,10 @@ struct EditFeedScreen: View {
135135
}
136136
}
137137
.task {
138-
for await state in vmStoreOwner.instance.linkOpeningPreferenceState {
139-
self.linkOpeningPreference = state
140-
}
141-
}
142-
.task {
143-
for await state in vmStoreOwner.instance.isHiddenFromTimelineState {
144-
self.isHidden = state as? Bool ?? false
145-
}
146-
}
147-
.task {
148-
for await state in vmStoreOwner.instance.isPinnedState {
149-
self.isPinned = state as? Bool ?? false
138+
for await state in vmStoreOwner.instance.feedSourceSettingsState {
139+
self.linkOpeningPreference = state.linkOpeningPreference
140+
self.isHidden = state.isHiddenFromTimeline
141+
self.isPinned = state.isPinned
150142
}
151143
}
152144
}

shared/src/commonMain/kotlin/com/prof18/feedflow/shared/presentation/EditFeedViewModel.kt

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import androidx.lifecycle.ViewModel
44
import androidx.lifecycle.viewModelScope
55
import com.prof18.feedflow.core.model.CategoryName
66
import com.prof18.feedflow.core.model.FeedSource
7+
import com.prof18.feedflow.core.model.FeedSourceSettings
78
import com.prof18.feedflow.core.model.LinkOpeningPreference
89
import com.prof18.feedflow.core.model.SyncAccounts
910
import com.prof18.feedflow.shared.domain.feed.FeedSourcesRepository
@@ -31,14 +32,8 @@ class EditFeedViewModel internal constructor(
3132
private val feedNameMutableState = MutableStateFlow("")
3233
val feedNameState = feedNameMutableState.asStateFlow()
3334

34-
private val linkOpeningPreferenceMutableState = MutableStateFlow(LinkOpeningPreference.DEFAULT)
35-
val linkOpeningPreferenceState = linkOpeningPreferenceMutableState.asStateFlow()
36-
37-
private val isHiddenFromTimelineMutableState = MutableStateFlow(false)
38-
val isHiddenFromTimelineState = isHiddenFromTimelineMutableState.asStateFlow()
39-
40-
private val isPinnedMutableState = MutableStateFlow(false)
41-
val isPinnedState = isPinnedMutableState.asStateFlow()
35+
private val feedSourceSettingsMutableState = MutableStateFlow(FeedSourceSettings())
36+
val feedSourceSettingsState = feedSourceSettingsMutableState.asStateFlow()
4237

4338
private val feedEditedMutableState: MutableSharedFlow<FeedEditedState> = MutableSharedFlow()
4439
val feedEditedState = feedEditedMutableState.asSharedFlow()
@@ -61,21 +56,27 @@ class EditFeedViewModel internal constructor(
6156
}
6257

6358
fun updateLinkOpeningPreference(preference: LinkOpeningPreference) {
64-
linkOpeningPreferenceMutableState.update { preference }
59+
feedSourceSettingsMutableState.update { oldValue ->
60+
oldValue.copy(linkOpeningPreference = preference)
61+
}
6562
viewModelScope.launch {
6663
feedEditedMutableState.emit(FeedEditedState.Idle)
6764
}
6865
}
6966

7067
fun updateIsHiddenFromTimeline(isHidden: Boolean) {
71-
isHiddenFromTimelineMutableState.update { isHidden }
68+
feedSourceSettingsMutableState.update { oldValue ->
69+
oldValue.copy(isHiddenFromTimeline = isHidden)
70+
}
7271
viewModelScope.launch {
7372
feedEditedMutableState.emit(FeedEditedState.Idle)
7473
}
7574
}
7675

7776
fun updateIsPinned(isPinned: Boolean) {
78-
isPinnedMutableState.update { isPinned }
77+
feedSourceSettingsMutableState.update { oldValue ->
78+
oldValue.copy(isPinned = isPinned)
79+
}
7980
viewModelScope.launch {
8081
feedEditedMutableState.emit(FeedEditedState.Idle)
8182
}
@@ -87,9 +88,13 @@ class EditFeedViewModel internal constructor(
8788
viewModelScope.launch {
8889
feedUrlMutableState.update { feedSource.url }
8990
feedNameMutableState.update { feedSource.title }
90-
linkOpeningPreferenceMutableState.update { feedSource.linkOpeningPreference }
91-
isHiddenFromTimelineMutableState.update { feedSource.isHiddenFromTimeline }
92-
isPinnedMutableState.update { feedSource.isPinned }
91+
feedSourceSettingsMutableState.update {
92+
FeedSourceSettings(
93+
linkOpeningPreference = feedSource.linkOpeningPreference,
94+
isHiddenFromTimeline = feedSource.isHiddenFromTimeline,
95+
isPinned = feedSource.isPinned,
96+
)
97+
}
9398

9499
val categoryName = feedSource.category?.title?.let { CategoryName(it) }
95100
categoryUseCase.initCategories(categoryName)
@@ -126,9 +131,9 @@ class EditFeedViewModel internal constructor(
126131
url = feedUrlState.value,
127132
title = feedNameState.value,
128133
category = selectedCategory,
129-
linkOpeningPreference = linkOpeningPreferenceState.value,
130-
isHiddenFromTimeline = isHiddenFromTimelineState.value,
131-
isPinned = isPinnedState.value,
134+
linkOpeningPreference = feedSourceSettingsState.value.linkOpeningPreference,
135+
isHiddenFromTimeline = feedSourceSettingsState.value.isHiddenFromTimeline,
136+
isPinned = feedSourceSettingsState.value.isPinned,
132137
)
133138

134139
if (newFeedSource != null && newFeedSource != originalFeedSource) {

sharedUI/src/commonMain/kotlin/com/prof18/feedflow/shared/ui/feed/editfeed/EditFeedComponents.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import androidx.compose.ui.graphics.Color
1818
import com.prof18.feedflow.core.model.CategoriesState
1919
import com.prof18.feedflow.core.model.CategoryId
2020
import com.prof18.feedflow.core.model.CategoryName
21+
import com.prof18.feedflow.core.model.FeedSourceSettings
2122
import com.prof18.feedflow.core.model.LinkOpeningPreference
2223
import com.prof18.feedflow.core.utils.TestingTag
2324
import com.prof18.feedflow.shared.ui.feed.CategoriesSelector
@@ -37,9 +38,7 @@ fun EditFeedContent(
3738
errorMessage: String,
3839
canEditUrl: Boolean,
3940
categoriesState: CategoriesState,
40-
linkOpeningPreference: LinkOpeningPreference,
41-
isHidden: Boolean,
42-
isPinned: Boolean,
41+
feedSourceSettings: FeedSourceSettings,
4342
onFeedUrlUpdated: (String) -> Unit,
4443
onFeedNameUpdated: (String) -> Unit,
4544
onLinkOpeningPreferenceSelected: (LinkOpeningPreference) -> Unit,
@@ -94,7 +93,7 @@ fun EditFeedContent(
9493
modifier = Modifier
9594
.padding(top = Spacing.regular)
9695
.fillMaxWidth(),
97-
currentPreference = linkOpeningPreference,
96+
currentPreference = feedSourceSettings.linkOpeningPreference,
9897
onPreferenceSelected = onLinkOpeningPreferenceSelected,
9998
)
10099
}
@@ -108,12 +107,12 @@ fun EditFeedContent(
108107
Text(
109108
text = LocalFeedFlowStrings.current.hideFeedFromTimelineDescription,
110109
modifier = Modifier.padding(top = Spacing.xsmall)
111-
.weight(1f)
110+
.weight(1f),
112111
)
113112
Switch(
114-
checked = isHidden,
113+
checked = feedSourceSettings.isHiddenFromTimeline,
115114
onCheckedChange = onHiddenToggled,
116-
modifier = Modifier.padding(start = Spacing.regular)
115+
modifier = Modifier.padding(start = Spacing.regular),
117116
)
118117
}
119118
}
@@ -127,12 +126,12 @@ fun EditFeedContent(
127126
Text(
128127
text = LocalFeedFlowStrings.current.pinFeedSourceDescription,
129128
modifier = Modifier.padding(top = Spacing.xsmall)
130-
.weight(1f)
129+
.weight(1f),
131130
)
132131
Switch(
133-
checked = isPinned,
132+
checked = feedSourceSettings.isPinned,
134133
onCheckedChange = onPinnedToggled,
135-
modifier = Modifier.padding(start = Spacing.regular)
134+
modifier = Modifier.padding(start = Spacing.regular),
136135
)
137136
}
138137
}

0 commit comments

Comments
 (0)