- iOS: Add BackgroundSyncService, SyncScheduler, SyncWorker, BookmarkViewModel, FeedViewModel - iOS: Add BackgroundSyncService, SyncScheduler, SyncWorker services - Linux: Add settings-store.vala, State.vala signals, view widgets (FeedList, FeedDetail, AddFeed, Search, Settings, Bookmark) - Linux: Add bookmark-store.vala, bookmark vala model, search-service.vala - Android: Add NotificationService, NotificationManager, NotificationPreferencesStore - Android: Add BookmarkDao, BookmarkRepository, SettingsStore - Add unit tests for iOS, Android, Linux - Add integration tests - Add performance benchmarks - Update tasks and documentation Co-Authored-By: Paperclip <noreply@paperclip.ing>
92 lines
2.5 KiB
Swift
92 lines
2.5 KiB
Swift
//
|
|
// BookmarkViewModel.swift
|
|
// RSSuper
|
|
//
|
|
// ViewModel for bookmark state management
|
|
//
|
|
|
|
import Foundation
|
|
import Combine
|
|
|
|
/// State enum for bookmark data
|
|
enum BookmarkState {
|
|
case idle
|
|
case loading
|
|
case success([Bookmark])
|
|
case error(String)
|
|
}
|
|
|
|
/// ViewModel for managing bookmark state
|
|
class BookmarkViewModel: ObservableObject {
|
|
@Published var bookmarkState: BookmarkState = .idle
|
|
@Published var bookmarkCount: Int = 0
|
|
@Published var bookmarks: [Bookmark] = []
|
|
|
|
private let feedService: FeedServiceProtocol
|
|
private var cancellables = Set<AnyCancellable>()
|
|
|
|
init(feedService: FeedServiceProtocol = FeedService()) {
|
|
self.feedService = feedService
|
|
}
|
|
|
|
deinit {
|
|
cancellables.forEach { $0.cancel() }
|
|
}
|
|
|
|
/// Load all bookmarks
|
|
func loadBookmarks() {
|
|
bookmarkState = .loading
|
|
|
|
Task { [weak self] in
|
|
guard let self = self else { return }
|
|
|
|
let starredItems = self.feedService.getStarredFeedItems()
|
|
|
|
// Convert FeedItem to Bookmark
|
|
let bookmarks = starredItems.compactMap { item in
|
|
// Try to get the Bookmark from database, or create one from FeedItem
|
|
return Bookmark(
|
|
id: item.id,
|
|
feedItemId: item.id,
|
|
title: item.title,
|
|
link: item.link,
|
|
description: item.description,
|
|
content: item.content,
|
|
createdAt: item.published
|
|
)
|
|
}
|
|
|
|
DispatchQueue.main.async {
|
|
self.bookmarks = bookmarks
|
|
self.bookmarkState = .success(bookmarks)
|
|
self.bookmarkCount = bookmarks.count
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Load bookmark count
|
|
func loadBookmarkCount() {
|
|
let starredItems = feedService.getStarredItems()
|
|
bookmarkCount = starredItems.count
|
|
}
|
|
|
|
/// Add a bookmark (star an item)
|
|
func addBookmark(itemId: String) {
|
|
feedService.markItemAsStarred(itemId: itemId)
|
|
loadBookmarks()
|
|
}
|
|
|
|
/// Remove a bookmark (unstar an item)
|
|
func removeBookmark(itemId: String) {
|
|
feedService.unstarItem(itemId: itemId)
|
|
loadBookmarks()
|
|
}
|
|
|
|
/// Load bookmarks by tag (category)
|
|
func loadBookmarks(byTag tag: String) {
|
|
// Filter bookmarks by category - this requires adding category support to FeedItem
|
|
// For now, load all bookmarks
|
|
loadBookmarks()
|
|
}
|
|
}
|