Skip to content

Commit

Permalink
Fixed new Reddit img tags, Improved link recognition, Improved custom…
Browse files Browse the repository at this point in the history
… theme menus
  • Loading branch information
ccrama committed Feb 27, 2021
1 parent 733c679 commit 5494fd2
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 98 deletions.
2 changes: 1 addition & 1 deletion Podfile.lock
Expand Up @@ -119,7 +119,7 @@ CHECKOUT OPTIONS:
:commit: e76cd225ff60f12f8ec0052e39e5e307a32c0762
:git: https://github.com/ccrama/MKColorPicker
reddift:
:commit: 41300e433197e5955e661a27bda4fd6a58185dfa
:commit: 79d54d0d00a3b888f766d413ef4a191c4e4c99f7
:git: https://github.com/ccrama/reddift
RLBAlertsPickers:
:commit: a22003f93a803c2e14b193f636669c21358fb1d7
Expand Down
112 changes: 56 additions & 56 deletions Slide for Reddit.xcodeproj/project.pbxproj
Expand Up @@ -50,13 +50,13 @@
B49EFE382511A18F002D6AEE /* HotPostsWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = B49EFE372511A18F002D6AEE /* HotPostsWidget.swift */; };
B49EFE482511A1D1002D6AEE /* FavoriteSubredditsWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = B49EFE472511A1D1002D6AEE /* FavoriteSubredditsWidget.swift */; };
B49EFE522511A221002D6AEE /* UIImage+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B49EFE512511A221002D6AEE /* UIImage+Extensions.swift */; };
B4F333E1251273AF0032BB64 /* SDWebImage in Frameworks */ = {isa = PBXBuildFile; productRef = B4F333E0251273AF0032BB64 /* SDWebImage */; };
B4F333EB251274050032BB64 /* BadgeSwift in Frameworks */ = {isa = PBXBuildFile; productRef = B4F333EA251274050032BB64 /* BadgeSwift */; };
B4F333F52512742E0032BB64 /* BiometricAuthentication in Frameworks */ = {isa = PBXBuildFile; productRef = B4F333F42512742E0032BB64 /* BiometricAuthentication */; };
B4F3348B2512770F0032BB64 /* Embassy in Frameworks */ = {isa = PBXBuildFile; productRef = B4F3348A2512770F0032BB64 /* Embassy */; };
B4F3349F251277B80032BB64 /* Starscream in Frameworks */ = {isa = PBXBuildFile; productRef = B4F3349E251277B80032BB64 /* Starscream */; };
B4F3354C25127BAB0032BB64 /* Anchorage in Frameworks */ = {isa = PBXBuildFile; productRef = B4F3354B25127BAB0032BB64 /* Anchorage */; };
B4F3355625127BD20032BB64 /* Then in Frameworks */ = {isa = PBXBuildFile; productRef = B4F3355525127BD20032BB64 /* Then */; };
B4F333E1251273AF0032BB64 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; productRef = B4F333E0251273AF0032BB64 /* SwiftPackageProductDependency */; };
B4F333EB251274050032BB64 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; productRef = B4F333EA251274050032BB64 /* SwiftPackageProductDependency */; };
B4F333F52512742E0032BB64 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; productRef = B4F333F42512742E0032BB64 /* SwiftPackageProductDependency */; };
B4F3348B2512770F0032BB64 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; productRef = B4F3348A2512770F0032BB64 /* SwiftPackageProductDependency */; };
B4F3349F251277B80032BB64 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; productRef = B4F3349E251277B80032BB64 /* SwiftPackageProductDependency */; };
B4F3354C25127BAB0032BB64 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; productRef = B4F3354B25127BAB0032BB64 /* SwiftPackageProductDependency */; };
B4F3355625127BD20032BB64 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; productRef = B4F3355525127BD20032BB64 /* SwiftPackageProductDependency */; };
B776B17D5CA92860424F37C0 /* ModQueueContributionLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = B776BA7C2B7217C3875F3BEC /* ModQueueContributionLoader.swift */; };
B776B1DF80711B443ED76B61 /* SettingsPro.swift in Sources */ = {isa = PBXBuildFile; fileRef = B776B2AEE4A2438F5803329C /* SettingsPro.swift */; };
B776B1E23F4DEC18069F1579 /* MediaViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B776BC65995FE8D1EE75E2AB /* MediaViewController.swift */; };
Expand Down Expand Up @@ -202,7 +202,7 @@
BE2F3F5D1EF96877003C1B28 /* SettingsContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE2F3F5C1EF96877003C1B28 /* SettingsContent.swift */; };
BE3144FF25663674004A908C /* AsyncTextAttachment.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE3144FE25663674004A908C /* AsyncTextAttachment.swift */; };
BE314509256738FF004A908C /* TitleUITextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE314508256738FF004A908C /* TitleUITextView.swift */; };
BE31454625674E03004A908C /* Proton in Frameworks */ = {isa = PBXBuildFile; productRef = BE31454525674E03004A908C /* Proton */; };
BE31454625674E03004A908C /* BuildFile in Frameworks */ = {isa = PBXBuildFile; productRef = BE31454525674E03004A908C /* SwiftPackageProductDependency */; };
BE325C66257EF04600BD2468 /* RedditObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE325C65257EF04600BD2468 /* RedditObject.swift */; };
BE325C70257EF06A00BD2468 /* SubmissionObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE325C6F257EF06A00BD2468 /* SubmissionObject.swift */; };
BE325C7C257EF33900BD2468 /* CommentObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE325C7B257EF33900BD2468 /* CommentObject.swift */; };
Expand Down Expand Up @@ -972,18 +972,18 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
B4F333F52512742E0032BB64 /* BiometricAuthentication in Frameworks */,
B4F333F52512742E0032BB64 /* BuildFile in Frameworks */,
BEC2AB3A250D8D2C00AD5BEA /* WidgetKit.framework in Frameworks */,
B4F3355625127BD20032BB64 /* Then in Frameworks */,
B4F333E1251273AF0032BB64 /* SDWebImage in Frameworks */,
B4F333EB251274050032BB64 /* BadgeSwift in Frameworks */,
B4F3355625127BD20032BB64 /* BuildFile in Frameworks */,
B4F333E1251273AF0032BB64 /* BuildFile in Frameworks */,
B4F333EB251274050032BB64 /* BuildFile in Frameworks */,
BE51BE6520C7386A00DFFD8B /* StoreKit.framework in Frameworks */,
B4F3354C25127BAB0032BB64 /* Anchorage in Frameworks */,
B4F3348B2512770F0032BB64 /* Embassy in Frameworks */,
BE31454625674E03004A908C /* Proton in Frameworks */,
B4F3354C25127BAB0032BB64 /* BuildFile in Frameworks */,
B4F3348B2512770F0032BB64 /* BuildFile in Frameworks */,
BE31454625674E03004A908C /* BuildFile in Frameworks */,
BE2E9F0823492B4300FE07B4 /* CloudKit.framework in Frameworks */,
BE7BFB481F1997BA009CA2E1 /* MapKit.framework in Frameworks */,
B4F3349F251277B80032BB64 /* Starscream in Frameworks */,
B4F3349F251277B80032BB64 /* BuildFile in Frameworks */,
01BBE6AB1AC863FE2E897632 /* Pods_Slide_for_Reddit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -1841,14 +1841,14 @@
);
name = "Slide for Reddit";
packageProductDependencies = (
B4F333E0251273AF0032BB64 /* SDWebImage */,
B4F333EA251274050032BB64 /* BadgeSwift */,
B4F333F42512742E0032BB64 /* BiometricAuthentication */,
B4F3348A2512770F0032BB64 /* Embassy */,
B4F3349E251277B80032BB64 /* Starscream */,
B4F3354B25127BAB0032BB64 /* Anchorage */,
B4F3355525127BD20032BB64 /* Then */,
BE31454525674E03004A908C /* Proton */,
B4F333E0251273AF0032BB64 /* SwiftPackageProductDependency */,
B4F333EA251274050032BB64 /* SwiftPackageProductDependency */,
B4F333F42512742E0032BB64 /* SwiftPackageProductDependency */,
B4F3348A2512770F0032BB64 /* SwiftPackageProductDependency */,
B4F3349E251277B80032BB64 /* SwiftPackageProductDependency */,
B4F3354B25127BAB0032BB64 /* SwiftPackageProductDependency */,
B4F3355525127BD20032BB64 /* SwiftPackageProductDependency */,
BE31454525674E03004A908C /* SwiftPackageProductDependency */,
);
productName = "Slide for Reddit";
productReference = BE8FCA041E0C46090063B8EF /* Slide for Reddit.app */;
Expand Down Expand Up @@ -2012,14 +2012,14 @@
);
mainGroup = BE8FC9FB1E0C46090063B8EF;
packageReferences = (
B4F333DF251273AF0032BB64 /* XCRemoteSwiftPackageReference "SDWebImage" */,
B4F333E9251274050032BB64 /* XCRemoteSwiftPackageReference "swift-badge" */,
B4F333F32512742E0032BB64 /* XCRemoteSwiftPackageReference "BiometricAuthentication" */,
B4F334892512770F0032BB64 /* XCRemoteSwiftPackageReference "Embassy" */,
B4F3349D251277B80032BB64 /* XCRemoteSwiftPackageReference "Starscream" */,
B4F3354A25127BAB0032BB64 /* XCRemoteSwiftPackageReference "Anchorage" */,
B4F3355425127BD20032BB64 /* XCRemoteSwiftPackageReference "Then" */,
BE31454425674E03004A908C /* XCRemoteSwiftPackageReference "proton" */,
B4F333DF251273AF0032BB64 /* RemoteSwiftPackageReference */,
B4F333E9251274050032BB64 /* RemoteSwiftPackageReference */,
B4F333F32512742E0032BB64 /* RemoteSwiftPackageReference */,
B4F334892512770F0032BB64 /* RemoteSwiftPackageReference */,
B4F3349D251277B80032BB64 /* RemoteSwiftPackageReference */,
B4F3354A25127BAB0032BB64 /* RemoteSwiftPackageReference */,
B4F3355425127BD20032BB64 /* RemoteSwiftPackageReference */,
BE31454425674E03004A908C /* RemoteSwiftPackageReference */,
);
productRefGroup = BE8FCA051E0C46090063B8EF /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -3565,63 +3565,63 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
B4F333DF251273AF0032BB64 /* XCRemoteSwiftPackageReference "SDWebImage" */ = {
B4F333DF251273AF0032BB64 /* RemoteSwiftPackageReference */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/SDWebImage/SDWebImage";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 5.9.1;
};
};
B4F333E9251274050032BB64 /* XCRemoteSwiftPackageReference "swift-badge" */ = {
B4F333E9251274050032BB64 /* RemoteSwiftPackageReference */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/evgenyneu/swift-badge";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 8.0.2;
};
};
B4F333F32512742E0032BB64 /* XCRemoteSwiftPackageReference "BiometricAuthentication" */ = {
B4F333F32512742E0032BB64 /* RemoteSwiftPackageReference */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/rushisangani/BiometricAuthentication";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 3.1.2;
};
};
B4F334892512770F0032BB64 /* XCRemoteSwiftPackageReference "Embassy" */ = {
B4F334892512770F0032BB64 /* RemoteSwiftPackageReference */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/envoy/Embassy";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 4.1.1;
};
};
B4F3349D251277B80032BB64 /* XCRemoteSwiftPackageReference "Starscream" */ = {
B4F3349D251277B80032BB64 /* RemoteSwiftPackageReference */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/daltoniam/Starscream";
requirement = {
kind = exactVersion;
version = 3.1.1;
};
};
B4F3354A25127BAB0032BB64 /* XCRemoteSwiftPackageReference "Anchorage" */ = {
B4F3354A25127BAB0032BB64 /* RemoteSwiftPackageReference */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/Rightpoint/Anchorage";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 4.5.0;
};
};
B4F3355425127BD20032BB64 /* XCRemoteSwiftPackageReference "Then" */ = {
B4F3355425127BD20032BB64 /* RemoteSwiftPackageReference */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/devxoul/Then";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 2.7.0;
};
};
BE31454425674E03004A908C /* XCRemoteSwiftPackageReference "proton" */ = {
BE31454425674E03004A908C /* RemoteSwiftPackageReference */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/rajdeep/proton";
requirement = {
Expand All @@ -3632,44 +3632,44 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
B4F333E0251273AF0032BB64 /* SDWebImage */ = {
B4F333E0251273AF0032BB64 /* SwiftPackageProductDependency */ = {
isa = XCSwiftPackageProductDependency;
package = B4F333DF251273AF0032BB64 /* XCRemoteSwiftPackageReference "SDWebImage" */;
package = B4F333DF251273AF0032BB64 /* RemoteSwiftPackageReference */;
productName = SDWebImage;
};
B4F333EA251274050032BB64 /* BadgeSwift */ = {
B4F333EA251274050032BB64 /* SwiftPackageProductDependency */ = {
isa = XCSwiftPackageProductDependency;
package = B4F333E9251274050032BB64 /* XCRemoteSwiftPackageReference "swift-badge" */;
package = B4F333E9251274050032BB64 /* RemoteSwiftPackageReference */;
productName = BadgeSwift;
};
B4F333F42512742E0032BB64 /* BiometricAuthentication */ = {
B4F333F42512742E0032BB64 /* SwiftPackageProductDependency */ = {
isa = XCSwiftPackageProductDependency;
package = B4F333F32512742E0032BB64 /* XCRemoteSwiftPackageReference "BiometricAuthentication" */;
package = B4F333F32512742E0032BB64 /* RemoteSwiftPackageReference */;
productName = BiometricAuthentication;
};
B4F3348A2512770F0032BB64 /* Embassy */ = {
B4F3348A2512770F0032BB64 /* SwiftPackageProductDependency */ = {
isa = XCSwiftPackageProductDependency;
package = B4F334892512770F0032BB64 /* XCRemoteSwiftPackageReference "Embassy" */;
package = B4F334892512770F0032BB64 /* RemoteSwiftPackageReference */;
productName = Embassy;
};
B4F3349E251277B80032BB64 /* Starscream */ = {
B4F3349E251277B80032BB64 /* SwiftPackageProductDependency */ = {
isa = XCSwiftPackageProductDependency;
package = B4F3349D251277B80032BB64 /* XCRemoteSwiftPackageReference "Starscream" */;
package = B4F3349D251277B80032BB64 /* RemoteSwiftPackageReference */;
productName = Starscream;
};
B4F3354B25127BAB0032BB64 /* Anchorage */ = {
B4F3354B25127BAB0032BB64 /* SwiftPackageProductDependency */ = {
isa = XCSwiftPackageProductDependency;
package = B4F3354A25127BAB0032BB64 /* XCRemoteSwiftPackageReference "Anchorage" */;
package = B4F3354A25127BAB0032BB64 /* RemoteSwiftPackageReference */;
productName = Anchorage;
};
B4F3355525127BD20032BB64 /* Then */ = {
B4F3355525127BD20032BB64 /* SwiftPackageProductDependency */ = {
isa = XCSwiftPackageProductDependency;
package = B4F3355425127BD20032BB64 /* XCRemoteSwiftPackageReference "Then" */;
package = B4F3355425127BD20032BB64 /* RemoteSwiftPackageReference */;
productName = Then;
};
BE31454525674E03004A908C /* Proton */ = {
BE31454525674E03004A908C /* SwiftPackageProductDependency */ = {
isa = XCSwiftPackageProductDependency;
package = BE31454425674E03004A908C /* XCRemoteSwiftPackageReference "proton" */;
package = BE31454425674E03004A908C /* RemoteSwiftPackageReference */;
productName = Proton;
};
/* End XCSwiftPackageProductDependency section */
Expand Down
27 changes: 12 additions & 15 deletions Slide for Reddit/AppDelegate.swift
Expand Up @@ -775,25 +775,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true
} else if url.absoluteString.contains("colors") {
let themeName = url.absoluteString.removingPercentEncoding!.split("#")[1]
let alert = UIAlertController(title: "Save \"\(themeName.replacingOccurrences(of: "<H>", with: "#"))\"", message: "You can set it as your theme in Settings > Theme\n\n\n\n\n", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Save", style: .default, handler: { (_) in
let colorString = url.absoluteString.removingPercentEncoding!

let themeView = ThemeCellView().then {
$0.setTheme(string: url.absoluteString.removingPercentEncoding ?? url.absoluteString)
}
let cv = themeView.contentView

let alert = DragDownAlertMenu(title: themeName, subtitle: "", icon: nil, extraView: cv, themeColor: nil, full: false)

alert.addAction(title: "Save Theme", icon: UIImage(sfString: .squareAndArrowDownFill, overrideString: "save-1")) {
let colorString = url.absoluteString.removingPercentEncoding ?? url.absoluteString

let title = colorString.split("#")[1]
UserDefaults.standard.set(colorString, forKey: "Theme+" + title)
}))
alert.addCancelButton()
let themeView = ThemeCellView().then {
$0.setTheme(colors: url.absoluteString.removingPercentEncoding!)
}
let cv = themeView.contentView
alert.view.addSubview(cv)
cv.leftAnchor /==/ alert.view.leftAnchor + 8
cv.rightAnchor /==/ alert.view.rightAnchor - 8
cv.topAnchor /==/ alert.view.topAnchor + 90
cv.heightAnchor /==/ 60

alert.showWindowless()

alert.show(UIApplication.shared.keyWindow?.topViewController())
return true
} else if url.absoluteString.contains("reddit.com") || url.absoluteString.contains("google.com/amp") || url.absoluteString.contains("redd.it") {
VCPresenter.openRedditLink(url.absoluteString.replacingOccurrences(of: "slide://", with: ""), window?.rootViewController as? UINavigationController, window?.rootViewController)
Expand Down
14 changes: 9 additions & 5 deletions Slide for Reddit/DragDownAlertMenu.swift
Expand Up @@ -202,6 +202,8 @@ class DragDownAlertMenu: UIViewController, UITableViewDelegate, UITableViewDataS
var timer: Timer?
var isSearching = false
var taskSearch: URLSessionDataTask?

var extraViewHeight = CGFloat(30)

init(title: String, subtitle: String, icon: String?, extraView: UIView? = nil, themeColor: UIColor? = nil, full: Bool = false) {
self.descriptor = title
Expand Down Expand Up @@ -332,7 +334,7 @@ class DragDownAlertMenu: UIViewController, UITableViewDelegate, UITableViewDataS
}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return (subtitle.isEmpty ? (extraView == nil ? 55 : 90) : 80) + (hasInput ? 58 : 0)
return (subtitle.isEmpty ? (extraView == nil ? 55 : 55 + extraViewHeight + 16) : 80) + (hasInput ? 58 : 0)
}

func getText() -> String? {
Expand Down Expand Up @@ -388,7 +390,9 @@ class DragDownAlertMenu: UIViewController, UITableViewDelegate, UITableViewDataS
}
} else {
maxHeight = UIScreen.main.bounds.height * (2 / 3)
height = min(maxHeight, CGFloat((subtitle.isEmpty ? 55 : 80) + (hasInput ? 58 : 0) + (60 * actions.count) + 60 + (extraView != nil ? 40 : 0)))
let evHeight = CGFloat(16 + extraViewHeight) // XCode couldn't compile this inline :/
let actionsHeight = CGFloat(60 * actions.count)
height = min(maxHeight, CGFloat((subtitle.isEmpty ? 55 : 80) + (hasInput ? 58 : 0) + actionsHeight + 60 + (extraView != nil ? evHeight : 0)))
if isSearch {
height += 158
}
Expand Down Expand Up @@ -468,7 +472,7 @@ class DragDownAlertMenu: UIViewController, UITableViewDelegate, UITableViewDataS
let close = UIImageView(image: UIImage(sfString: SFSymbol.xmark, overrideString: "close")?.navIcon().getCopy(withColor: themeColor ?? UIColor.fontColor))
close.contentMode = .center
toReturn.addSubview(close)
close.centerYAnchor /==/ toReturn.centerYAnchor
close.topAnchor /==/ toReturn.topAnchor + 16
close.rightAnchor /==/ toReturn.rightAnchor - 16
close.heightAnchor /==/ 30
close.widthAnchor /==/ 30
Expand Down Expand Up @@ -516,13 +520,13 @@ class DragDownAlertMenu: UIViewController, UITableViewDelegate, UITableViewDataS
} else if extraView != nil {
toReturn.addSubviews(extraView!, label)
label.leftAnchor /==/ toReturn.leftAnchor + 16
label.rightAnchor /==/ close.leftAnchor - 8
label.rightAnchor /==/ toReturn.rightAnchor - 16
label.topAnchor /==/ toReturn.topAnchor + 8
label.heightAnchor /==/ 40

toReturn.isUserInteractionEnabled = true
extraView!.leftAnchor /==/ toReturn.leftAnchor + 16
extraView!.heightAnchor /==/ 30
extraView!.heightAnchor /==/ extraViewHeight ~ .required
extraView!.rightAnchor /==/ toReturn.rightAnchor - 16
extraView!.topAnchor /==/ label.bottomAnchor + 8
extraView!.bottomAnchor /==/ toReturn.bottomAnchor - 8
Expand Down

0 comments on commit 5494fd2

Please sign in to comment.