Skip to content

Commit ee6b333

Browse files
committed
Add parameter to synchronize at launch
1 parent a43415a commit ee6b333

File tree

7 files changed

+79
-62
lines changed

7 files changed

+79
-62
lines changed

app/src/main/java/com/readrops/app/more/preferences/PreferencesScreen.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ class PreferencesScreen : AndroidScreen() {
155155

156156
PreferenceHeader(text = stringResource(id = R.string.timeline))
157157

158+
SwitchPreferenceWidget(
159+
preference = loadedState.syncAtLaunchPref.second,
160+
isChecked = loadedState.syncAtLaunchPref.first,
161+
title = stringResource(R.string.synchronize_at_launch)
162+
)
163+
158164
ListPreferenceWidget(
159165
preference = loadedState.mainFilterPref.second,
160166
selectedKey = loadedState.mainFilterPref.first,

app/src/main/java/com/readrops/app/more/preferences/PreferencesScreenModel.kt

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,34 @@ class PreferencesScreenModel(
1919

2020
init {
2121
screenModelScope.launch(dispatcher) {
22-
val flows = listOf(
23-
preferences.theme.flow,
24-
preferences.backgroundSynchronization.flow,
25-
preferences.scrollRead.flow,
26-
preferences.hideReadFeeds.flow,
27-
preferences.openLinksWith.flow,
28-
preferences.timelineItemSize.flow,
29-
preferences.mainFilter.flow
30-
)
31-
32-
combine(
33-
flows
34-
) { list ->
35-
PreferencesScreenState.Loaded(
36-
themePref = (list[0] as String) to preferences.theme,
37-
backgroundSyncPref = (list[1] as String) to preferences.backgroundSynchronization,
38-
scrollReadPref = (list[2] as Boolean) to preferences.scrollRead,
39-
hideReadFeeds = (list[3] as Boolean) to preferences.hideReadFeeds,
40-
openLinksWith = (list[4] as String) to preferences.openLinksWith,
41-
timelineItemSize = (list[5] as String) to preferences.timelineItemSize,
42-
mainFilterPref = (list[6] as String) to preferences.mainFilter
22+
with(preferences) {
23+
val flows = listOf(
24+
theme.flow,
25+
backgroundSynchronization.flow,
26+
scrollRead.flow,
27+
hideReadFeeds.flow,
28+
openLinksWith.flow,
29+
timelineItemSize.flow,
30+
mainFilter.flow,
31+
synchAtLaunch.flow
4332
)
44-
}.collect { theme ->
45-
mutableState.update { theme }
33+
34+
combine(
35+
flows
36+
) { list ->
37+
PreferencesScreenState.Loaded(
38+
themePref = (list[0] as String) to theme,
39+
backgroundSyncPref = (list[1] as String) to backgroundSynchronization,
40+
scrollReadPref = (list[2] as Boolean) to scrollRead,
41+
hideReadFeeds = (list[3] as Boolean) to hideReadFeeds,
42+
openLinksWith = (list[4] as String) to openLinksWith,
43+
timelineItemSize = (list[5] as String) to timelineItemSize,
44+
mainFilterPref = (list[6] as String) to mainFilter,
45+
syncAtLaunchPref = (list[7] as Boolean) to synchAtLaunch
46+
)
47+
}.collect { theme ->
48+
mutableState.update { theme }
49+
}
4650
}
4751
}
4852
}
@@ -61,6 +65,7 @@ sealed class PreferencesScreenState {
6165
val openLinksWith: PreferenceState<String>,
6266
val timelineItemSize: PreferenceState<String>,
6367
val mainFilterPref: PreferenceState<String>,
68+
val syncAtLaunchPref: PreferenceState<Boolean>
6469
) : PreferencesScreenState()
6570

6671
}

app/src/main/java/com/readrops/app/timelime/TimelineScreenModel.kt

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,33 @@ class TimelineScreenModel(
6767
init {
6868
screenModelScope.launch(dispatcher) {
6969
val mainFilter = MainFilter.valueOf(preferences.mainFilter.flow.first())
70-
_timelineState.update {
71-
it.copy(
72-
filters = updateFilters {
73-
it.filters.copy(
74-
mainFilter = mainFilter
75-
)
76-
}
77-
)
78-
}
70+
var syncAtLaunch = preferences.synchAtLaunch.flow.first()
7971

8072
combine(
8173
accountEvent,
82-
filters
83-
) { account, filters ->
84-
account to filters.copy(accountId = account.id)
85-
}.collectLatest { (account, filters) ->
86-
this@TimelineScreenModel.filters.update { filters }
87-
buildPager()
74+
filters,
75+
getTimelinePreferences()
76+
) { account, filters, timelinePreferences ->
77+
Triple(account, filters.copy(accountId = account.id), timelinePreferences)
78+
}.collectLatest { (account, filters, timelinePreferences) ->
79+
_timelineState.update {
80+
it.copy(
81+
preferences = timelinePreferences,
82+
filters = filters.copy(
83+
mainFilter = mainFilter,
84+
showReadItems = timelinePreferences.showReadItems,
85+
orderField = timelinePreferences.orderField,
86+
orderType = timelinePreferences.orderType
87+
)
88+
)
89+
}
90+
91+
if (syncAtLaunch) {
92+
refreshTimeline()
93+
syncAtLaunch = false
94+
} else {
95+
buildPager()
96+
}
8897

8998
preferences.hideReadFeeds.flow
9099
.flatMapLatest { hideReadFeeds ->
@@ -102,7 +111,6 @@ class TimelineScreenModel(
102111
)
103112
}
104113
}
105-
106114
}
107115
}
108116

@@ -115,24 +123,6 @@ class TimelineScreenModel(
115123
}
116124
}
117125
}
118-
119-
screenModelScope.launch(dispatcher) {
120-
getTimelinePreferences()
121-
.collect { preferences ->
122-
_timelineState.update {
123-
it.copy(
124-
preferences = preferences,
125-
filters = updateFilters {
126-
it.filters.copy(
127-
showReadItems = preferences.showReadItems,
128-
orderField = preferences.orderField,
129-
orderType = preferences.orderType
130-
)
131-
}
132-
)
133-
}
134-
}
135-
}
136126
}
137127

138128
private fun getTimelinePreferences(): Flow<TimelinePreferences> = with(preferences) {
@@ -146,6 +136,7 @@ class TimelineScreenModel(
146136
theme.flow,
147137
openLinksWith.flow,
148138
globalOpenInAsk.flow,
139+
synchAtLaunch.flow,
149140
transform = {
150141
TimelinePreferences(
151142
itemSize = when (it[0]) {
@@ -161,14 +152,15 @@ class TimelineScreenModel(
161152
theme = it[6] as String,
162153
openInExternalBrowser = it[7] as String == "external_navigator",
163154
openInAsk = it[8] as Boolean,
155+
syncAtLaunch = it[9] as Boolean
164156
)
165157
}
166158
)
167159
}
168160

169161
private fun buildPager(empty: Boolean = false) {
170162
val query = ItemsQueryBuilder.buildItemsQuery(
171-
queryFilters = filters.value,
163+
queryFilters = _timelineState.value.filters,
172164
separateState = currentAccount!!.config.useSeparateState
173165
)
174166

@@ -205,7 +197,7 @@ class TimelineScreenModel(
205197
buildPager(empty = true)
206198

207199
screenModelScope.launch(dispatcher) {
208-
val filterPair = with(filters.value) {
200+
val filterPair = with(_timelineState.value.filters) {
209201
when (subFilter) {
210202
SubFilter.FEED -> SyncWorker.FEED_ID_KEY to feedId
211203
SubFilter.FOLDER -> SyncWorker.FOLDER_ID_KEY to folderId
@@ -511,7 +503,8 @@ data class TimelinePreferences(
511503
val orderType: OrderType = OrderType.DESC,
512504
val theme: String = "light",
513505
val openInExternalBrowser: Boolean = false,
514-
val openInAsk: Boolean = true
506+
val openInAsk: Boolean = true,
507+
val syncAtLaunch: Boolean = false
515508
)
516509

517510
sealed interface DialogState {

app/src/main/java/com/readrops/app/timelime/TimelineTab.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,15 @@ object TimelineTab : Tab {
140140
}
141141

142142
// remove splash screen when opening the app
143-
LaunchedEffect(items.isLoading()) {
143+
LaunchedEffect(items.isLoading(), preferences.syncAtLaunch) {
144144
val activity = (context as MainActivity)
145-
if (!items.isLoading() && !activity.ready) {
145+
146+
if (preferences.syncAtLaunch) {
146147
activity.ready = true
148+
} else {
149+
if (!items.isLoading() && !activity.ready) {
150+
activity.ready = true
151+
}
147152
}
148153
}
149154

app/src/main/java/com/readrops/app/util/Preferences.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ class Preferences(
103103
key = stringPreferencesKey("main_filter"),
104104
default = "ALL" // uppercase important, used with Enum.valueOf()
105105
)
106+
107+
val synchAtLaunch = Preference(
108+
dataStore = dataStore,
109+
key = booleanPreferencesKey("sync_at_launch"),
110+
default = false
111+
)
106112
}
107113

108114

app/src/main/res/values-fr/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,5 @@
193193
<string name="external_view">Vue externe</string>
194194
<string name="do_not_ask_again_next_feeds">Ne pas me redemander pour les autres flux</string>
195195
<string name="default_category">Catégorie par défaut</string>
196+
<string name="synchronize_at_launch">Synchroniser au démarrage</string>
196197
</resources>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,5 @@
202202
<string name="external_view">External view</string>
203203
<string name="do_not_ask_again_next_feeds">Do not ask me again for next feeds</string>
204204
<string name="default_category">Default category</string>
205+
<string name="synchronize_at_launch">Synchronize at launch</string>
205206
</resources>

0 commit comments

Comments
 (0)