Skip to content
This repository has been archived by the owner on May 18, 2023. It is now read-only.

Commit

Permalink
Update iOS example project
Browse files Browse the repository at this point in the history
  • Loading branch information
shipinev committed Aug 21, 2019
1 parent 033f97d commit 677b164
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 255 deletions.
2 changes: 1 addition & 1 deletion Example/Podfile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :ios, '8.3'
platform :ios, '10.0'
use_frameworks!

target 'ReadabilityKit_Example' do
Expand Down
8 changes: 4 additions & 4 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- Ji (5.0.0)
- ReadabilityKit (0.7.1):
- ReadabilityKit (0.7.3):
- Ji (= 5.0.0)

DEPENDENCIES:
Expand All @@ -16,8 +16,8 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
Ji: d795fed288fe78658b404c88946d753b17d8d7f4
ReadabilityKit: 94cdec0266cf09b434829554b01eadaf3ce2862a
ReadabilityKit: 8c2885beb8e5550cf0d365689897568228de41c9

PODFILE CHECKSUM: 51d8e36b0be7e9863f061fdd6dd82cb519146085
PODFILE CHECKSUM: d0121ae236a65011c2bcaf54e2b5ab5e3179de56

COCOAPODS: 1.7.1
COCOAPODS: 1.7.4
6 changes: 6 additions & 0 deletions Example/ReadabilityKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 607FACD91AFB9204008FA782 /* Main.storyboard */; };
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; };
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; };
66CD899A230ACC9500E3FE42 /* UIWebViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66CD8999230ACC9500E3FE42 /* UIWebViewExtension.swift */; };
B1FC4F450974B977518C0F48 /* Pods_ReadabilityKit_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1724B33ED9EA2C29FE44D48F /* Pods_ReadabilityKit_Example.framework */; };
/* End PBXBuildFile section */

