From d1b34fe9649d6636f8df466abfd99e274efdfa83 Mon Sep 17 00:00:00 2001 From: kingbri Date: Tue, 26 Jul 2022 22:27:13 -0400 Subject: [PATCH] Settings: Add AboutView and style buttons Add a ListRowButtonView which runs a function and include a label. Use this to style magnet choice buttons. Signed-off-by: kingbri --- Ferrite.xcodeproj/project.pbxproj | 12 ++++ Ferrite/Extensions/UIApplication.swift | 27 +++++++ Ferrite/Views/AboutView.swift | 41 +++++++++++ Ferrite/Views/CommonViews/ListRowViews.swift | 75 ++++++++++++++++++++ Ferrite/Views/MagnetChoiceView.swift | 16 ++--- Ferrite/Views/SettingsView.swift | 6 ++ 6 files changed, 169 insertions(+), 8 deletions(-) create mode 100644 Ferrite/Extensions/UIApplication.swift create mode 100644 Ferrite/Views/AboutView.swift create mode 100644 Ferrite/Views/CommonViews/ListRowViews.swift diff --git a/Ferrite.xcodeproj/project.pbxproj b/Ferrite.xcodeproj/project.pbxproj index 35f8d09..601c669 100644 --- a/Ferrite.xcodeproj/project.pbxproj +++ b/Ferrite.xcodeproj/project.pbxproj @@ -11,6 +11,9 @@ 0C0D50E2288DF7700035ECC8 /* TorrentSource+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C0D50E0288DF7700035ECC8 /* TorrentSource+CoreDataProperties.swift */; }; 0C0D50E5288DFE7F0035ECC8 /* SourceModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C0D50E4288DFE7F0035ECC8 /* SourceModels.swift */; }; 0C0D50E7288DFF850035ECC8 /* SourceListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C0D50E6288DFF850035ECC8 /* SourceListView.swift */; }; + 0C32FB532890D19D002BD219 /* AboutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C32FB522890D19D002BD219 /* AboutView.swift */; }; + 0C32FB552890D1BF002BD219 /* UIApplication.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C32FB542890D1BF002BD219 /* UIApplication.swift */; }; + 0C32FB572890D1F2002BD219 /* ListRowViews.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C32FB562890D1F2002BD219 /* ListRowViews.swift */; }; 0C57D4CC289032ED008534E8 /* SearchResultRDView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C57D4CB289032ED008534E8 /* SearchResultRDView.swift */; }; 0C64A4B4288903680079976D /* Base32 in Frameworks */ = {isa = PBXBuildFile; productRef = 0C64A4B3288903680079976D /* Base32 */; }; 0C64A4B7288903880079976D /* KeychainSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 0C64A4B6288903880079976D /* KeychainSwift */; }; @@ -53,6 +56,9 @@ 0C0D50E0288DF7700035ECC8 /* TorrentSource+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TorrentSource+CoreDataProperties.swift"; sourceTree = ""; }; 0C0D50E4288DFE7F0035ECC8 /* SourceModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceModels.swift; sourceTree = ""; }; 0C0D50E6288DFF850035ECC8 /* SourceListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceListView.swift; sourceTree = ""; }; + 0C32FB522890D19D002BD219 /* AboutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutView.swift; sourceTree = ""; }; + 0C32FB542890D1BF002BD219 /* UIApplication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIApplication.swift; sourceTree = ""; }; + 0C32FB562890D1F2002BD219 /* ListRowViews.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListRowViews.swift; sourceTree = ""; }; 0C57D4CB289032ED008534E8 /* SearchResultRDView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResultRDView.swift; sourceTree = ""; }; 0CA05456288EE58200850554 /* SettingsSourceUrlView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsSourceUrlView.swift; sourceTree = ""; }; 0CA05458288EE9E600850554 /* SourceManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceManager.swift; sourceTree = ""; }; @@ -152,6 +158,7 @@ children = ( 0CA148C1288903F000DE2211 /* NavView.swift */, 0CFEFCFC288A006200B3F490 /* GroupBoxStyle.swift */, + 0C32FB562890D1F2002BD219 /* ListRowViews.swift */, ); path = CommonViews; sourceTree = ""; @@ -170,6 +177,7 @@ 0CA148C9288903F000DE2211 /* Collection.swift */, 0CA148CA288903F000DE2211 /* Data.swift */, 0CA148CB288903F000DE2211 /* Task.swift */, + 0C32FB542890D1BF002BD219 /* UIApplication.swift */, ); path = Extensions; sourceTree = ""; @@ -190,6 +198,7 @@ 0CBC76FC288D914F0054BE44 /* BatchChoiceView.swift */, 0CA148BD288903F000DE2211 /* MagnetChoiceView.swift */, 0C0D50E6288DFF850035ECC8 /* SourceListView.swift */, + 0C32FB522890D19D002BD219 /* AboutView.swift */, ); path = Views; sourceTree = ""; @@ -332,11 +341,13 @@ files = ( 0CE37ABB288E4AE900428C2D /* TorrentSourceUrl+CoreDataProperties.swift in Sources */, 0C0D50E5288DFE7F0035ECC8 /* SourceModels.swift in Sources */, + 0C32FB532890D19D002BD219 /* AboutView.swift in Sources */, 0CA148DB288903F000DE2211 /* NavView.swift in Sources */, 0CBC7705288DE7F40054BE44 /* PersistenceController.swift in Sources */, 0CA0545B288EEA4E00850554 /* SourceListEditorView.swift in Sources */, 0CA148E9288903F000DE2211 /* MainView.swift in Sources */, 0CBC76FD288D914F0054BE44 /* BatchChoiceView.swift in Sources */, + 0C32FB552890D1BF002BD219 /* UIApplication.swift in Sources */, 0C0D50E7288DFF850035ECC8 /* SourceListView.swift in Sources */, 0CA148EC288903F000DE2211 /* ContentView.swift in Sources */, 0CA148E1288903F000DE2211 /* Collection.swift in Sources */, @@ -359,6 +370,7 @@ 0CA148E5288903F000DE2211 /* DebridManager.swift in Sources */, 0CBC7702288DE4400054BE44 /* FerriteDB.xcdatamodeld in Sources */, 0CA148D9288903F000DE2211 /* CardView.swift in Sources */, + 0C32FB572890D1F2002BD219 /* ListRowViews.swift in Sources */, 0CA148EB288903F000DE2211 /* SearchResultsView.swift in Sources */, 0CA148D7288903F000DE2211 /* LoginWebView.swift in Sources */, 0C0D50E2288DF7700035ECC8 /* TorrentSource+CoreDataProperties.swift in Sources */, diff --git a/Ferrite/Extensions/UIApplication.swift b/Ferrite/Extensions/UIApplication.swift new file mode 100644 index 0000000..c4554ec --- /dev/null +++ b/Ferrite/Extensions/UIApplication.swift @@ -0,0 +1,27 @@ +// +// UIApplication.swift +// Ferrite +// +// Created by Brian Dashore on 7/26/22. +// + +import SwiftUI + +// Extensions to get the version/build number for AboutView +extension UIApplication { + var appVersion: String { + Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String + } + + var appBuild: String { + Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as! String + } + + var buildType: String { + #if DEBUG + return "Debug" + #else + return "Release" + #endif + } +} diff --git a/Ferrite/Views/AboutView.swift b/Ferrite/Views/AboutView.swift new file mode 100644 index 0000000..4654400 --- /dev/null +++ b/Ferrite/Views/AboutView.swift @@ -0,0 +1,41 @@ +// +// AboutView.swift +// Ferrite +// +// Created by Brian Dashore on 7/26/22. +// + +import SwiftUI + +struct AboutView: View { + @Environment(\.dismiss) var dismiss + + var body: some View { + VStack { + /* + Image("AppImage") + .resizable() + .frame(width: 100, height: 100) + .cornerRadius(25) + */ + + Text("Ferrite is a free and open source application developed by kingbri under the GNU-GPLv3 license.") + .padding() + + List { + ListRowTextView(leftText: "Version", rightText: UIApplication.shared.appVersion) + ListRowTextView(leftText: "Build number", rightText: UIApplication.shared.appBuild) + ListRowTextView(leftText: "Build type", rightText: UIApplication.shared.buildType) + ListRowLinkView(text: "GitHub repository", link: "https://github.com/bdashore3/Ferrite") + } + .listStyle(.insetGrouped) + } + .navigationTitle("About") + } +} + +struct AboutView_Previews: PreviewProvider { + static var previews: some View { + AboutView() + } +} diff --git a/Ferrite/Views/CommonViews/ListRowViews.swift b/Ferrite/Views/CommonViews/ListRowViews.swift new file mode 100644 index 0000000..770c4be --- /dev/null +++ b/Ferrite/Views/CommonViews/ListRowViews.swift @@ -0,0 +1,75 @@ +// +// ListRowViews.swift +// Ferrite +// +// Created by Brian Dashore on 7/26/22. +// + +import SwiftUI + +// These views were imported from Asobi +// View alias for a list row with an external link +struct ListRowLinkView: View { + let text: String + let link: String + + var body: some View { + HStack { + Link(text, destination: URL(string: link)!) + .foregroundColor(.primary) + + Spacer() + + Image(systemName: "arrow.up.forward.app.fill") + .foregroundColor(.gray) + } + } +} + +struct ListRowButtonView: View { + let text: String + let systemImage: String? + let action: () -> Void + + init(_ text: String, systemImage: String? = nil, action: @escaping () -> Void) { + self.text = text + self.systemImage = systemImage + self.action = action + } + + var body: some View { + HStack { + Button(text) { + action() + } + + Spacer() + + if let imageName = systemImage { + Image(systemName: imageName) + .foregroundColor(.gray) + } + } + } +} + +struct ListRowTextView: View { + let leftText: String + var rightText: String? + var rightSymbol: String? + + var body: some View { + HStack { + Text(leftText) + + Spacer() + + if let rightText = rightText { + Text(rightText) + } else { + Image(systemName: rightSymbol!) + .foregroundColor(.gray) + } + } + } +} diff --git a/Ferrite/Views/MagnetChoiceView.swift b/Ferrite/Views/MagnetChoiceView.swift index 15aabcb..56f07f1 100644 --- a/Ferrite/Views/MagnetChoiceView.swift +++ b/Ferrite/Views/MagnetChoiceView.swift @@ -24,7 +24,7 @@ struct MagnetChoiceView: View { Form { if realDebridEnabled, debridManager.matchSearchResult(result: scrapingModel.selectedSearchResult) != .none { Section("Real Debrid options") { - Button("Play on Outplayer") { + ListRowButtonView("Play on Outplayer", systemImage: "arrow.up.forward.app.fill") { guard let downloadUrl = URL(string: "outplayer://\(debridManager.realDebridDownloadUrl)") else { return } @@ -32,7 +32,7 @@ struct MagnetChoiceView: View { UIApplication.shared.open(downloadUrl) } - Button("Play on VLC") { + ListRowButtonView("Play on VLC", systemImage: "arrow.up.forward.app.fill") { guard let downloadUrl = URL(string: "vlc://\(debridManager.realDebridDownloadUrl)") else { return } @@ -40,7 +40,7 @@ struct MagnetChoiceView: View { UIApplication.shared.open(downloadUrl) } - Button("Play on Infuse") { + ListRowButtonView("Play on Infuse", systemImage: "arrow.up.forward.app.fill") { guard let downloadUrl = URL(string: "infuse://x-callback-url/play?url=\(debridManager.realDebridDownloadUrl)") else { return } @@ -48,11 +48,11 @@ struct MagnetChoiceView: View { UIApplication.shared.open(downloadUrl) } - Button("Copy download URL") { + ListRowButtonView("Copy download URL", systemImage: "doc.on.doc.fill") { UIPasteboard.general.string = debridManager.realDebridDownloadUrl } - Button("Share download URL") { + ListRowButtonView("Share download URL", systemImage: "square.and.arrow.up.fill") { guard let url = URL(string: debridManager.realDebridDownloadUrl) else { return } @@ -64,18 +64,18 @@ struct MagnetChoiceView: View { } Section("Magnet options") { - Button("Copy magnet") { + ListRowButtonView("Copy magnet", systemImage: "doc.on.doc.fill") { UIPasteboard.general.string = scrapingModel.selectedSearchResult?.magnetLink } - Button("Share magnet") { + ListRowButtonView("Share magnet", systemImage: "square.and.arrow.up.fill") { if let result = scrapingModel.selectedSearchResult, let url = URL(string: result.magnetLink) { activityItem = ActivityItem(items: url) showActivityView.toggle() } } - Button("Open in WebTor") { + ListRowButtonView("Open in WebTor", systemImage: "arrow.up.forward.app.fill") { if let result = scrapingModel.selectedSearchResult, let url = URL(string: "https://webtor.io/#/show?magnet=\(result.magnetLink)") { diff --git a/Ferrite/Views/SettingsView.swift b/Ferrite/Views/SettingsView.swift index 631e75a..19adb2a 100644 --- a/Ferrite/Views/SettingsView.swift +++ b/Ferrite/Views/SettingsView.swift @@ -42,6 +42,12 @@ struct SettingsView: View { Section("Source management") { NavigationLink("Source lists", destination: SettingsSourceListView()) } + + Section { + ListRowLinkView(text: "Report issues", link: "https://github.com/bdashore3/Ferrite/issues") + + NavigationLink("About", destination: AboutView()) + } } .sheet(isPresented: $debridManager.showWebView) { LoginWebView(url: URL(string: debridManager.realDebridAuthUrl)!)