Skip to content

Commit

Permalink
Add button and prepare view model to implement API
Browse files Browse the repository at this point in the history
  • Loading branch information
danielebogo committed Jan 28, 2025
1 parent 5697d52 commit 71aa310
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
34 changes: 34 additions & 0 deletions podcasts/PodcastFeedViewModel.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,43 @@
import Foundation

class PodcastFeedViewModel {
enum LoadingState {
case idle
case loading
}

let uuid: String?

private(set) var loadingState: LoadingState = .idle

init(uuid: String?) {
self.uuid = uuid
}

func checkIfNewEpisodesAreAvailable() async -> Bool {
// Test implementation to simulate the API
await MainActor.run {
loadingState = .loading
}
_ = await shouldReloadPodcasts()

try? await Task.sleep(nanoseconds: 3_000_000_000)

await MainActor.run {
Toast.show(L10n.podcastFeedReloadNoEpisodesFound)
}
await MainActor.run {
loadingState = .idle
}
return false
}

private func shouldReloadPodcasts() async -> Int {
await MainActor.run {
Toast.show(L10n.podcastFeedReloadLoading)
}
return 202
}

private func pollUpdatePodcast() async { }
}
10 changes: 9 additions & 1 deletion podcasts/PodcastViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,15 @@ class PodcastViewController: FakeNavViewController, PodcastActionsDelegate, Sync
}

func reloadPodcastFeed() {

if podcastFeedViewModel?.loadingState == .loading {
return
}
Task { @MainActor [weak self] in
let podcastNeedsReload = await self?.podcastFeedViewModel?.checkIfNewEpisodesAreAvailable() ?? false
if podcastNeedsReload {
self?.loadPodcastInfo()
}
}
}

// MARK: - Long press actions
Expand Down

0 comments on commit 71aa310

Please sign in to comment.