Expand All @@ -32,6 +33,7 @@
607FACDA1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
607FACDC1AFB9204008FA782 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
607FACDF1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
66CD8999230ACC9500E3FE42 /* UIWebViewExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIWebViewExtension.swift; sourceTree = "<group>"; };
ACC2EDE82A7E59DF7ADB44A4 /* Pods-ReadabilityKit_Example-ReadabilityKit_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReadabilityKit_Example-ReadabilityKit_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ReadabilityKit_Example-ReadabilityKit_Tests/Pods-ReadabilityKit_Example-ReadabilityKit_Tests.debug.xcconfig"; sourceTree = "<group>"; };
AFD795EC3253A91F72C4FF19 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -97,6 +99,7 @@
607FACDC1AFB9204008FA782 /* Images.xcassets */,
607FACDE1AFB9204008FA782 /* LaunchScreen.xib */,
607FACD31AFB9204008FA782 /* Supporting Files */,
66CD8999230ACC9500E3FE42 /* UIWebViewExtension.swift */,
);
name = "Example for ReadabilityKit";
path = ReadabilityKit;
Expand Down Expand Up @@ -239,6 +242,7 @@
607FACD81AFB9204008FA782 /* MainController.swift in Sources */,
5707F3A61D1A97D300FAD21C /* DetailsController.swift in Sources */,
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
66CD899A230ACC9500E3FE42 /* UIWebViewExtension.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -360,6 +364,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = ReadabilityKit/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
Expand All @@ -375,6 +380,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = ReadabilityKit/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
Expand Down
336 changes: 151 additions & 185 deletions Example/ReadabilityKit/Base.lproj/Main.storyboard
100644 → 100755

Large diffs are not rendered by default.

72 changes: 46 additions & 26 deletions Example/ReadabilityKit/DetailsController.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,64 @@ import UIKit

class DetailsController: UIViewController {

@IBAction func onDone() {
self.dismiss(animated: true, completion: .none)
}

@IBOutlet weak var titleView: UITextView?
@IBOutlet weak var imageView: UIImageView?
@IBOutlet weak var keywordsView: UITextView?
@IBOutlet weak var descriptionView: UITextView?
@IBOutlet weak var videoURLView: UITextView?

@IBOutlet weak var imageView: UIImageView?
@IBOutlet weak var videoURLTextView: UITextView?
@IBOutlet weak var contentTextView: UITextView?

var image: UIImage?
var titleText: String?
var desc: String?
var keywords: [String]?
var videoURL: String?

@IBAction func onDone() {
self.navigationController?.popViewController(animated: true)
}

override func viewDidLoad() {
super.viewDidLoad()

titleView?.text = titleText
imageView?.image = image
keywordsView?.text = keywords?.joined(separator: ", ")
descriptionView?.text = desc

if let videoURLVal = videoURL {
videoURLView?.text = videoURLVal
videoURLView?.isHidden = false

let videoURLRecongnizer = UITapGestureRecognizer(target: self, action: #selector(DetailsController.openVideo))
videoURLView?.addGestureRecognizer(videoURLRecongnizer)
} else {
videoURLView?.isHidden = true
}
imageView?.image = image

if let videoURL = self.videoURL {
videoURLTextView?.text = videoURL
videoURLTextView?.isHidden = false

let videoURLRecongnizer = UITapGestureRecognizer(target: self, action: #selector(openVideo))
videoURLTextView?.addGestureRecognizer(videoURLRecongnizer)
} else {
videoURLTextView?.isHidden = true
}

let boldFont = UIFont.systemFont(ofSize: 17, weight: .bold)
let regularFont = UIFont.systemFont(ofSize: 17)
let stringFormat = "%@\n"

let contentAttributedString = NSMutableAttributedString()
contentAttributedString.append(
NSAttributedString(
string: String(format: stringFormat, titleText ?? ""),
attributes: [NSAttributedString.Key.font: boldFont]
)
)
contentAttributedString.append(
NSAttributedString(
string: String(format: stringFormat, keywords?.joined(separator: ", ") ?? ""),
attributes: [NSAttributedString.Key.font: regularFont]
)
)
contentAttributedString.append(
NSAttributedString(
string: String(format: stringFormat, desc ?? ""),
attributes: [NSAttributedString.Key.font: regularFont]
)
)
contentTextView?.attributedText = contentAttributedString
}

@objc func openVideo() {
if let url = URL(string: self.videoURLView!.text) {
UIApplication.shared.openURL(url)
if let url = URL(string: videoURLTextView?.text ?? "") {
UIApplication.shared.open(url, options: [:], completionHandler: .none)
}
}
}
14 changes: 9 additions & 5 deletions Example/ReadabilityKit/Info.plist
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand All @@ -34,11 +39,10 @@
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
</dict>
</plist>
55 changes: 21 additions & 34 deletions Example/ReadabilityKit/MainController.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ class MainController: UIViewController, UIWebViewDelegate, UITextFieldDelegate {

@IBOutlet weak var addressField: UITextField?
@IBOutlet weak var webView: UIWebView?
@IBOutlet weak var activityView: UIView?

var url: URL?
var parser: Readability?
var image: UIImage?
var parsedData: ReadabilityData?

override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -66,34 +69,19 @@ class MainController: UIViewController, UIWebViewDelegate, UITextFieldDelegate {
}

@IBAction func onParse() {

UIView.animate(withDuration: 0.1, animations: {
self.activityView?.alpha = 1.0
}, completion: { _ in
self.parseUrl()
})
parseHTMLContent()
}

func moveToDetails() {
UIView.animate(withDuration: 0.1, animations: {
self.activityView?.alpha = 0.0
}, completion: { _ in
self.performSegue(withIdentifier: "details_segue", sender: .none)
})
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

if segue.identifier == "details_segue" {

let detailsController = segue.destination as? DetailsController

detailsController?.titleText = parsedData?.title
detailsController?.desc = parsedData?.description
detailsController?.keywords = parsedData?.keywords
detailsController?.image = image
detailsController?.videoURL = parsedData?.topVideo
}
guard let viewController = self.storyboard?.instantiateViewController(withIdentifier: "Details View Controller") as? DetailsController else {
return
}
viewController.titleText = parsedData?.title
viewController.desc = parsedData?.description
viewController.keywords = parsedData?.keywords
viewController.image = image
viewController.videoURL = parsedData?.topVideo
self.navigationController?.pushViewController(viewController, animated: true)
}

func loadDefaultPage() {
Expand Down Expand Up @@ -125,13 +113,12 @@ class MainController: UIViewController, UIWebViewDelegate, UITextFieldDelegate {

// MARK: Parsing

func parseUrl() {
guard let url = url else {
func parseHTMLContent() {
guard let htmlContent = webView?.htmlContent else {
return
}

Readability.parse(url: url) { data in


Readability.parse(htmlString: htmlContent) { data in
self.parsedData = data

guard let imageUrlStr = data?.topImage else {
Expand All @@ -149,7 +136,7 @@ class MainController: UIViewController, UIWebViewDelegate, UITextFieldDelegate {
self.image = UIImage(data: imageData)

self.moveToDetails()
}

}
}
}
}
17 changes: 17 additions & 0 deletions Example/ReadabilityKit/UIWebViewExtension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// UIWebViewExtension.swift
// ReadabilityKit_Example
//
// Created by Dmitry Shipinev on 19/08/2019.
// Copyright © 2019 CocoaPods. All rights reserved.
//

import UIKit

extension UIWebView {

var htmlContent: String? {
return self.stringByEvaluatingJavaScript(from: "document.documentElement.outerHTML")
}

}

0 comments on commit 677b164

Please sign in to comment.