feat: Implement native List view with swipe actions and Safari integration
- Replace ScrollView + LazyVStack with native List for better performance - Add swipe actions for bookmark management (archive left, favorite/delete right) - Implement programmatic navigation with NavigationStack and navigationDestination - Create reusable SafariUtil for opening URLs in SFSafariViewController - Add clipboard URL detection and paste functionality in AddBookmarkView - Improve BookmarkCardView layout with better image handling and meta info - Add comprehensive date formatting with relative time display - Implement proper progress bar visualization for reading progress Navigation improvements: - Use Button + navigationDestination instead of NavigationLink - Add selectedBookmarkId state management for programmatic navigation - Support for share extension URL handling with notification system UI/UX enhancements: - Native iOS swipe gestures with haptic feedback - Consistent Safari integration across all views - Better accessibility with proper button targets - Improved visual hierarchy with refined spacing and typography - Added image fallback chain (image → thumbnail → icon → placeholder) Technical changes: - Remove ScrollView scroll tracking complexity - Simplify FAB button logic (always visible on unread tab) - Add String+Identifiable extension for navigation - Refactor duplicate Safari opening code into utility class
This commit is contained in:
parent
8882a402ef
commit
28cecf585c
@ -56,7 +56,7 @@ class BookmarksRepository: PBookmarksRepository {
|
|||||||
let response = try await api.createBookmark(createRequest: dto)
|
let response = try await api.createBookmark(createRequest: dto)
|
||||||
|
|
||||||
// Prüfe ob die Erstellung erfolgreich war
|
// Prüfe ob die Erstellung erfolgreich war
|
||||||
guard response.status == 0 else {
|
guard response.status == 0 || response.status == 202 else {
|
||||||
throw CreateBookmarkError.serverError(response.message)
|
throw CreateBookmarkError.serverError(response.message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,46 +5,81 @@ struct AddBookmarkView: View {
|
|||||||
@Environment(\.dismiss) private var dismiss
|
@Environment(\.dismiss) private var dismiss
|
||||||
|
|
||||||
init(prefilledURL: String? = nil, prefilledTitle: String? = nil) {
|
init(prefilledURL: String? = nil, prefilledTitle: String? = nil) {
|
||||||
viewModel.title = prefilledTitle ?? ""
|
_viewModel = State(initialValue: AddBookmarkViewModel())
|
||||||
viewModel.url = prefilledURL ?? ""
|
if let url = prefilledURL {
|
||||||
|
viewModel.url = url
|
||||||
|
}
|
||||||
|
if let title = prefilledTitle {
|
||||||
|
viewModel.title = title
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
Form {
|
VStack(spacing: 0) {
|
||||||
Section(header: Text("Bookmark Details")) {
|
// Scrollable Form Content
|
||||||
VStack(alignment: .leading, spacing: 8) {
|
ScrollView {
|
||||||
Text("URL *")
|
VStack(spacing: 24) {
|
||||||
.font(.caption)
|
// Header
|
||||||
|
VStack(spacing: 8) {
|
||||||
|
Image(systemName: "bookmark.circle.fill")
|
||||||
|
.font(.system(size: 48))
|
||||||
|
.foregroundColor(.accentColor)
|
||||||
|
|
||||||
|
Text("Neues Bookmark")
|
||||||
|
.font(.title2)
|
||||||
|
.fontWeight(.semibold)
|
||||||
|
|
||||||
|
Text("Füge einen neuen Link zu deiner Sammlung hinzu")
|
||||||
|
.font(.subheadline)
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
}
|
||||||
|
.padding(.top, 20)
|
||||||
|
|
||||||
|
// Form Fields
|
||||||
|
VStack(spacing: 20) {
|
||||||
|
// URL Field
|
||||||
|
VStack(alignment: .leading, spacing: 8) {
|
||||||
|
HStack {
|
||||||
|
Label("URL", systemImage: "link")
|
||||||
|
.font(.headline)
|
||||||
|
.foregroundColor(.primary)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Text("Erforderlich")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.red)
|
||||||
|
}
|
||||||
|
|
||||||
TextField("https://example.com", text: $viewModel.url)
|
TextField("https://example.com", text: $viewModel.url)
|
||||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
.textFieldStyle(CustomTextFieldStyle())
|
||||||
.keyboardType(.URL)
|
.keyboardType(.URL)
|
||||||
.autocapitalization(.none)
|
.autocapitalization(.none)
|
||||||
.autocorrectionDisabled()
|
.autocorrectionDisabled()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Title Field
|
||||||
VStack(alignment: .leading, spacing: 8) {
|
VStack(alignment: .leading, spacing: 8) {
|
||||||
Text("Titel (optional)")
|
Label("Titel", systemImage: "note.text")
|
||||||
.font(.caption)
|
.font(.headline)
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.primary)
|
||||||
|
|
||||||
TextField("Bookmark Titel", text: $viewModel.title)
|
TextField("Optional: Eigener Titel", text: $viewModel.title)
|
||||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
.textFieldStyle(CustomTextFieldStyle())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Section(header: Text("Labels")) {
|
// Labels Field
|
||||||
VStack(alignment: .leading, spacing: 8) {
|
VStack(alignment: .leading, spacing: 8) {
|
||||||
Text("Labels (durch Komma getrennt)")
|
Label("Labels", systemImage: "tag")
|
||||||
.font(.caption)
|
.font(.headline)
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.primary)
|
||||||
|
|
||||||
TextField("work, important, later", text: $viewModel.labelsText)
|
TextField("z.B. arbeit, wichtig, später", text: $viewModel.labelsText)
|
||||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
.textFieldStyle(CustomTextFieldStyle())
|
||||||
}
|
|
||||||
|
|
||||||
|
// Labels Preview
|
||||||
if !viewModel.parsedLabels.isEmpty {
|
if !viewModel.parsedLabels.isEmpty {
|
||||||
LazyVGrid(columns: [
|
LazyVGrid(columns: [
|
||||||
GridItem(.adaptive(minimum: 80))
|
GridItem(.adaptive(minimum: 80))
|
||||||
@ -52,77 +87,111 @@ struct AddBookmarkView: View {
|
|||||||
ForEach(viewModel.parsedLabels, id: \.self) { label in
|
ForEach(viewModel.parsedLabels, id: \.self) { label in
|
||||||
Text(label)
|
Text(label)
|
||||||
.font(.caption)
|
.font(.caption)
|
||||||
.padding(.horizontal, 8)
|
.fontWeight(.medium)
|
||||||
.padding(.vertical, 4)
|
.padding(.horizontal, 12)
|
||||||
.background(Color.blue.opacity(0.1))
|
.padding(.vertical, 6)
|
||||||
.foregroundColor(.blue)
|
.background(Color.accentColor.opacity(0.1))
|
||||||
|
.foregroundColor(.accentColor)
|
||||||
.clipShape(Capsule())
|
.clipShape(Capsule())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.padding(.top, 8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Section {
|
// Clipboard Section
|
||||||
Button("Aus Zwischenablage einfügen") {
|
if viewModel.clipboardURL != nil {
|
||||||
viewModel.pasteFromClipboard()
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
}
|
Label("Zwischenablage", systemImage: "doc.on.clipboard")
|
||||||
.disabled(viewModel.clipboardURL == nil)
|
.font(.headline)
|
||||||
|
.foregroundColor(.primary)
|
||||||
|
|
||||||
if let clipboardURL = viewModel.clipboardURL {
|
HStack {
|
||||||
Text("Zwischenablage: \(clipboardURL)")
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
Text("URL gefunden:")
|
||||||
.font(.caption)
|
.font(.caption)
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
.lineLimit(1)
|
|
||||||
|
Text(viewModel.clipboardURL ?? "")
|
||||||
|
.font(.subheadline)
|
||||||
|
.lineLimit(2)
|
||||||
.truncationMode(.middle)
|
.truncationMode(.middle)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Button("Einfügen") {
|
||||||
|
viewModel.pasteFromClipboard()
|
||||||
|
}
|
||||||
|
.buttonStyle(SecondaryButtonStyle())
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
.background(Color(.systemGray6))
|
||||||
|
.clipShape(RoundedRectangle(cornerRadius: 12))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.navigationTitle("Bookmark hinzufügen")
|
}
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
.padding(.horizontal, 20)
|
||||||
.toolbar {
|
|
||||||
ToolbarItem(placement: .navigationBarLeading) {
|
Spacer(minLength: 100) // Platz für Button
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bottom Action Area
|
||||||
|
VStack(spacing: 16) {
|
||||||
|
Divider()
|
||||||
|
|
||||||
|
VStack(spacing: 12) {
|
||||||
|
// Save Button
|
||||||
|
Button(action: {
|
||||||
|
Task {
|
||||||
|
await viewModel.createBookmark()
|
||||||
|
if viewModel.hasCreated {
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
HStack {
|
||||||
|
if viewModel.isLoading {
|
||||||
|
ProgressView()
|
||||||
|
.scaleEffect(0.8)
|
||||||
|
.foregroundColor(.white)
|
||||||
|
} else {
|
||||||
|
Image(systemName: "bookmark.fill")
|
||||||
|
}
|
||||||
|
|
||||||
|
Text(viewModel.isLoading ? "Wird gespeichert..." : "Bookmark speichern")
|
||||||
|
.fontWeight(.semibold)
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
.frame(height: 50)
|
||||||
|
.background(viewModel.isValid && !viewModel.isLoading ? Color.accentColor : Color.gray)
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.clipShape(RoundedRectangle(cornerRadius: 12))
|
||||||
|
}
|
||||||
|
.disabled(!viewModel.isValid || viewModel.isLoading)
|
||||||
|
|
||||||
|
// Cancel Button
|
||||||
Button("Abbrechen") {
|
Button("Abbrechen") {
|
||||||
dismiss()
|
dismiss()
|
||||||
viewModel.clearForm()
|
viewModel.clearForm()
|
||||||
}
|
}
|
||||||
|
.foregroundColor(.secondary)
|
||||||
}
|
}
|
||||||
|
.padding(.horizontal, 20)
|
||||||
ToolbarItem(placement: .navigationBarTrailing) {
|
.padding(.bottom, 20)
|
||||||
Button("Speichern") {
|
|
||||||
Task {
|
|
||||||
await viewModel.createBookmark()
|
|
||||||
dismiss()
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
.disabled(!viewModel.isValid || viewModel.isLoading)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.overlay {
|
|
||||||
if viewModel.isLoading {
|
|
||||||
ZStack {
|
|
||||||
Color.black.opacity(0.3)
|
|
||||||
|
|
||||||
VStack(spacing: 16) {
|
|
||||||
ProgressView()
|
|
||||||
.scaleEffect(1.2)
|
|
||||||
|
|
||||||
Text("Bookmark wird erstellt...")
|
|
||||||
.font(.subheadline)
|
|
||||||
}
|
|
||||||
.padding(24)
|
|
||||||
.background(Color(.systemBackground))
|
.background(Color(.systemBackground))
|
||||||
.clipShape(RoundedRectangle(cornerRadius: 12))
|
|
||||||
.shadow(radius: 10)
|
|
||||||
}
|
}
|
||||||
.ignoresSafeArea()
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
}
|
.toolbar {
|
||||||
}
|
ToolbarItem(placement: .navigationBarTrailing) {
|
||||||
.alert("Erfolgreich", isPresented: $viewModel.showSuccessAlert) {
|
Button("Schließen") {
|
||||||
Button("OK") {
|
|
||||||
dismiss()
|
dismiss()
|
||||||
|
viewModel.clearForm()
|
||||||
|
}
|
||||||
|
.foregroundColor(.secondary)
|
||||||
}
|
}
|
||||||
} message: {
|
|
||||||
Text("Bookmark wurde erfolgreich hinzugefügt!")
|
|
||||||
}
|
}
|
||||||
.alert("Fehler", isPresented: $viewModel.showErrorAlert) {
|
.alert("Fehler", isPresented: $viewModel.showErrorAlert) {
|
||||||
Button("OK", role: .cancel) { }
|
Button("OK", role: .cancel) { }
|
||||||
@ -139,6 +208,36 @@ struct AddBookmarkView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Custom Styles
|
||||||
|
|
||||||
|
struct CustomTextFieldStyle: TextFieldStyle {
|
||||||
|
func _body(configuration: TextField<Self._Label>) -> some View {
|
||||||
|
configuration
|
||||||
|
.padding()
|
||||||
|
.background(Color(.systemGray6))
|
||||||
|
.clipShape(RoundedRectangle(cornerRadius: 12))
|
||||||
|
.overlay(
|
||||||
|
RoundedRectangle(cornerRadius: 12)
|
||||||
|
.stroke(Color(.systemGray4), lineWidth: 1)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SecondaryButtonStyle: ButtonStyle {
|
||||||
|
func makeBody(configuration: Configuration) -> some View {
|
||||||
|
configuration.label
|
||||||
|
.font(.subheadline)
|
||||||
|
.fontWeight(.medium)
|
||||||
|
.padding(.horizontal, 16)
|
||||||
|
.padding(.vertical, 8)
|
||||||
|
.background(Color.accentColor.opacity(0.1))
|
||||||
|
.foregroundColor(.accentColor)
|
||||||
|
.clipShape(Capsule())
|
||||||
|
.scaleEffect(configuration.isPressed ? 0.95 : 1.0)
|
||||||
|
.animation(.easeInOut(duration: 0.1), value: configuration.isPressed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
AddBookmarkView()
|
AddBookmarkView()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,7 @@ class AddBookmarkViewModel {
|
|||||||
var isLoading: Bool = false
|
var isLoading: Bool = false
|
||||||
var errorMessage: String?
|
var errorMessage: String?
|
||||||
var showErrorAlert: Bool = false
|
var showErrorAlert: Bool = false
|
||||||
var showSuccessAlert: Bool = false
|
var hasCreated: Bool = false
|
||||||
var clipboardURL: String?
|
var clipboardURL: String?
|
||||||
|
|
||||||
var isValid: Bool {
|
var isValid: Bool {
|
||||||
@ -33,6 +33,7 @@ class AddBookmarkViewModel {
|
|||||||
|
|
||||||
isLoading = true
|
isLoading = true
|
||||||
errorMessage = nil
|
errorMessage = nil
|
||||||
|
hasCreated = false
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let cleanURL = url.trimmingCharacters(in: .whitespacesAndNewlines)
|
let cleanURL = url.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
@ -51,6 +52,7 @@ class AddBookmarkViewModel {
|
|||||||
print("Server response: \(message)")
|
print("Server response: \(message)")
|
||||||
|
|
||||||
clearForm()
|
clearForm()
|
||||||
|
hasCreated = true
|
||||||
} catch let error as CreateBookmarkError {
|
} catch let error as CreateBookmarkError {
|
||||||
errorMessage = error.localizedDescription
|
errorMessage = error.localizedDescription
|
||||||
showErrorAlert = true
|
showErrorAlert = true
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import SafariServices
|
||||||
|
|
||||||
struct BookmarkDetailView: View {
|
struct BookmarkDetailView: View {
|
||||||
let bookmarkId: String
|
let bookmarkId: String
|
||||||
@ -76,10 +77,21 @@ struct BookmarkDetailView: View {
|
|||||||
|
|
||||||
HStack {
|
HStack {
|
||||||
Image(systemName: "textformat")
|
Image(systemName: "textformat")
|
||||||
Text("\(viewModel.bookmarkDetail.wordCount) Wörter • \(viewModel.bookmarkDetail.readingTime) min Lesezeit")
|
Text("\(viewModel.bookmarkDetail.wordCount ?? 0) Wörter • \(viewModel.bookmarkDetail.readingTime ?? 0) min Lesezeit")
|
||||||
.font(.subheadline)
|
.font(.subheadline)
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HStack {
|
||||||
|
Image(systemName: "safari")
|
||||||
|
Button(action: {
|
||||||
|
SafariUtil.openInSafari(url: viewModel.bookmarkDetail.url)
|
||||||
|
}) {
|
||||||
|
Text("Original Seite öffnen")
|
||||||
|
.font(.subheadline)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import SafariServices
|
||||||
|
|
||||||
struct BookmarkCardView: View {
|
struct BookmarkCardView: View {
|
||||||
let bookmark: Bookmark
|
let bookmark: Bookmark
|
||||||
@ -7,8 +8,6 @@ struct BookmarkCardView: View {
|
|||||||
let onDelete: (Bookmark) -> Void
|
let onDelete: (Bookmark) -> Void
|
||||||
let onToggleFavorite: (Bookmark) -> Void
|
let onToggleFavorite: (Bookmark) -> Void
|
||||||
|
|
||||||
@State private var showingActionSheet = false
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(alignment: .leading, spacing: 8) {
|
VStack(alignment: .leading, spacing: 8) {
|
||||||
// Vorschaubild - verwende image oder thumbnail
|
// Vorschaubild - verwende image oder thumbnail
|
||||||
@ -28,35 +27,6 @@ struct BookmarkCardView: View {
|
|||||||
.clipShape(RoundedRectangle(cornerRadius: 8))
|
.clipShape(RoundedRectangle(cornerRadius: 8))
|
||||||
|
|
||||||
VStack(alignment: .leading, spacing: 4) {
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
// Status-Icons und Action-Button
|
|
||||||
HStack {
|
|
||||||
HStack(spacing: 6) {
|
|
||||||
if bookmark.isMarked {
|
|
||||||
IconBadge(systemName: "heart.fill", color: .red)
|
|
||||||
}
|
|
||||||
if bookmark.isArchived {
|
|
||||||
IconBadge(systemName: "archivebox.fill", color: .gray)
|
|
||||||
}
|
|
||||||
if bookmark.hasArticle {
|
|
||||||
IconBadge(systemName: "doc.text.fill", color: .green)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer()
|
|
||||||
|
|
||||||
// Action Menu Button
|
|
||||||
Button(action: {
|
|
||||||
showingActionSheet = true
|
|
||||||
}) {
|
|
||||||
Image(systemName: "ellipsis")
|
|
||||||
.foregroundColor(.secondary)
|
|
||||||
.padding(8)
|
|
||||||
.background(Color.gray.opacity(0.1))
|
|
||||||
.clipShape(Circle())
|
|
||||||
}
|
|
||||||
.buttonStyle(PlainButtonStyle())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Titel
|
// Titel
|
||||||
Text(bookmark.title)
|
Text(bookmark.title)
|
||||||
.font(.headline)
|
.font(.headline)
|
||||||
@ -64,28 +34,9 @@ struct BookmarkCardView: View {
|
|||||||
.lineLimit(2)
|
.lineLimit(2)
|
||||||
.multilineTextAlignment(.leading)
|
.multilineTextAlignment(.leading)
|
||||||
|
|
||||||
// Beschreibung
|
|
||||||
if !bookmark.description.isEmpty {
|
|
||||||
Text(bookmark.description)
|
|
||||||
.font(.subheadline)
|
|
||||||
.foregroundColor(.secondary)
|
|
||||||
.lineLimit(3)
|
|
||||||
.multilineTextAlignment(.leading)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Meta-Info mit Datum
|
// Meta-Info mit Datum
|
||||||
VStack(alignment: .leading, spacing: 4) {
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
HStack {
|
HStack {
|
||||||
if !bookmark.siteName.isEmpty {
|
|
||||||
Label(bookmark.siteName, systemImage: "globe")
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer()
|
|
||||||
|
|
||||||
if let readingTime = bookmark.readingTime, readingTime > 0 {
|
|
||||||
Label("\(readingTime) min", systemImage: "clock")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Veröffentlichungsdatum
|
// Veröffentlichungsdatum
|
||||||
if let publishedDate = formattedPublishedDate {
|
if let publishedDate = formattedPublishedDate {
|
||||||
@ -93,6 +44,26 @@ struct BookmarkCardView: View {
|
|||||||
Label(publishedDate, systemImage: "calendar")
|
Label(publishedDate, systemImage: "calendar")
|
||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Spacer() // show spacer only if we have the published Date
|
||||||
|
}
|
||||||
|
|
||||||
|
if let readingTime = bookmark.readingTime, readingTime > 0 {
|
||||||
|
Label("\(readingTime) min", systemImage: "clock")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HStack {
|
||||||
|
if !bookmark.siteName.isEmpty {
|
||||||
|
Label(bookmark.siteName, systemImage: "globe")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HStack {
|
||||||
|
|
||||||
|
Label("Original Seite öffnen", systemImage: "safari")
|
||||||
|
.onTapGesture {
|
||||||
|
SafariUtil.openInSafari(url: bookmark.url)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.font(.caption)
|
.font(.caption)
|
||||||
@ -111,16 +82,42 @@ struct BookmarkCardView: View {
|
|||||||
.background(Color(.systemBackground))
|
.background(Color(.systemBackground))
|
||||||
.clipShape(RoundedRectangle(cornerRadius: 12))
|
.clipShape(RoundedRectangle(cornerRadius: 12))
|
||||||
.shadow(color: .black.opacity(0.1), radius: 2, x: 0, y: 1)
|
.shadow(color: .black.opacity(0.1), radius: 2, x: 0, y: 1)
|
||||||
.confirmationDialog("Bookmark Aktionen", isPresented: $showingActionSheet) {
|
// Swipe Actions hinzufügen
|
||||||
actionButtons
|
.swipeActions(edge: .trailing, allowsFullSwipe: true) {
|
||||||
|
// Löschen (ganz rechts)
|
||||||
|
Button("Löschen", role: .destructive) {
|
||||||
|
onDelete(bookmark)
|
||||||
|
}
|
||||||
|
.tint(.red)
|
||||||
|
|
||||||
|
// Favorit (rechts)
|
||||||
|
Button {
|
||||||
|
onToggleFavorite(bookmark)
|
||||||
|
} label: {
|
||||||
|
Label(bookmark.isMarked ? "Entfernen" : "Favorit",
|
||||||
|
systemImage: bookmark.isMarked ? "heart.slash" : "heart.fill")
|
||||||
|
}
|
||||||
|
.tint(bookmark.isMarked ? .gray : .pink)
|
||||||
|
}
|
||||||
|
.swipeActions(edge: .leading, allowsFullSwipe: true) {
|
||||||
|
// Archivieren (links)
|
||||||
|
Button {
|
||||||
|
onArchive(bookmark)
|
||||||
|
} label: {
|
||||||
|
if currentState == .archived {
|
||||||
|
Label("Wiederherstellen", systemImage: "tray.and.arrow.up")
|
||||||
|
} else {
|
||||||
|
Label("Archivieren", systemImage: "archivebox")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.tint(currentState == .archived ? .blue : .orange)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Computed Properties
|
// MARK: - Computed Properties
|
||||||
|
|
||||||
private var formattedPublishedDate: String? {
|
private var formattedPublishedDate: String? {
|
||||||
guard let published = bookmark.published,
|
guard let published = bookmark.published, !published.isEmpty else {
|
||||||
!published.isEmpty else {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,33 +181,6 @@ struct BookmarkCardView: View {
|
|||||||
return formatter.string(from: date)
|
return formatter.string(from: date)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var actionButtons: some View {
|
|
||||||
Group {
|
|
||||||
// Favorit Toggle
|
|
||||||
Button(bookmark.isMarked ? "Favorit entfernen" : "Als Favorit markieren") {
|
|
||||||
onToggleFavorite(bookmark)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Archivieren/Dearchivieren basierend auf aktuellem State
|
|
||||||
if currentState == .archived {
|
|
||||||
Button("Aus Archiv entfernen") {
|
|
||||||
onArchive(bookmark)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Button("Archivieren") {
|
|
||||||
onArchive(bookmark)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Permanent löschen (immer verfügbar)
|
|
||||||
Button("Permanent löschen", role: .destructive) {
|
|
||||||
onDelete(bookmark)
|
|
||||||
}
|
|
||||||
|
|
||||||
Button("Abbrechen", role: .cancel) { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private var imageURL: URL? {
|
private var imageURL: URL? {
|
||||||
// Bevorzuge image, dann thumbnail, dann icon
|
// Bevorzuge image, dann thumbnail, dann icon
|
||||||
if let imageUrl = bookmark.resources.image?.src {
|
if let imageUrl = bookmark.resources.image?.src {
|
||||||
|
|||||||
@ -3,8 +3,7 @@ import SwiftUI
|
|||||||
struct BookmarksView: View {
|
struct BookmarksView: View {
|
||||||
@State private var viewModel = BookmarksViewModel()
|
@State private var viewModel = BookmarksViewModel()
|
||||||
@State private var showingAddBookmark = false
|
@State private var showingAddBookmark = false
|
||||||
@State private var scrollOffset: CGFloat = 0
|
@State private var selectedBookmarkId: String?
|
||||||
@State private var isScrolling = false
|
|
||||||
let state: BookmarkState
|
let state: BookmarkState
|
||||||
|
|
||||||
@State private var showingAddBookmarkFromShare = false
|
@State private var showingAddBookmarkFromShare = false
|
||||||
@ -12,15 +11,16 @@ struct BookmarksView: View {
|
|||||||
@State private var shareTitle = ""
|
@State private var shareTitle = ""
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
NavigationStack {
|
||||||
ZStack {
|
ZStack {
|
||||||
if viewModel.isLoading && viewModel.bookmarks.isEmpty {
|
if viewModel.isLoading && viewModel.bookmarks.isEmpty {
|
||||||
ProgressView("Lade \(state.displayName)...")
|
ProgressView("Lade \(state.displayName)...")
|
||||||
} else {
|
} else {
|
||||||
ScrollView {
|
List {
|
||||||
LazyVStack(spacing: 12) {
|
|
||||||
ForEach(viewModel.bookmarks, id: \.id) { bookmark in
|
ForEach(viewModel.bookmarks, id: \.id) { bookmark in
|
||||||
NavigationLink(destination: BookmarkDetailView(bookmarkId: bookmark.id)) {
|
Button(action: {
|
||||||
|
selectedBookmarkId = bookmark.id
|
||||||
|
}) {
|
||||||
BookmarkCardView(
|
BookmarkCardView(
|
||||||
bookmark: bookmark,
|
bookmark: bookmark,
|
||||||
currentState: state,
|
currentState: state,
|
||||||
@ -40,13 +40,14 @@ struct BookmarksView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.padding(.bottom, 20)
|
|
||||||
}
|
}
|
||||||
.buttonStyle(PlainButtonStyle())
|
.buttonStyle(PlainButtonStyle())
|
||||||
|
.listRowInsets(EdgeInsets(top: 8, leading: 16, bottom: 8, trailing: 16))
|
||||||
|
.listRowSeparator(.hidden)
|
||||||
|
.listRowBackground(Color.clear)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding()
|
.listStyle(.plain)
|
||||||
}
|
|
||||||
.refreshable {
|
.refreshable {
|
||||||
await viewModel.refreshBookmarks()
|
await viewModel.refreshBookmarks()
|
||||||
}
|
}
|
||||||
@ -60,8 +61,39 @@ struct BookmarksView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FAB Button - nur bei "Ungelesen" anzeigen
|
||||||
|
if state == .unread {
|
||||||
|
VStack {
|
||||||
|
Spacer()
|
||||||
|
HStack {
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Button(action: {
|
||||||
|
showingAddBookmark = true
|
||||||
|
}) {
|
||||||
|
Image(systemName: "plus")
|
||||||
|
.font(.title2)
|
||||||
|
.fontWeight(.semibold)
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.frame(width: 56, height: 56)
|
||||||
|
.background(Color.accentColor)
|
||||||
|
.clipShape(Circle())
|
||||||
|
.shadow(color: .black.opacity(0.25), radius: 6, x: 0, y: 3)
|
||||||
|
}
|
||||||
|
.padding(.trailing, 20)
|
||||||
|
.padding(.bottom, 20)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.navigationTitle(state.displayName)
|
.navigationTitle(state.displayName)
|
||||||
|
.navigationDestination(item: Binding<String?>(
|
||||||
|
get: { selectedBookmarkId },
|
||||||
|
set: { selectedBookmarkId = $0 }
|
||||||
|
)) { bookmarkId in
|
||||||
|
BookmarkDetailView(bookmarkId: bookmarkId)
|
||||||
|
}
|
||||||
.sheet(isPresented: $showingAddBookmark) {
|
.sheet(isPresented: $showingAddBookmark) {
|
||||||
AddBookmarkView(prefilledURL: shareURL, prefilledTitle: shareTitle)
|
AddBookmarkView(prefilledURL: shareURL, prefilledTitle: shareTitle)
|
||||||
}
|
}
|
||||||
@ -79,7 +111,7 @@ struct BookmarksView: View {
|
|||||||
// Refresh bookmarks when sheet is dismissed
|
// Refresh bookmarks when sheet is dismissed
|
||||||
if oldValue && !newValue {
|
if oldValue && !newValue {
|
||||||
Task {
|
Task {
|
||||||
await viewModel.refreshBookmarks()
|
await viewModel.loadBookmarks(state: state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,32 +119,6 @@ struct BookmarksView: View {
|
|||||||
handleShareNotification(notification)
|
handleShareNotification(notification)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.overlay {
|
|
||||||
// Animated FAB Button
|
|
||||||
VStack {
|
|
||||||
Spacer()
|
|
||||||
HStack {
|
|
||||||
Spacer()
|
|
||||||
|
|
||||||
Button(action: {
|
|
||||||
showingAddBookmark = true
|
|
||||||
}) {
|
|
||||||
Image(systemName: "plus")
|
|
||||||
.font(.title2)
|
|
||||||
.fontWeight(.semibold)
|
|
||||||
.foregroundColor(.white)
|
|
||||||
.frame(width: 56, height: 56)
|
|
||||||
.background(Color.accentColor)
|
|
||||||
.clipShape(Circle())
|
|
||||||
.shadow(color: .black.opacity(0.25), radius: 6, x: 0, y: 3)
|
|
||||||
.scaleEffect(isScrolling ? 0.8 : 1.0)
|
|
||||||
.opacity(isScrolling ? 0.7 : 1.0)
|
|
||||||
}
|
|
||||||
.padding(.trailing, 20)
|
|
||||||
.padding(.bottom, 20)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleShareNotification(_ notification: Notification) {
|
private func handleShareNotification(_ notification: Notification) {
|
||||||
@ -130,10 +136,7 @@ struct BookmarksView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper für Scroll-Tracking
|
// String Identifiable Extension für navigationDestination
|
||||||
struct ScrollOffsetPreferenceKey: PreferenceKey {
|
extension String: Identifiable {
|
||||||
static var defaultValue: CGFloat = 0
|
public var id: String { self }
|
||||||
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
|
|
||||||
value = nextValue()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
25
readeck/Utils/SafariUtil.swift
Normal file
25
readeck/Utils/SafariUtil.swift
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import UIKit
|
||||||
|
import SafariServices
|
||||||
|
|
||||||
|
class SafariUtil {
|
||||||
|
static func openInSafari(url: String) {
|
||||||
|
guard let url = URL(string: url) else { return }
|
||||||
|
|
||||||
|
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
|
||||||
|
let window = windowScene.windows.first,
|
||||||
|
let rootViewController = window.rootViewController {
|
||||||
|
|
||||||
|
let safariViewController = SFSafariViewController(url: url)
|
||||||
|
safariViewController.preferredBarTintColor = UIColor.systemBackground
|
||||||
|
safariViewController.preferredControlTintColor = UIColor.tintColor
|
||||||
|
|
||||||
|
// Finde den präsentierenden View Controller
|
||||||
|
var presentingViewController = rootViewController
|
||||||
|
while let presented = presentingViewController.presentedViewController {
|
||||||
|
presentingViewController = presented
|
||||||
|
}
|
||||||
|
|
||||||
|
presentingViewController.present(safariViewController, animated: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user