Skip to content

Commit

Permalink
Merge pull request #127 from analogcode/dev
Browse files Browse the repository at this point in the history
Add watermarked image for share activity by @CamMcLeod
  • Loading branch information
fethica authored Aug 20, 2019
2 parents e1f69ee + 8ed5bff commit 7bdd5e7
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Give it a quick watch.
* Download and cache images using ImageLoader class

## Important Notes
- 8.20.19: Add watermarked image for share activity by [@CamMcLeod](https://github.com/CamMcLeod).
- 5.18.19: master branch migrated to Xcode 10.2/Swift 5 by [@fethica](https://github.com/fethica).
- 9.4.19: Add AirPlay support by [@geraldnolan](https://github.com/geraldnolan).
- 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).
Expand Down
16 changes: 15 additions & 1 deletion SwiftRadio.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
2C5545BD1C1124DE00728469 /* SwiftRadioUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C5545BC1C1124DE00728469 /* SwiftRadioUITests.swift */; };
53113F39230C720900462C0E /* ShareImageGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53113F38230C720900462C0E /* ShareImageGenerator.swift */; };
5F22BA3C1F72AD5A00CB5911 /* SpringLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F22BA1E1F72AD3700CB5911 /* SpringLabel.swift */; };
5F22BA3D1F72AD5A00CB5911 /* BlurView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F22BA1F1F72AD3900CB5911 /* BlurView.swift */; };
5F22BA3E1F72AD5A00CB5911 /* DesignableTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F22BA201F72AD3B00CB5911 /* DesignableTabBarController.swift */; };
Expand Down Expand Up @@ -36,6 +37,8 @@
5F22BA551F72AD5A00CB5911 /* AutoTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F22BA3A1F72AD5800CB5911 /* AutoTextView.swift */; };
5F22BA561F72AD5A00CB5911 /* DesignableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F22BA3B1F72AD5900CB5911 /* DesignableView.swift */; };
5FDEE0221F72FF980064333C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5FDEE0211F72FF980064333C /* LaunchScreen.storyboard */; };
6258DCD822D93A3500166C65 /* LogoShareView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6258DCD722D93A3500166C65 /* LogoShareView.swift */; };
6258DCDA22D93A5400166C65 /* LogoShareView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6258DCD922D93A5400166C65 /* LogoShareView.xib */; };
81AD229B21646DEA002ADFDD /* FRadioPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81AD229821646DEA002ADFDD /* FRadioPlayer.swift */; };
81AD229C21646DEA002ADFDD /* FRadioAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81AD229921646DEA002ADFDD /* FRadioAPI.swift */; };
81AD229D21646DEA002ADFDD /* Reachability.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81AD229A21646DEA002ADFDD /* Reachability.swift */; };
Expand Down Expand Up @@ -74,6 +77,7 @@
2C5545BA1C1124DE00728469 /* SwiftRadioUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftRadioUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
2C5545BC1C1124DE00728469 /* SwiftRadioUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftRadioUITests.swift; sourceTree = "<group>"; };
2C5545BE1C1124DE00728469 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
53113F38230C720900462C0E /* ShareImageGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareImageGenerator.swift; sourceTree = "<group>"; };
5F22BA1E1F72AD3700CB5911 /* SpringLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpringLabel.swift; sourceTree = "<group>"; };
5F22BA1F1F72AD3900CB5911 /* BlurView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurView.swift; sourceTree = "<group>"; };
5F22BA201F72AD3B00CB5911 /* DesignableTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DesignableTabBarController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -105,6 +109,8 @@
5F22BA3A1F72AD5800CB5911 /* AutoTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoTextView.swift; sourceTree = "<group>"; };
5F22BA3B1F72AD5900CB5911 /* DesignableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DesignableView.swift; sourceTree = "<group>"; };
5FDEE0211F72FF980064333C /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
6258DCD722D93A3500166C65 /* LogoShareView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogoShareView.swift; sourceTree = "<group>"; };
6258DCD922D93A5400166C65 /* LogoShareView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LogoShareView.xib; sourceTree = "<group>"; };
81AD229821646DEA002ADFDD /* FRadioPlayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FRadioPlayer.swift; sourceTree = "<group>"; };
81AD229921646DEA002ADFDD /* FRadioAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FRadioAPI.swift; sourceTree = "<group>"; };
81AD229A21646DEA002ADFDD /* Reachability.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Reachability.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -294,6 +300,9 @@
94D260951B45E3FA00DE671C /* AnimationFrames.swift */,
949E5EAF1ACB340200AB6280 /* UIImageView+Download.swift */,
94E9761B1B1A8F3200F52B1E /* UIImage+DropShadow.swift */,
53113F38230C720900462C0E /* ShareImageGenerator.swift */,
6258DCD722D93A3500166C65 /* LogoShareView.swift */,
6258DCD922D93A5400166C65 /* LogoShareView.xib */,
);
name = "UI Helpers";
sourceTree = "<group>";
Expand Down Expand Up @@ -373,7 +382,7 @@
};
9409E1151ABF6FEA00312E2B = {
CreatedOnToolsVersion = 6.2;
DevelopmentTeam = G24WJ3XCZ3;
DevelopmentTeam = 6G96AERJ7Q;
LastSwiftMigration = 1020;
SystemCapabilities = {
com.apple.BackgroundModes = {
Expand Down Expand Up @@ -417,6 +426,7 @@
files = (
945DB3C21AD58E3A00495EBB /* stations.json in Resources */,
945DB3C51AD5A6E200495EBB /* NothingFoundCell.xib in Resources */,
6258DCDA22D93A5400166C65 /* LogoShareView.xib in Resources */,
CF72ACE721F7155200461EED /* Main.storyboard in Resources */,
5FDEE0221F72FF980064333C /* LaunchScreen.storyboard in Resources */,
9409E1261ABF6FEA00312E2B /* Images.xcassets in Resources */,
Expand Down Expand Up @@ -449,11 +459,13 @@
94D30EA71AD07A880024FE96 /* StationTableViewCell.swift in Sources */,
5F22BA3C1F72AD5A00CB5911 /* SpringLabel.swift in Sources */,
5F22BA3D1F72AD5A00CB5911 /* BlurView.swift in Sources */,
53113F39230C720900462C0E /* ShareImageGenerator.swift in Sources */,
5F22BA411F72AD5A00CB5911 /* SpringTextField.swift in Sources */,
9409E1401ABF78B000312E2B /* NowPlayingViewController.swift in Sources */,
94D1D0A51AD6D6230022CA11 /* InfoDetailViewController.swift in Sources */,
5F22BA4B1F72AD5A00CB5911 /* KeyboardLayoutConstraint.swift in Sources */,
5F22BA421F72AD5A00CB5911 /* SoundPlayer.swift in Sources */,
6258DCD822D93A3500166C65 /* LogoShareView.swift in Sources */,
5F22BA4A1F72AD5A00CB5911 /* DesignableTextView.swift in Sources */,
949BBB401ACC9DEE005B7C26 /* DataManager.swift in Sources */,
5F22BA4E1F72AD5A00CB5911 /* Misc.swift in Sources */,
Expand Down Expand Up @@ -639,6 +651,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 6G96AERJ7Q;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/SwiftRadio",
Expand All @@ -662,6 +675,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 6G96AERJ7Q;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/SwiftRadio",
Expand Down
2 changes: 1 addition & 1 deletion SwiftRadio/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.0.6</string>
<string>2.0.7</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
30 changes: 30 additions & 0 deletions SwiftRadio/LogoShareView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// LogoShareView.swift
// SwiftRadio
//
// Created by Cameron Mcleod on 2019-07-12.
// Copyright © 2019 matthewfecher.com. All rights reserved.
//

import UIKit

class LogoShareView: UIView {

@IBOutlet weak var albumArtImageView: UIImageView!
@IBOutlet weak var radioShoutoutLabel: UILabel!
@IBOutlet weak var trackTitleLabel: UILabel!
@IBOutlet weak var trackArtistLabel: UILabel!
@IBOutlet weak var logoImageView: UIImageView!

class func instanceFromNib() -> LogoShareView {
return UINib(nibName: "LogoShareView", bundle: nil).instantiate(withOwner: nil, options: nil)[0] as! LogoShareView
}

func shareSetup(albumArt : UIImage, radioShoutout: String, trackTitle: String, trackArtist: String) {
self.albumArtImageView.image = albumArt
self.radioShoutoutLabel.text = radioShoutout
self.trackTitleLabel.text = trackTitle
self.trackArtistLabel.text = trackArtist
self.logoImageView.image = UIImage(named: "logo")
}
}
79 changes: 79 additions & 0 deletions SwiftRadio/LogoShareView.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<device id="retina6_1" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="LogoShareView" customModule="SwiftRadio" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="20" translatesAutoresizingMaskIntoConstraints="NO" id="sgO-Os-qNc" userLabel="Main Stack">
<rect key="frame" x="8" y="8" width="584" height="584"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="zmo-M8-m9o" userLabel="Album Art">
<rect key="frame" x="0.0" y="0.0" width="584" height="435"/>
<constraints>
<constraint firstAttribute="height" constant="435" id="odw-Xz-Dzz"/>
</constraints>
</imageView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="20" translatesAutoresizingMaskIntoConstraints="NO" id="tPe-Vc-KR3" userLabel="Track Info">
<rect key="frame" x="0.0" y="455" width="584" height="88"/>
<subviews>
<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">
<rect key="frame" x="0.0" y="0.0" width="181.5" height="88"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="lightTextColor"/>
<color key="highlightedColor" cocoaTouchSystemColor="lightTextColor"/>
</label>
<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">
<rect key="frame" x="201.5" y="0.0" width="181" height="88"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="lightTextColor"/>
<color key="highlightedColor" cocoaTouchSystemColor="lightTextColor"/>
</label>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Wb0-C0-hGr" userLabel="Logo">
<rect key="frame" x="402.5" y="0.0" width="181.5" height="88"/>
</imageView>
</subviews>
</stackView>
<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">
<rect key="frame" x="0.0" y="563" width="584" height="21"/>
<constraints>
<constraint firstAttribute="height" constant="21" id="gRG-0o-oJ8"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="lightTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
</subviews>
<color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="sgO-Os-qNc" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="8" id="Mtg-2A-d5g"/>
<constraint firstItem="sgO-Os-qNc" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" constant="8" id="PAp-lT-AWa"/>
<constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="sgO-Os-qNc" secondAttribute="trailing" constant="8" id="Ydx-tF-aHS"/>
<constraint firstAttribute="bottom" secondItem="sgO-Os-qNc" secondAttribute="bottom" constant="8" id="f80-X9-fsP"/>
</constraints>
<nil key="simulatedTopBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
<connections>
<outlet property="albumArtImageView" destination="zmo-M8-m9o" id="UAh-AN-ANo"/>
<outlet property="logoImageView" destination="Wb0-C0-hGr" id="P1S-1A-jy7"/>
<outlet property="radioShoutoutLabel" destination="LsP-Sq-acL" id="o6j-gY-1Wg"/>
<outlet property="trackArtistLabel" destination="UhH-FP-Yas" id="NR4-tS-aF6"/>
<outlet property="trackTitleLabel" destination="ptC-tD-gdN" id="EHQ-oR-a74"/>
</connections>
</view>
</objects>
</document>
7 changes: 5 additions & 2 deletions SwiftRadio/NowPlayingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,11 @@ class NowPlayingViewController: UIViewController {
}

@IBAction func shareButtonPressed(_ sender: UIButton) {
let songToShare = "I'm listening to \(currentTrack.title) on \(currentStation.name) via Swift Radio Pro"
let activityViewController = UIActivityViewController(activityItems: [songToShare, currentTrack.artworkImage!], applicationActivities: nil)

let radioShoutout = "I'm listening to \(currentStation.name) via Swift Radio Pro"
let shareImage = ShareImageGenerator(radioShoutout: radioShoutout, track: currentTrack).generate()

let activityViewController = UIActivityViewController(activityItems: [radioShoutout, shareImage], applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceRect = CGRect(x: view.center.x, y: view.center.y, width: 0, height: 0)
activityViewController.popoverPresentationController?.sourceView = view
activityViewController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
Expand Down
34 changes: 34 additions & 0 deletions SwiftRadio/ShareImageGenerator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// ShareImageCreator.swift
// SwiftRadio
//
// Created by Fethi El Hassasna on 2019-08-20.
// Copyright © 2019 matthewfecher.com. All rights reserved.
//

import UIKit

class ShareImageGenerator {

private let radioShoutout: String
private let track: Track

init(radioShoutout: String, track: Track) {
self.radioShoutout = radioShoutout
self.track = track
}

func generate() -> UIImage {
let logoShareView = LogoShareView.instanceFromNib()
let songToShare = radioShoutout

logoShareView.shareSetup(albumArt: track.artworkImage ?? #imageLiteral(resourceName: "albumArt"), radioShoutout: songToShare, trackTitle: track.title, trackArtist: track.artist)

UIGraphicsBeginImageContextWithOptions(CGSize(width: logoShareView.frame.width, height: logoShareView.frame.height), true, 0)
logoShareView.drawHierarchy(in: logoShareView.frame, afterScreenUpdates: true)
let shareImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

return shareImage ?? track.artworkImage ?? #imageLiteral(resourceName: "albumArt")
}
}

0 comments on commit 7bdd5e7

Please sign in to comment.