Skip to content

Swift UI refactor opds catalog selector #497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
527e9c1
add OPDSCatalogRow
FuzzzzyBoy Oct 23, 2024
1f4cba3
add OPDSCatalogView
FuzzzzyBoy Oct 23, 2024
bf1dcf5
add OPDSCatalogView
FuzzzzyBoy Oct 23, 2024
973dc61
fix naming
FuzzzzyBoy Oct 23, 2024
d496570
add view model
FuzzzzyBoy Oct 23, 2024
39e524d
preload catalogs
FuzzzzyBoy Oct 23, 2024
fb617ab
refactoring
FuzzzzyBoy Oct 23, 2024
98d378f
add OPDSCatalog
FuzzzzyBoy Oct 23, 2024
d14aa50
rename
FuzzzzyBoy Oct 23, 2024
d2b8b49
refactoring
FuzzzzyBoy Oct 23, 2024
dab723f
handle catalog tap
FuzzzzyBoy Oct 23, 2024
0757d5b
open catalog
FuzzzzyBoy Oct 23, 2024
5a800db
restore
FuzzzzyBoy Oct 23, 2024
5689e63
add plain style
FuzzzzyBoy Oct 23, 2024
a3ad471
rename
FuzzzzyBoy Oct 23, 2024
1208fac
fix warning
FuzzzzyBoy Oct 23, 2024
9baab18
add empty AddOPDSCatalogView
FuzzzzyBoy Oct 23, 2024
a6bda48
add swipe actions
FuzzzzyBoy Oct 23, 2024
3822e78
remove when delete tap
FuzzzzyBoy Oct 23, 2024
f2db90f
update user defaults
FuzzzzyBoy Oct 23, 2024
c23bb23
rename
FuzzzzyBoy Oct 23, 2024
d0c7bf8
add id to catalog
FuzzzzyBoy Oct 23, 2024
d66a378
show EditOPDSCatalogView
FuzzzzyBoy Oct 23, 2024
3fc2dcd
edit catalog
FuzzzzyBoy Oct 23, 2024
112c99d
remove title
FuzzzzyBoy Oct 23, 2024
4f0eaf8
show error alert
FuzzzzyBoy Oct 23, 2024
6445395
add new catalog
FuzzzzyBoy Oct 23, 2024
6ede359
customize symbols
FuzzzzyBoy Oct 23, 2024
02bfad9
set target ios 15
FuzzzzyBoy Oct 23, 2024
aae896e
SwiftFormat fixes
FuzzzzyBoy Oct 23, 2024
50a9344
restore shevron
FuzzzzyBoy Oct 23, 2024
df325bb
SwiftFormat
FuzzzzyBoy Oct 23, 2024
0e56c7b
bump ios version
FuzzzzyBoy Nov 1, 2024
fae1a88
remove OPDSCatalogSymbol
FuzzzzyBoy Nov 1, 2024
a301e5f
fix init
FuzzzzyBoy Nov 1, 2024
37cb9dc
fix show edit button
FuzzzzyBoy Nov 1, 2024
5ab1214
remove OPDSCatalogSelectorViewController
FuzzzzyBoy Nov 1, 2024
a05ee5e
remove edit catalog logic
FuzzzzyBoy Nov 1, 2024
e3a030c
restore
FuzzzzyBoy Nov 1, 2024
eede5c8
swiftformat fixes
FuzzzzyBoy Nov 1, 2024
ee313ba
Bump Test App to iOS 18
mickael-menu Nov 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TestApp/Integrations/Carthage/project+lcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
deploymentTarget: "18.0"
sources:
- path: Sources
excludes:
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/Carthage/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
deploymentTarget: "18.0"
sources:
- path: Sources
excludes:
Expand Down
4 changes: 2 additions & 2 deletions TestApp/Integrations/CocoaPods/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :ios, '14.0'
platform :ios, '18.0'

