mirror of
https://github.com/Matte23/circolapp.git
synced 2025-12-06 07:29:10 +00:00
Automatically resolve circular's direct URL on iOS
This commit is contained in:
@@ -36,6 +36,7 @@
|
|||||||
95CA31B2255C1EDE00AC095B /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95CA31B1255C1EDE00AC095B /* ContentView.swift */; };
|
95CA31B2255C1EDE00AC095B /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95CA31B1255C1EDE00AC095B /* ContentView.swift */; };
|
||||||
95CA31B7255C1EE000AC095B /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 95CA31B6255C1EE000AC095B /* Preview Assets.xcassets */; };
|
95CA31B7255C1EE000AC095B /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 95CA31B6255C1EE000AC095B /* Preview Assets.xcassets */; };
|
||||||
95CA31C0255C28C300AC095B /* CircularView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95CA31BF255C28C300AC095B /* CircularView.swift */; };
|
95CA31C0255C28C300AC095B /* CircularView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95CA31BF255C28C300AC095B /* CircularView.swift */; };
|
||||||
|
95CED73225DBFA3B00C0E661 /* ActivityIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95CED73125DBFA3B00C0E661 /* ActivityIndicator.swift */; };
|
||||||
95DB71AB258A1C1500A78033 /* CarteView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95DB71AA258A1C1500A78033 /* CarteView.swift */; };
|
95DB71AB258A1C1500A78033 /* CarteView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95DB71AA258A1C1500A78033 /* CarteView.swift */; };
|
||||||
95E58FBB2592195B00689C37 /* ShareSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E58FBA2592195B00689C37 /* ShareSheet.swift */; };
|
95E58FBB2592195B00689C37 /* ShareSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E58FBA2592195B00689C37 /* ShareSheet.swift */; };
|
||||||
95F6666E2590D712006DE74F /* URLUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F6666D2590D712006DE74F /* URLUtils.swift */; };
|
95F6666E2590D712006DE74F /* URLUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F6666D2590D712006DE74F /* URLUtils.swift */; };
|
||||||
@@ -90,6 +91,7 @@
|
|||||||
95CA31B6255C1EE000AC095B /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
|
95CA31B6255C1EE000AC095B /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
|
||||||
95CA31B8255C1EE000AC095B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
95CA31B8255C1EE000AC095B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||||
95CA31BF255C28C300AC095B /* CircularView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircularView.swift; sourceTree = "<group>"; };
|
95CA31BF255C28C300AC095B /* CircularView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircularView.swift; sourceTree = "<group>"; };
|
||||||
|
95CED73125DBFA3B00C0E661 /* ActivityIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityIndicator.swift; sourceTree = "<group>"; };
|
||||||
95DB71AA258A1C1500A78033 /* CarteView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CarteView.swift; sourceTree = "<group>"; };
|
95DB71AA258A1C1500A78033 /* CarteView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CarteView.swift; sourceTree = "<group>"; };
|
||||||
95E58FBA2592195B00689C37 /* ShareSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareSheet.swift; sourceTree = "<group>"; };
|
95E58FBA2592195B00689C37 /* ShareSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareSheet.swift; sourceTree = "<group>"; };
|
||||||
95F6666D2590D712006DE74F /* URLUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLUtils.swift; sourceTree = "<group>"; };
|
95F6666D2590D712006DE74F /* URLUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLUtils.swift; sourceTree = "<group>"; };
|
||||||
@@ -155,6 +157,7 @@
|
|||||||
950C1783258E582E00B2DBFE /* PadView.swift */,
|
950C1783258E582E00B2DBFE /* PadView.swift */,
|
||||||
950C1785258E58AD00B2DBFE /* SidebarView.swift */,
|
950C1785258E58AD00B2DBFE /* SidebarView.swift */,
|
||||||
950C1787258E5BD300B2DBFE /* PhoneView.swift */,
|
950C1787258E5BD300B2DBFE /* PhoneView.swift */,
|
||||||
|
95CED73125DBFA3B00C0E661 /* ActivityIndicator.swift */,
|
||||||
);
|
);
|
||||||
path = View;
|
path = View;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -247,7 +250,7 @@
|
|||||||
isa = PBXProject;
|
isa = PBXProject;
|
||||||
attributes = {
|
attributes = {
|
||||||
LastSwiftUpdateCheck = 1210;
|
LastSwiftUpdateCheck = 1210;
|
||||||
LastUpgradeCheck = 1210;
|
LastUpgradeCheck = 1240;
|
||||||
TargetAttributes = {
|
TargetAttributes = {
|
||||||
95CA31AB255C1EDD00AC095B = {
|
95CA31AB255C1EDD00AC095B = {
|
||||||
CreatedOnToolsVersion = 12.1;
|
CreatedOnToolsVersion = 12.1;
|
||||||
@@ -377,6 +380,7 @@
|
|||||||
95CA31C0255C28C300AC095B /* CircularView.swift in Sources */,
|
95CA31C0255C28C300AC095B /* CircularView.swift in Sources */,
|
||||||
954AF8FF2588A61B00666D0C /* RemindersViewModel.swift in Sources */,
|
954AF8FF2588A61B00666D0C /* RemindersViewModel.swift in Sources */,
|
||||||
952DEDDF2576F8DC001DF85D /* SceneDelegate.swift in Sources */,
|
952DEDDF2576F8DC001DF85D /* SceneDelegate.swift in Sources */,
|
||||||
|
95CED73225DBFA3B00C0E661 /* ActivityIndicator.swift in Sources */,
|
||||||
954AF8FA2588A5DD00666D0C /* RemindersList.swift in Sources */,
|
954AF8FA2588A5DD00666D0C /* RemindersList.swift in Sources */,
|
||||||
95CA31B2255C1EDE00AC095B /* ContentView.swift in Sources */,
|
95CA31B2255C1EDE00AC095B /* ContentView.swift in Sources */,
|
||||||
955B7A10257D10A70091B1F9 /* ViewControllerResolver.swift in Sources */,
|
955B7A10257D10A70091B1F9 /* ViewControllerResolver.swift in Sources */,
|
||||||
@@ -420,6 +424,7 @@
|
|||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||||
|
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
|
||||||
CLANG_ANALYZER_NONNULL = YES;
|
CLANG_ANALYZER_NONNULL = YES;
|
||||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
||||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
|
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
|
||||||
@@ -482,6 +487,7 @@
|
|||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||||
|
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
|
||||||
CLANG_ANALYZER_NONNULL = YES;
|
CLANG_ANALYZER_NONNULL = YES;
|
||||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
||||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
|
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "1230"
|
LastUpgradeVersion = "1240"
|
||||||
version = "1.3">
|
version = "1.3">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
|
|||||||
18
ios/circolapp/circolapp/View/ActivityIndicator.swift
Normal file
18
ios/circolapp/circolapp/View/ActivityIndicator.swift
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
// credits: https://stackoverflow.com/questions/56496638/activity-indicator-in-swiftui
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import UIKit
|
||||||
|
|
||||||
|
struct ActivityIndicator: UIViewRepresentable {
|
||||||
|
|
||||||
|
@Binding var isAnimating: Bool
|
||||||
|
let style: UIActivityIndicatorView.Style
|
||||||
|
|
||||||
|
func makeUIView(context: UIViewRepresentableContext<ActivityIndicator>) -> UIActivityIndicatorView {
|
||||||
|
return UIActivityIndicatorView(style: style)
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateUIView(_ uiView: UIActivityIndicatorView, context: UIViewRepresentableContext<ActivityIndicator>) {
|
||||||
|
isAnimating ? uiView.startAnimating() : uiView.stopAnimating()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,9 +22,26 @@ import Shared
|
|||||||
struct AttachmentView: View {
|
struct AttachmentView: View {
|
||||||
@State private var sharingPhone: Bool = false
|
@State private var sharingPhone: Bool = false
|
||||||
@State private var sharingPad: Bool = false
|
@State private var sharingPad: Bool = false
|
||||||
|
@State private var loadingRealUrl = false
|
||||||
|
|
||||||
var attachmentName: String
|
var index: Int
|
||||||
var attachmentUrl: String
|
var circular: Circular
|
||||||
|
|
||||||
|
let attachmentName: String
|
||||||
|
let attachmentUrl: String
|
||||||
|
var realAttachmentUrl: String = ""
|
||||||
|
|
||||||
|
init(index: Int, circular: Circular) {
|
||||||
|
self.index = index
|
||||||
|
self.circular = circular
|
||||||
|
|
||||||
|
attachmentName = circular.attachmentsNames[index] as! String
|
||||||
|
attachmentUrl = circular.attachmentsUrls[index] as! String
|
||||||
|
|
||||||
|
if circular.realAttachmentsUrls.count == circular.attachmentsUrls.count {
|
||||||
|
realAttachmentUrl = circular.realAttachmentsUrls[index] as! String
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Divider()
|
Divider()
|
||||||
@@ -34,8 +51,12 @@ struct AttachmentView: View {
|
|||||||
.multilineTextAlignment(.leading)
|
.multilineTextAlignment(.leading)
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
|
if loadingRealUrl {
|
||||||
|
ActivityIndicator(isAnimating: .constant(true), style: .medium)
|
||||||
|
.padding(8.0)
|
||||||
|
} else {
|
||||||
Button(action: {
|
Button(action: {
|
||||||
URLUtils.openUrl(url: attachmentUrl)
|
runWhenUrlIsAvailable(code: {realUrl in URLUtils.openUrl(url: realUrl)})
|
||||||
}) {
|
}) {
|
||||||
Image(systemName: "envelope.open.fill")
|
Image(systemName: "envelope.open.fill")
|
||||||
.resizable()
|
.resizable()
|
||||||
@@ -44,6 +65,7 @@ struct AttachmentView: View {
|
|||||||
.padding(8.0)
|
.padding(8.0)
|
||||||
}
|
}
|
||||||
.buttonStyle(BorderlessButtonStyle())
|
.buttonStyle(BorderlessButtonStyle())
|
||||||
|
}
|
||||||
|
|
||||||
Button(action: {
|
Button(action: {
|
||||||
if UIDevice.current.userInterfaceIdiom == .phone {
|
if UIDevice.current.userInterfaceIdiom == .phone {
|
||||||
@@ -68,10 +90,31 @@ struct AttachmentView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func runWhenUrlIsAvailable(code: @escaping (_ url: String) -> Void) {
|
||||||
|
if realAttachmentUrl == "" {
|
||||||
|
loadingRealUrl = true
|
||||||
|
|
||||||
|
iOSRepository.getCircularRepository().getRealUrlForAttachment(index: Int32(index), rawUrls: circular.attachmentsUrls as! [String], realUrls: circular.realAttachmentsUrls as! [String], id: circular.id, school: circular.school, completionHandler: {realUrls, _ in
|
||||||
|
|
||||||
|
if realUrls == nil {
|
||||||
|
code(attachmentUrl)
|
||||||
|
}
|
||||||
|
|
||||||
|
loadingRealUrl = false
|
||||||
|
code(realUrls![index])
|
||||||
|
} )
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
code(realAttachmentUrl)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AttachmentView_Previews: PreviewProvider {
|
struct AttachmentView_Previews: PreviewProvider {
|
||||||
|
static var previewCircular = Circular(id: 1, school: 0, name: "This is a circular", url: "http://example.com", realUrl: "http://example.com", date: "19/11/2020", favourite: false, reminder: false, read: false, attachmentsNames: ["This is an attachment"], attachmentsUrls: ["http://example.com"], realAttachmentsUrls: [])
|
||||||
|
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
AttachmentView(attachmentName: "This is an attachment", attachmentUrl: "http://example.com")
|
AttachmentView(index: 0, circular: previewCircular)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ struct CircularView: View {
|
|||||||
@State private var sharingPhone: Bool = false
|
@State private var sharingPhone: Bool = false
|
||||||
@State private var sharingPad: Bool = false
|
@State private var sharingPad: Bool = false
|
||||||
@State private var showDetail = false
|
@State private var showDetail = false
|
||||||
|
@State private var loadingRealUrl = false
|
||||||
|
|
||||||
var circular: Circular
|
var circular: Circular
|
||||||
|
|
||||||
@@ -52,12 +53,16 @@ struct CircularView: View {
|
|||||||
|
|
||||||
if showDetail {
|
if showDetail {
|
||||||
HStack {
|
HStack {
|
||||||
|
if loadingRealUrl {
|
||||||
|
ActivityIndicator(isAnimating: .constant(true), style: .medium)
|
||||||
|
.padding(.leading, 32.0)
|
||||||
|
} else {
|
||||||
Button(action: {
|
Button(action: {
|
||||||
if !circular.read {
|
if !circular.read {
|
||||||
iOSRepository.getCircularDao().markRead(id: circular.id, school: circular.school, read: true, completionHandler: {_,_ in })
|
iOSRepository.getCircularDao().markRead(id: circular.id, school: circular.school, read: true, completionHandler: {_,_ in })
|
||||||
}
|
}
|
||||||
|
|
||||||
URLUtils.openUrl(url: circular.url)
|
runWhenUrlIsAvailable(code: {realUrl in URLUtils.openUrl(url: realUrl)})
|
||||||
}) {
|
}) {
|
||||||
Image(systemName: "envelope.open.fill")
|
Image(systemName: "envelope.open.fill")
|
||||||
.resizable()
|
.resizable()
|
||||||
@@ -66,6 +71,7 @@ struct CircularView: View {
|
|||||||
.padding(.leading, 32.0)
|
.padding(.leading, 32.0)
|
||||||
}
|
}
|
||||||
.buttonStyle(BorderlessButtonStyle())
|
.buttonStyle(BorderlessButtonStyle())
|
||||||
|
}
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
@@ -130,15 +136,29 @@ struct CircularView: View {
|
|||||||
|
|
||||||
|
|
||||||
ForEach(0..<circular.attachmentsNames.count, id: \.self) { index in
|
ForEach(0..<circular.attachmentsNames.count, id: \.self) { index in
|
||||||
AttachmentView(attachmentName: circular.attachmentsNames[index] as! String, attachmentUrl: circular.attachmentsUrls[index] as! String)
|
AttachmentView(index: index, circular: circular)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func runWhenUrlIsAvailable(code: @escaping (_ url: String) -> Void) {
|
||||||
|
if circular.realUrl == nil {
|
||||||
|
loadingRealUrl = true
|
||||||
|
iOSRepository.getCircularRepository().getRealUrl(rawUrl: circular.url, id: circular.id, school: circular.school, completionHandler:
|
||||||
|
{realUrl, _ in
|
||||||
|
loadingRealUrl = false
|
||||||
|
code(realUrl!)
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
code(circular.realUrl!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct CircularView_Previews: PreviewProvider {
|
struct CircularView_Previews: PreviewProvider {
|
||||||
static var previewCircular = Circular(id: 1, school: 0, name: "This is a circular", url: "http://example.com", date: "19/11/2020", favourite: false, reminder: false, read: false, attachmentsNames: [], attachmentsUrls: [])
|
static var previewCircular = Circular(id: 1, school: 0, name: "This is a circular", url: "http://example.com", realUrl: "http://example.com", date: "19/11/2020", favourite: false, reminder: false, read: false, attachmentsNames: [], attachmentsUrls: [], realAttachmentsUrls: [])
|
||||||
|
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
CircularView(circular: previewCircular)
|
CircularView(circular: previewCircular)
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ struct NewReminderView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct NewReminderView_Previews: PreviewProvider {
|
struct NewReminderView_Previews: PreviewProvider {
|
||||||
static var previewCircular = Circular(id: 1, school: 0, name: "This is a circular", url: "http://example.com", date: "19/11/2020", favourite: false, reminder: false, read: false, attachmentsNames: [], attachmentsUrls: [])
|
static var previewCircular = Circular(id: 1, school: 0, name: "This is a circular", url: "http://example.com", realUrl: "http://example.com", date: "19/11/2020", favourite: false, reminder: false, read: false, attachmentsNames: [], attachmentsUrls: [], realAttachmentsUrls: [])
|
||||||
|
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
NewReminderView(circular: previewCircular)
|
NewReminderView(circular: previewCircular)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ Pod::Spec.new do |spec|
|
|||||||
spec.pod_target_xcconfig = {
|
spec.pod_target_xcconfig = {
|
||||||
'KOTLIN_TARGET[sdk=iphonesimulator*]' => 'ios_x64',
|
'KOTLIN_TARGET[sdk=iphonesimulator*]' => 'ios_x64',
|
||||||
'KOTLIN_TARGET[sdk=iphoneos*]' => 'ios_arm',
|
'KOTLIN_TARGET[sdk=iphoneos*]' => 'ios_arm',
|
||||||
'KOTLIN_TARGET[sdk=watchsimulator*]' => 'watchos_x86',
|
'KOTLIN_TARGET[sdk=watchsimulator*]' => 'watchos_x64',
|
||||||
'KOTLIN_TARGET[sdk=watchos*]' => 'watchos_arm',
|
'KOTLIN_TARGET[sdk=watchos*]' => 'watchos_arm',
|
||||||
'KOTLIN_TARGET[sdk=appletvsimulator*]' => 'tvos_x64',
|
'KOTLIN_TARGET[sdk=appletvsimulator*]' => 'tvos_x64',
|
||||||
'KOTLIN_TARGET[sdk=appletvos*]' => 'tvos_arm64',
|
'KOTLIN_TARGET[sdk=appletvos*]' => 'tvos_arm64',
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ actual class SpecificCurieServer actual constructor(private val curieServer: Cur
|
|||||||
}
|
}
|
||||||
|
|
||||||
actual fun parseFileUrl(string: String): String {
|
actual fun parseFileUrl(string: String): String {
|
||||||
TODO("Not yet implemented")
|
val document = HTMLParser(string).parseDocument()
|
||||||
|
return document.querySelector(".mtli_attachment")!!.attributes.objectForKey("href").toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user