Skip to content

Commit 7bdd5e7

Browse files
authored
Merge pull request #127 from analogcode/dev
Add watermarked image for share activity by @CamMcLeod
2 parents e1f69ee + 8ed5bff commit 7bdd5e7

7 files changed

+165
-4
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Give it a quick watch.
3333
* Download and cache images using ImageLoader class
3434

3535
## Important Notes
36+
- 8.20.19: Add watermarked image for share activity by [@CamMcLeod](https://github.com/CamMcLeod).
3637
- 5.18.19: master branch migrated to Xcode 10.2/Swift 5 by [@fethica](https://github.com/fethica).
3738
- 9.4.19: Add AirPlay support by [@geraldnolan](https://github.com/geraldnolan).
3839
- 2.10.19: Add CarPlay support by [@fethica](https://github.com/fethica) -- [Announcement](https://github.com/analogcode/Swift-Radio-Pro/issues/110). Branch here: [carplay branch](https://github.com/analogcode/Swift-Radio-Pro/tree/carplay).

SwiftRadio.xcodeproj/project.pbxproj

+15-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
2C5545BD1C1124DE00728469 /* SwiftRadioUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C5545BC1C1124DE00728469 /* SwiftRadioUITests.swift */; };
11+
53113F39230C720900462C0E /* ShareImageGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53113F38230C720900462C0E /* ShareImageGenerator.swift */; };
1112
5F22BA3C1F72AD5A00CB5911 /* SpringLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F22BA1E1F72AD3700CB5911 /* SpringLabel.swift */; };
1213
5F22BA3D1F72AD5A00CB5911 /* BlurView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F22BA1F1F72AD3900CB5911 /* BlurView.swift */; };
1314
5F22BA3E1F72AD5A00CB5911 /* DesignableTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F22BA201F72AD3B00CB5911 /* DesignableTabBarController.swift */; };
@@ -36,6 +37,8 @@
3637
5F22BA551F72AD5A00CB5911 /* AutoTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F22BA3A1F72AD5800CB5911 /* AutoTextView.swift */; };
3738
5F22BA561F72AD5A00CB5911 /* DesignableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F22BA3B1F72AD5900CB5911 /* DesignableView.swift */; };
3839
5FDEE0221F72FF980064333C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5FDEE0211F72FF980064333C /* LaunchScreen.storyboard */; };
40+
6258DCD822D93A3500166C65 /* LogoShareView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6258DCD722D93A3500166C65 /* LogoShareView.swift */; };
41+
6258DCDA22D93A5400166C65 /* LogoShareView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6258DCD922D93A5400166C65 /* LogoShareView.xib */; };
3942
81AD229B21646DEA002ADFDD /* FRadioPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81AD229821646DEA002ADFDD /* FRadioPlayer.swift */; };
4043
81AD229C21646DEA002ADFDD /* FRadioAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81AD229921646DEA002ADFDD /* FRadioAPI.swift */; };
4144
81AD229D21646DEA002ADFDD /* Reachability.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81AD229A21646DEA002ADFDD /* Reachability.swift */; };
@@ -74,6 +77,7 @@
7477
2C5545BA1C1124DE00728469 /* SwiftRadioUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftRadioUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
7578
2C5545BC1C1124DE00728469 /* SwiftRadioUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftRadioUITests.swift; sourceTree = "<group>"; };
7679
2C5545BE1C1124DE00728469 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
80+
53113F38230C720900462C0E /* ShareImageGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareImageGenerator.swift; sourceTree = "<group>"; };
7781
5F22BA1E1F72AD3700CB5911 /* SpringLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpringLabel.swift; sourceTree = "<group>"; };
7882
5F22BA1F1F72AD3900CB5911 /* BlurView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurView.swift; sourceTree = "<group>"; };
7983
5F22BA201F72AD3B00CB5911 /* DesignableTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DesignableTabBarController.swift; sourceTree = "<group>"; };
@@ -105,6 +109,8 @@
105109
5F22BA3A1F72AD5800CB5911 /* AutoTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoTextView.swift; sourceTree = "<group>"; };
106110
5F22BA3B1F72AD5900CB5911 /* DesignableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DesignableView.swift; sourceTree = "<group>"; };
107111
5FDEE0211F72FF980064333C /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
112+
6258DCD722D93A3500166C65 /* LogoShareView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogoShareView.swift; sourceTree = "<group>"; };
113+
6258DCD922D93A5400166C65 /* LogoShareView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LogoShareView.xib; sourceTree = "<group>"; };
108114
81AD229821646DEA002ADFDD /* FRadioPlayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FRadioPlayer.swift; sourceTree = "<group>"; };
109115
81AD229921646DEA002ADFDD /* FRadioAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FRadioAPI.swift; sourceTree = "<group>"; };
110116
81AD229A21646DEA002ADFDD /* Reachability.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Reachability.swift; sourceTree = "<group>"; };
@@ -294,6 +300,9 @@
294300
94D260951B45E3FA00DE671C /* AnimationFrames.swift */,
295301
949E5EAF1ACB340200AB6280 /* UIImageView+Download.swift */,
296302
94E9761B1B1A8F3200F52B1E /* UIImage+DropShadow.swift */,
303+
53113F38230C720900462C0E /* ShareImageGenerator.swift */,
304+
6258DCD722D93A3500166C65 /* LogoShareView.swift */,
305+
6258DCD922D93A5400166C65 /* LogoShareView.xib */,
297306
);
298307
name = "UI Helpers";
299308
sourceTree = "<group>";
@@ -373,7 +382,7 @@
373382
};
374383
9409E1151ABF6FEA00312E2B = {
375384
CreatedOnToolsVersion = 6.2;
376-
DevelopmentTeam = G24WJ3XCZ3;
385+
DevelopmentTeam = 6G96AERJ7Q;
377386
LastSwiftMigration = 1020;
378387
SystemCapabilities = {
379388
com.apple.BackgroundModes = {
@@ -417,6 +426,7 @@
417426
files = (
418427
945DB3C21AD58E3A00495EBB /* stations.json in Resources */,
419428
945DB3C51AD5A6E200495EBB /* NothingFoundCell.xib in Resources */,
429+
6258DCDA22D93A5400166C65 /* LogoShareView.xib in Resources */,
420430
CF72ACE721F7155200461EED /* Main.storyboard in Resources */,
421431
5FDEE0221F72FF980064333C /* LaunchScreen.storyboard in Resources */,
422432
9409E1261ABF6FEA00312E2B /* Images.xcassets in Resources */,
@@ -449,11 +459,13 @@
449459
94D30EA71AD07A880024FE96 /* StationTableViewCell.swift in Sources */,
450460
5F22BA3C1F72AD5A00CB5911 /* SpringLabel.swift in Sources */,
451461
5F22BA3D1F72AD5A00CB5911 /* BlurView.swift in Sources */,
462+
53113F39230C720900462C0E /* ShareImageGenerator.swift in Sources */,
452463
5F22BA411F72AD5A00CB5911 /* SpringTextField.swift in Sources */,
453464
9409E1401ABF78B000312E2B /* NowPlayingViewController.swift in Sources */,
454465
94D1D0A51AD6D6230022CA11 /* InfoDetailViewController.swift in Sources */,
455466
5F22BA4B1F72AD5A00CB5911 /* KeyboardLayoutConstraint.swift in Sources */,
456467
5F22BA421F72AD5A00CB5911 /* SoundPlayer.swift in Sources */,
468+
6258DCD822D93A3500166C65 /* LogoShareView.swift in Sources */,
457469
5F22BA4A1F72AD5A00CB5911 /* DesignableTextView.swift in Sources */,
458470
949BBB401ACC9DEE005B7C26 /* DataManager.swift in Sources */,
459471
5F22BA4E1F72AD5A00CB5911 /* Misc.swift in Sources */,
@@ -639,6 +651,7 @@
639651
CODE_SIGN_IDENTITY = "iPhone Developer";
640652
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
641653
DEFINES_MODULE = YES;
654+
DEVELOPMENT_TEAM = 6G96AERJ7Q;
642655
FRAMEWORK_SEARCH_PATHS = (
643656
"$(inherited)",
644657
"$(PROJECT_DIR)/SwiftRadio",
@@ -662,6 +675,7 @@
662675
CODE_SIGN_IDENTITY = "iPhone Developer";
663676
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
664677
DEFINES_MODULE = YES;
678+
DEVELOPMENT_TEAM = 6G96AERJ7Q;
665679
FRAMEWORK_SEARCH_PATHS = (
666680
"$(inherited)",
667681
"$(PROJECT_DIR)/SwiftRadio",

SwiftRadio/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>2.0.6</string>
20+
<string>2.0.7</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleVersion</key>

SwiftRadio/LogoShareView.swift

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// LogoShareView.swift
3+
// SwiftRadio
4+
//
5+
// Created by Cameron Mcleod on 2019-07-12.
6+
// Copyright © 2019 matthewfecher.com. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class LogoShareView: UIView {
12+
13+
@IBOutlet weak var albumArtImageView: UIImageView!
14+
@IBOutlet weak var radioShoutoutLabel: UILabel!
15+
@IBOutlet weak var trackTitleLabel: UILabel!
16+
@IBOutlet weak var trackArtistLabel: UILabel!
17+
@IBOutlet weak var logoImageView: UIImageView!
18+
19+
class func instanceFromNib() -> LogoShareView {
20+
return UINib(nibName: "LogoShareView", bundle: nil).instantiate(withOwner: nil, options: nil)[0] as! LogoShareView
21+
}
22+
23+
func shareSetup(albumArt : UIImage, radioShoutout: String, trackTitle: String, trackArtist: String) {
24+
self.albumArtImageView.image = albumArt
25+
self.radioShoutoutLabel.text = radioShoutout
26+
self.trackTitleLabel.text = trackTitle
27+
self.trackArtistLabel.text = trackArtist
28+
self.logoImageView.image = UIImage(named: "logo")
29+
}
30+
}

SwiftRadio/LogoShareView.xib

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
3+
<device id="retina6_1" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
6+
<dependencies>
7+
<deployment identifier="iOS"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
9+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
10+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
11+
</dependencies>
12+
<objects>
13+
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
14+
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
15+
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="LogoShareView" customModule="SwiftRadio" customModuleProvider="target">
16+
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
17+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
18+
<subviews>
19+
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="20" translatesAutoresizingMaskIntoConstraints="NO" id="sgO-Os-qNc" userLabel="Main Stack">
20+
<rect key="frame" x="8" y="8" width="584" height="584"/>
21+
<subviews>
22+
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="zmo-M8-m9o" userLabel="Album Art">
23+
<rect key="frame" x="0.0" y="0.0" width="584" height="435"/>
24+
<constraints>
25+
<constraint firstAttribute="height" constant="435" id="odw-Xz-Dzz"/>
26+
</constraints>
27+
</imageView>
28+
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="20" translatesAutoresizingMaskIntoConstraints="NO" id="tPe-Vc-KR3" userLabel="Track Info">
29+
<rect key="frame" x="0.0" y="455" width="584" height="88"/>
30+
<subviews>
31+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ptC-tD-gdN" userLabel="Title">
32+
<rect key="frame" x="0.0" y="0.0" width="181.5" height="88"/>
33+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
34+
<color key="textColor" cocoaTouchSystemColor="lightTextColor"/>
35+
<color key="highlightedColor" cocoaTouchSystemColor="lightTextColor"/>
36+
</label>
37+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="UhH-FP-Yas" userLabel="Artist">
38+
<rect key="frame" x="201.5" y="0.0" width="181" height="88"/>
39+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
40+
<color key="textColor" cocoaTouchSystemColor="lightTextColor"/>
41+
<color key="highlightedColor" cocoaTouchSystemColor="lightTextColor"/>
42+
</label>
43+
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Wb0-C0-hGr" userLabel="Logo">
44+
<rect key="frame" x="402.5" y="0.0" width="181.5" height="88"/>
45+
</imageView>
46+
</subviews>
47+
</stackView>
48+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="LsP-Sq-acL" userLabel="Radio Shoutout">
49+
<rect key="frame" x="0.0" y="563" width="584" height="21"/>
50+
<constraints>
51+
<constraint firstAttribute="height" constant="21" id="gRG-0o-oJ8"/>
52+
</constraints>
53+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
54+
<color key="textColor" cocoaTouchSystemColor="lightTextColor"/>
55+
<nil key="highlightedColor"/>
56+
</label>
57+
</subviews>
58+
</stackView>
59+
</subviews>
60+
<color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
61+
<constraints>
62+
<constraint firstItem="sgO-Os-qNc" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="8" id="Mtg-2A-d5g"/>
63+
<constraint firstItem="sgO-Os-qNc" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" constant="8" id="PAp-lT-AWa"/>
64+
<constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="sgO-Os-qNc" secondAttribute="trailing" constant="8" id="Ydx-tF-aHS"/>
65+
<constraint firstAttribute="bottom" secondItem="sgO-Os-qNc" secondAttribute="bottom" constant="8" id="f80-X9-fsP"/>
66+
</constraints>
67+
<nil key="simulatedTopBarMetrics"/>
68+
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
69+
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
70+
<connections>
71+
<outlet property="albumArtImageView" destination="zmo-M8-m9o" id="UAh-AN-ANo"/>
72+
<outlet property="logoImageView" destination="Wb0-C0-hGr" id="P1S-1A-jy7"/>
73+
<outlet property="radioShoutoutLabel" destination="LsP-Sq-acL" id="o6j-gY-1Wg"/>
74+
<outlet property="trackArtistLabel" destination="UhH-FP-Yas" id="NR4-tS-aF6"/>
75+
<outlet property="trackTitleLabel" destination="ptC-tD-gdN" id="EHQ-oR-a74"/>
76+
</connections>
77+
</view>
78+
</objects>
79+
</document>

SwiftRadio/NowPlayingViewController.swift

+5-2
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,11 @@ class NowPlayingViewController: UIViewController {
347347
}
348348

349349
@IBAction func shareButtonPressed(_ sender: UIButton) {
350-
let songToShare = "I'm listening to \(currentTrack.title) on \(currentStation.name) via Swift Radio Pro"
351-
let activityViewController = UIActivityViewController(activityItems: [songToShare, currentTrack.artworkImage!], applicationActivities: nil)
350+
351+
let radioShoutout = "I'm listening to \(currentStation.name) via Swift Radio Pro"
352+
let shareImage = ShareImageGenerator(radioShoutout: radioShoutout, track: currentTrack).generate()
353+
354+
let activityViewController = UIActivityViewController(activityItems: [radioShoutout, shareImage], applicationActivities: nil)
352355
activityViewController.popoverPresentationController?.sourceRect = CGRect(x: view.center.x, y: view.center.y, width: 0, height: 0)
353356
activityViewController.popoverPresentationController?.sourceView = view
354357
activityViewController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)

SwiftRadio/ShareImageGenerator.swift

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// ShareImageCreator.swift
3+
// SwiftRadio
4+
//
5+
// Created by Fethi El Hassasna on 2019-08-20.
6+
// Copyright © 2019 matthewfecher.com. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class ShareImageGenerator {
12+
13+
private let radioShoutout: String
14+
private let track: Track
15+
16+
init(radioShoutout: String, track: Track) {
17+
self.radioShoutout = radioShoutout
18+
self.track = track
19+
}
20+
21+
func generate() -> UIImage {
22+
let logoShareView = LogoShareView.instanceFromNib()
23+
let songToShare = radioShoutout
24+
25+
logoShareView.shareSetup(albumArt: track.artworkImage ?? #imageLiteral(resourceName: "albumArt"), radioShoutout: songToShare, trackTitle: track.title, trackArtist: track.artist)
26+
27+
UIGraphicsBeginImageContextWithOptions(CGSize(width: logoShareView.frame.width, height: logoShareView.frame.height), true, 0)
28+
logoShareView.drawHierarchy(in: logoShareView.frame, afterScreenUpdates: true)
29+
let shareImage = UIGraphicsGetImageFromCurrentImageContext()
30+
UIGraphicsEndImageContext()
31+
32+
return shareImage ?? track.artworkImage ?? #imageLiteral(resourceName: "albumArt")
33+
}
34+
}

0 commit comments

Comments
 (0)