target 'TestApp' do
# Comment the next line if you don't want to use dynamic frameworks
Expand All @@ -23,7 +23,7 @@ end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0'
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '18.0'
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
Expand Down
4 changes: 2 additions & 2 deletions TestApp/Integrations/CocoaPods/Podfile+lcp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :ios, '14.0'
platform :ios, '18.0'

target 'TestApp' do
# Comment the next line if you don't want to use dynamic frameworks
Expand Down Expand Up @@ -26,7 +26,7 @@ end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0'
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '18.0'
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/CocoaPods/project+lcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
deploymentTarget: "18.0"
sources:
- path: Sources
excludes:
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/CocoaPods/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
deploymentTarget: "18.0"
sources:
- path: Sources
excludes:
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/Local/project+lcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
deploymentTarget: "18.0"
sources:
- path: Sources
excludes:
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/Local/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
deploymentTarget: "18.0"
sources:
- path: Sources
excludes:
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/SPM/project+lcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
deploymentTarget: "18.0"
sources:
- path: Sources
excludes:
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/SPM/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
deploymentTarget: "18.0"
sources:
- path: Sources
excludes:
Expand Down
4 changes: 1 addition & 3 deletions TestApp/Sources/Library/LibraryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ class LibraryViewController: UIViewController, Loggable {

@objc func addBookFromDevice() {
var types = DocumentTypes.main.supportedUTTypes
if let type = UTType(String(kUTTypeText)) {
types.append(type)
}
types.append(UTType.text)

let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: types)
documentPicker.delegate = self
Expand Down
172 changes: 0 additions & 172 deletions TestApp/Sources/OPDS/OPDSCatalogSelectorViewController.swift

This file was deleted.

93 changes: 93 additions & 0 deletions TestApp/Sources/OPDS/OPDSCatalogs/EditOPDSCatalogView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//
// Copyright 2024 Readium Foundation. All rights reserved.
// Use of this source code is governed by the BSD-style license
// available in the top-level LICENSE file of the project.
//

import SwiftUI

struct EditOPDSCatalogView: View {
@State var catalog: OPDSCatalog
var onSave: (OPDSCatalog) -> Void

@Environment(\.presentationMode) var presentationMode

@State private var showErrorAlert = false
@State private var errorTitle = ""
@State private var errorMessage = ""
@State private var urlString: String

init(
catalog: OPDSCatalog,
onSave: @escaping (OPDSCatalog) -> Void
) {
self.catalog = catalog
self.onSave = onSave
urlString = catalog.url.absoluteString
}

var body: some View {
NavigationView {
Form {
Section(header: Text("opds_add_title")) {
TextField("Title", text: $catalog.title)
TextField("URL", text: $urlString)
.keyboardType(.URL)
.autocapitalization(.none)
.disableAutocorrection(true)
}
}
.navigationBarItems(
leading: Button("Cancel") {
presentationMode.wrappedValue.dismiss()
},
trailing: Button("Save") {
validateAndSave()
}
)
.alert(isPresented: $showErrorAlert) {
Alert(
title: Text(errorTitle),
message: Text(errorMessage),
dismissButton: .default(Text("OK"))
)
}
}
}

private func validateAndSave() {
let trimmedTitle = catalog.title.trimmingCharacters(in: .whitespacesAndNewlines)

if trimmedTitle.isEmpty {
errorTitle = "Title Required"
errorMessage = "Please enter a title."
showErrorAlert = true
return
}

if
let url = URL(string: urlString),
url.scheme != nil,
url.host != nil
{
catalog.url = url
onSave(catalog)
presentationMode.wrappedValue.dismiss()
} else {
errorTitle = "Invalid URL"
errorMessage = "Please enter a valid URL."
showErrorAlert = true
}
}
}

#Preview {
EditOPDSCatalogView(
catalog: OPDSCatalog(
id: UUID().uuidString,
title: "OPDS 2.0 Test Catalog",
url: URL(string: "https://test.opds.io/2.0/home.json")!
),
onSave: { _ in }
)
}
Loading
Loading