Skip to content

Commit

Permalink
Improve refresh indicator when syncing.
Browse files Browse the repository at this point in the history
  • Loading branch information
prof18 committed Jul 22, 2024
1 parent 37f1285 commit 922e65d
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 57 deletions.
29 changes: 0 additions & 29 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,6 @@ tasks.register("clean", Delete::class) {
delete(layout.buildDirectory.get())
}

// todo: delete
//allprojects {
// apply {
// plugin(rootProject.libs.plugins.detekt.get().pluginId)
// }
//
// dependencies {
// detektPlugins(rootProject.libs.io.gitlab.arturbosch.detekt.formatting) {
// exclude(group = "org.slf4j", module = "slf4j-nop")
// }
// detektPlugins(rootProject.libs.detekt.compose.rules)
// }
//
// detekt {
// source.setFrom(
// files(
// "src",
// DEFAULT_SRC_DIR_JAVA,
// DEFAULT_TEST_SRC_DIR_JAVA,
// DEFAULT_SRC_DIR_KOTLIN,
// DEFAULT_TEST_SRC_DIR_KOTLIN,
// ),
// )
// config.setFrom(rootProject.files("config/detekt/detekt.yml"))
// parallel = true
// autoCorrect = true
// }
//}

subprojects {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,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 = 37
private const val StringsVersion = 38
2 changes: 1 addition & 1 deletion i18n/src/commonMain/resources/locale/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<string name="reader_mode_warning">ℹ The reader mode tries to get the content of the article. There might be some glitches or unwanted characters.</string>
<string name="settings_title_feed">Feed</string>
<string name="settings_accounts">Accounts</string>
<string name="accounts_description">Connect an account to sync feed subscriptions, categories, read and bookmarked articles between your devices.\n\nThe functionality is in Beta and more services will be supported in the future.</string>
<string name="accounts_description">Connect an account to sync feed subscriptions, categories, read and bookmarked articles between your devices.\n\nThe functionality is in Beta, issues may occur (for example, read articles might not be fully synced). More services will be supported in the future.</string>
<string name="settings_behaviour_title">Behaviour</string>
<string name="settings_help_title">Help</string>
<string name="dropbox_connect_button">Connect</string>
Expand Down
16 changes: 16 additions & 0 deletions iosApp/Source/Accounts/Dropbox/DropboxSyncScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ struct DropboxSyncScreen: View {
self.appState.emitGenericError()
}
}
.task {
do {
let stream = asyncSequence(for: viewModel.syncMessageQueue)
for try await message in stream where message.isError() {
self.appState.snackbarQueue.append(
SnackbarData(
title: feedFlowStrings.errorAccountSync,
subtitle: nil,
showBanner: true
)
)
}
} catch {
self.appState.emitGenericError()
}
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion iosApp/Source/App/FeedFlowApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ class AppDelegate: NSObject, UIApplicationDelegate {
return true
}

func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
func application(
_ application: UIApplication,
handleEventsForBackgroundURLSession identifier: String,
completionHandler: @escaping () -> Void
) {
DropboxClientsManager.handleEventsForBackgroundURLSession(
with: identifier,
creationInfos: [],
Expand Down
18 changes: 1 addition & 17 deletions iosApp/Source/Home/HomeScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,26 +177,10 @@ struct HomeScreen: View {
self.appState.emitGenericError()
}
}
.task {
do {
let stream = asyncSequence(for: homeViewModel.syncMessageQueue)
for try await message in stream where message.isError() {
self.appState.snackbarQueue.append(
SnackbarData(
title: feedFlowStrings.errorAccountSync,
subtitle: nil,
showBanner: true
)
)
}
} catch {
self.appState.emitGenericError()
}
}
.onChange(of: scenePhase) { newScenePhase in
switch newScenePhase {
case .background:
homeViewModel.enqueueBackup()
homeViewModel.enqueueBackup(lastVisibleIndex: Int32(indexHolder.getLastReadIndex()))
default:
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ internal actual fun getPlatformModule(appEnvironment: AppEnvironment): Module =
feedSyncRepository = get(),
dateFormatter = get(),
feedRetrieverRepository = get(),
feedSyncMessageQueue = get(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ private val coreModule = module {
feedManagerRepository = get(),
settingsRepository = get(),
feedSyncRepository = get(),
feedSyncMessageQueue = get(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ internal class FeedRetrieverRepository(
val currentFeedFilter: StateFlow<FeedFilter> = currentFeedFilterMutableState.asStateFlow()

private var currentPage: Int = 0
private var isFeedSyncDone = true

private val knownUrlSuffix = listOf(
"",
Expand Down Expand Up @@ -200,12 +201,15 @@ internal class FeedRetrieverRepository(
getFeeds()
}

isFeedSyncDone = false
parseFeeds(
feedSourceUrls = feedSourceUrls,
forceRefresh = forceRefresh,
)

feedSyncRepository.syncFeedItems()
isFeedSyncDone = true
updateRefreshCount()

getFeeds()
}
Expand Down Expand Up @@ -398,7 +402,7 @@ internal class FeedRetrieverRepository(
val refreshedFeedCount = oldUpdate.refreshedFeedCount + 1
val totalFeedCount = oldUpdate.totalFeedCount

if (feedToUpdate.isEmpty()) {
if (feedToUpdate.isEmpty() && isFeedSyncDone) {
FinishedFeedUpdateStatus
} else {
InProgressFeedUpdateStatus(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.prof18.feedflow.core.model.FeedItemId
import com.prof18.feedflow.core.model.NavDrawerState
import com.prof18.feedflow.shared.domain.feed.manager.FeedManagerRepository
import com.prof18.feedflow.shared.domain.feed.retriever.FeedRetrieverRepository
import com.prof18.feedflow.shared.domain.feedsync.FeedSyncMessageQueue
import com.prof18.feedflow.shared.domain.feedsync.FeedSyncRepository
import com.prof18.feedflow.shared.domain.model.FeedUpdateStatus
import com.prof18.feedflow.shared.domain.settings.SettingsRepository
Expand All @@ -35,7 +34,6 @@ class HomeViewModel internal constructor(
private val feedManagerRepository: FeedManagerRepository,
private val settingsRepository: SettingsRepository,
private val feedSyncRepository: FeedSyncRepository,
feedSyncMessageQueue: FeedSyncMessageQueue,
) : BaseViewModel() {

// Loading
Expand Down Expand Up @@ -66,9 +64,6 @@ class HomeViewModel internal constructor(
@NativeCoroutinesState
val currentFeedFilter = feedRetrieverRepository.currentFeedFilter

@NativeCoroutines
val syncMessageQueue = feedSyncMessageQueue.messageQueue

init {
scope.launch {
feedRetrieverRepository.updateFeedFilter(FeedFilter.Timeline)
Expand Down Expand Up @@ -248,8 +243,10 @@ class HomeViewModel internal constructor(
}
}

fun enqueueBackup() {
// Used on iOS
fun enqueueBackup(lastVisibleIndex: Int) {
scope.launch {
markAsReadOnScroll(lastVisibleIndex)
feedSyncRepository.enqueueBackup()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.prof18.feedflow.feedsync.dropbox.DropboxStringCredentials
import com.prof18.feedflow.feedsync.dropbox.getDxCredentialsAsString
import com.prof18.feedflow.shared.domain.DateFormatter
import com.prof18.feedflow.shared.domain.feed.retriever.FeedRetrieverRepository
import com.prof18.feedflow.shared.domain.feedsync.FeedSyncMessageQueue
import com.prof18.feedflow.shared.domain.feedsync.FeedSyncRepository
import com.rickclephas.kmp.nativecoroutines.NativeCoroutines
import com.rickclephas.kmp.nativecoroutines.NativeCoroutinesState
Expand All @@ -30,6 +31,7 @@ class DropboxSyncViewModel internal constructor(
private val feedSyncRepository: FeedSyncRepository,
private val dateFormatter: DateFormatter,
private val feedRetrieverRepository: FeedRetrieverRepository,
feedSyncMessageQueue: FeedSyncMessageQueue,
) : BaseViewModel() {

private val dropboxSyncUiMutableState = MutableStateFlow<DropboxConnectionUiState>(
Expand All @@ -44,6 +46,9 @@ class DropboxSyncViewModel internal constructor(
@NativeCoroutines
val dropboxSyncMessageState: SharedFlow<DropboxSynMessages> = dropboxSyncMessageMutableState.asSharedFlow()

@NativeCoroutines
val syncMessageQueue = feedSyncMessageQueue.messageQueue

init {
restoreDropboxAuth()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.prof18.feedflow.i18n.feedFlowStrings
import com.prof18.feedflow.shared.domain.HtmlParser
import com.prof18.feedflow.shared.domain.browser.BrowserSettingsRepository
import com.prof18.feedflow.shared.domain.feedsync.FeedSyncIosWorker
import com.prof18.feedflow.shared.domain.feedsync.FeedSyncMessageQueue
import com.prof18.feedflow.shared.domain.feedsync.FeedSyncRepository
import com.prof18.feedflow.shared.domain.feedsync.FeedSyncWorker
import com.prof18.feedflow.shared.domain.opml.OpmlFeedHandler
Expand Down Expand Up @@ -108,6 +109,7 @@ internal actual fun getPlatformModule(appEnvironment: AppEnvironment): Module =
feedSyncRepository = get(),
dateFormatter = get(),
feedRetrieverRepository = get(),
feedSyncMessageQueue = get(),
)
}
}
Expand Down

0 comments on commit 922e65d

Please sign in to comment.