Skip to content

Commit

Permalink
Meme updation from the server; Fix the TIFF images getting saved inst…
Browse files Browse the repository at this point in the history
…ead of compressed JPEGs.
  • Loading branch information
avikantz committed Jul 6, 2016
1 parent 57b8eb0 commit 48da012
Show file tree
Hide file tree
Showing 114 changed files with 11,494 additions and 2,307 deletions.
165 changes: 134 additions & 31 deletions Meme Maker Mac.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Meme Maker Mac/Views/Cells/BaseCollectionViewItem.swift"
timestampString = "487332903.260921"
timestampString = "489489507.620738"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "32"
endingLineNumber = "32"
landmarkName = "BaseCollectionViewItem"
landmarkType = "3">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Meme Maker Mac/Views/Cells/BaseCollectionViewItem.swift"
timestampString = "487332188.359997"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "18"
endingLineNumber = "18"
startingLineNumber = "44"
endingLineNumber = "44"
landmarkName = "BaseCollectionViewItem"
landmarkType = "3">
</BreakpointContent>
Expand Down Expand Up @@ -253,7 +237,7 @@
endingColumnNumber = "9223372036854775807"
startingLineNumber = "95"
endingLineNumber = "95"
landmarkName = "prepareForSegue(_:sender:)"
landmarkName = "isGrid()"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
Expand Down
2 changes: 2 additions & 0 deletions Meme Maker Mac/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Copyright © 2016 avikantz. All rights reserved.
//

let kFetchCompleteNotification: String = "kFetchCompleteNotification"

let kToggleViewModeNotification: String = "kToggleViewModeNotification"
let kToggleViewModeKey: String = "kToggleViewModeKey"

Expand Down
22 changes: 22 additions & 0 deletions Meme Maker Mac/Assets.xcassets/MemeBlank.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "MemeBlank.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 22 additions & 16 deletions Meme Maker Mac/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -520,18 +520,8 @@
<action selector="darkModeAction:" target="cWc-bB-CNr" id="Ffe-xv-roP"/>
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="SqC-VJ-CMo">
<rect key="frame" x="54" y="120" width="132" height="32"/>
<buttonCell key="cell" type="push" title="Update Memes" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="W5Q-xw-hJL">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="updateMemesAction:" target="cWc-bB-CNr" id="ahP-Lr-phO"/>
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="q43-wU-MYT">
<rect key="frame" x="191" y="129" width="231" height="17"/>
<rect key="frame" x="170" y="131" width="231" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Last updated: Jun 22 2016, 07:24 PM" id="tcI-Ga-ymv">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlShadowColor" catalog="System" colorSpace="catalog"/>
Expand Down Expand Up @@ -568,19 +558,34 @@
<action selector="resetSettingsAction:" target="cWc-bB-CNr" id="ehq-3v-mHK"/>
</connections>
</button>
<progressIndicator hidden="YES" wantsLayer="YES" horizontalHuggingPriority="750" verticalHuggingPriority="750" maxValue="100" displayedWhenStopped="NO" bezeled="NO" indeterminate="YES" controlSize="small" style="spinning" translatesAutoresizingMaskIntoConstraints="NO" id="SGI-j9-3wU">
<rect key="frame" x="36" y="131" width="16" height="16"/>
</progressIndicator>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="SqC-VJ-CMo">
<rect key="frame" x="60" y="129" width="100" height="19"/>
<buttonCell key="cell" type="roundRect" title="Update Memes" bezelStyle="roundedRect" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="W5Q-xw-hJL">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="cellTitle"/>
</buttonCell>
<connections>
<action selector="updateMemesAction:" target="cWc-bB-CNr" id="ahP-Lr-phO"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="SqC-VJ-CMo" firstAttribute="leading" secondItem="QNy-0M-qOd" secondAttribute="leading" id="28v-Us-RLk"/>
<constraint firstItem="QNy-0M-qOd" firstAttribute="top" secondItem="qTy-cp-Uf8" secondAttribute="bottom" constant="14" id="4cI-ek-UOh"/>
<constraint firstItem="SqC-VJ-CMo" firstAttribute="leading" secondItem="SGI-j9-3wU" secondAttribute="trailing" constant="8" id="4xB-k8-8Ea"/>
<constraint firstAttribute="bottom" secondItem="2cU-yy-mV0" secondAttribute="bottom" constant="20" id="5F3-41-4X1"/>
<constraint firstItem="2cU-yy-mV0" firstAttribute="trailing" secondItem="q43-wU-MYT" secondAttribute="trailing" id="6Yd-a7-bgu"/>
<constraint firstItem="q43-wU-MYT" firstAttribute="trailing" secondItem="QNy-0M-qOd" secondAttribute="trailing" id="8lb-bV-Uc0"/>
<constraint firstItem="qTy-cp-Uf8" firstAttribute="top" secondItem="BpT-fz-c8N" secondAttribute="top" constant="60" id="B3Z-om-Qz7"/>
<constraint firstAttribute="bottom" secondItem="f2t-lk-hxt" secondAttribute="bottom" constant="20" id="C9E-cm-1RF"/>
<constraint firstItem="qTy-cp-Uf8" firstAttribute="leading" secondItem="BpT-fz-c8N" secondAttribute="leading" constant="60" id="JX3-Gb-C0O"/>
<constraint firstItem="q43-wU-MYT" firstAttribute="leading" secondItem="SqC-VJ-CMo" secondAttribute="trailing" constant="12" id="N9f-LA-i6c"/>
<constraint firstItem="SqC-VJ-CMo" firstAttribute="top" secondItem="QNy-0M-qOd" secondAttribute="bottom" constant="20" id="VkD-Bg-fGl"/>
<constraint firstItem="f2t-lk-hxt" firstAttribute="leading" secondItem="SqC-VJ-CMo" secondAttribute="leading" id="aCc-a1-QUv"/>
<constraint firstItem="2cU-yy-mV0" firstAttribute="trailing" secondItem="QNy-0M-qOd" secondAttribute="trailing" id="cPt-W3-NK6"/>
<constraint firstItem="QNy-0M-qOd" firstAttribute="leading" secondItem="qTy-cp-Uf8" secondAttribute="leading" id="ipw-Yg-yKN"/>
<constraint firstItem="SGI-j9-3wU" firstAttribute="centerY" secondItem="SqC-VJ-CMo" secondAttribute="centerY" id="lHV-4T-BIg"/>
<constraint firstItem="q43-wU-MYT" firstAttribute="centerY" secondItem="SqC-VJ-CMo" secondAttribute="centerY" id="mEW-N7-Bbu"/>
<constraint firstAttribute="trailing" secondItem="qTy-cp-Uf8" secondAttribute="trailing" constant="60" id="nln-9h-GbZ"/>
<constraint firstItem="QNy-0M-qOd" firstAttribute="trailing" secondItem="qTy-cp-Uf8" secondAttribute="trailing" id="vVi-zq-QiJ"/>
Expand All @@ -598,6 +603,7 @@
<outlet property="darkModeButton" destination="QNy-0M-qOd" id="OoS-YR-hDI"/>
<outlet property="lastUpdatedLabel" destination="q43-wU-MYT" id="yx4-wR-Cq4"/>
<outlet property="resetSettingsButton" destination="qTy-cp-Uf8" id="dhK-RJ-jVT"/>
<outlet property="updationSpinner" destination="SGI-j9-3wU" id="amV-JF-fTH"/>
</connections>
</viewController>
<customObject id="tsZ-WO-BRW" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
Expand Down Expand Up @@ -1101,23 +1107,23 @@
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="IlK-Px-2sU">
<rect key="frame" x="18" y="24" width="58" height="14"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Text Color" id="6OJ-vn-oSL">
<font key="font" metaFont="system" size="11"/>
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="kao-c9-8Ip">
<rect key="frame" x="132" y="24" width="57" height="14"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Text Font" id="m7k-oZ-exq">
<font key="font" metaFont="system" size="11"/>
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="NMw-m6-IOj">
<rect key="frame" x="229" y="24" width="73" height="14"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Outline Color" id="CXE-3r-vpx">
<font key="font" metaFont="system" size="11"/>
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
Expand Down
48 changes: 45 additions & 3 deletions Meme Maker Mac/Controllers/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class SettingsViewController: NSViewController {
@IBOutlet weak var darkModeButton: NSButton!

@IBOutlet weak var lastUpdatedLabel: NSTextField!

@IBOutlet weak var updationSpinner: NSProgressIndicator!

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -24,6 +26,8 @@ class SettingsViewController: NSViewController {

// darkModeButton.state = SettingsManager.getBool(ksettings)

lastUpdatedLabel.stringValue = "Last updated: " + SettingsManager.getLastUpdateDateString()

}

}
Expand All @@ -39,16 +43,54 @@ extension SettingsViewController {
}

@IBAction func updateMemesAction(sender: AnyObject) {
// Perform update...
let fetcher = MemeFetcher()
fetcher.fetchMemes()
updationSpinner.hidden = false
updationSpinner.startAnimation(self)
NSNotificationCenter.defaultCenter().addObserverForName(kFetchCompleteNotification, object: nil, queue: NSOperationQueue.mainQueue()) { (notification) in
self.updationSpinner.stopAnimation(self)
self.updationSpinner.hidden = true
self.lastUpdatedLabel.stringValue = "Last updated: " + SettingsManager.getLastUpdateDateString()
}
}

@IBAction func reportBugAction(sender: AnyObject) {

let shareItems = [getSystemDetails()]
let service = NSSharingService(named: NSSharingServiceNameComposeEmail)
service?.delegate = self
service?.recipients = ["[email protected]"]
service?.subject = "Meme maker bug report"
service?.performWithItems(shareItems)
}

@IBAction func feedbackAction(sender: AnyObject) {

let shareItems = [getSystemDetails()]
let service = NSSharingService(named: NSSharingServiceNameComposeEmail)
service?.delegate = self
service?.recipients = ["[email protected]"]
service?.subject = "Meme maker feedback/suggestion"
service?.performWithItems(shareItems)
}

func getSystemDetails() -> String {
if let dict = NSDictionary(contentsOfFile: "/System/Library/CoreServices/SystemVersion.plist") {
let details = "\n\n\nSystem version = \(dict["ProductName"]!) \(dict["ProductVersion"]!)\n"
return details
}
return ""
}

}

extension SettingsViewController: NSSharingServiceDelegate {

func sharingService(sharingService: NSSharingService, didShareItems items: [AnyObject]) {
print("share success")
}

func sharingService(sharingService: NSSharingService, didFailToShareItems items: [AnyObject], error: NSError) {
print("share failure")
}

}

11 changes: 10 additions & 1 deletion Meme Maker Mac/Controllers/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ class ViewController: NSViewController {
self.collectionView.reloadData()
}

NSNotificationCenter.defaultCenter().addObserverForName(kFetchCompleteNotification, object: nil, queue: NSOperationQueue.mainQueue()) { (notification) in
self.fetchLocalMemes()
}

if (NSDate().timeIntervalSinceDate(SettingsManager.getLastUpdateDate())) > 7 * 86400 {
print("Fetching latest memes, just for you!")
let fetcher = MemeFetcher()
fetcher.fetchMemes()
}

}

func fetchLocalMemes() -> Void {
Expand All @@ -63,7 +73,6 @@ class ViewController: NSViewController {
catch _ {
print("Error in fetching.")
}

self.filterMemesWithSearchText(self.searchField.stringValue)
}

Expand Down
5 changes: 5 additions & 0 deletions Meme Maker Mac/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,10 @@
<string>Main</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</plist>
8 changes: 0 additions & 8 deletions Meme Maker Mac/Meme Maker Mac.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,9 @@
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.assets.pictures.read-write</key>
<true/>
<key>com.apple.security.device.camera</key>
<true/>
<key>com.apple.security.files.downloads.read-write</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.network.server</key>
<true/>
</dict>
</plist>
73 changes: 73 additions & 0 deletions Meme Maker Mac/Models/MemeFetcher.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// MemeFetcher.swift
// Meme Maker Mac
//
// Created by Avikant Saini on 7/6/16.
// Copyright © 2016 avikantz. All rights reserved.
//

import Cocoa

public class MemeFetcher: NSObject {

private var context: NSManagedObjectContext? = nil

private var memes = NSMutableArray()
private var fetchedMemes = NSMutableArray()

override init() {
super.init()
let appDelegate = NSApplication.sharedApplication().delegate as! AppDelegate
context = appDelegate.managedObjectContext
}

public func fetchMemes() -> Void {
fetchMemes(0)
}

private func fetchMemes(paging: Int) -> Void {
let request = NSMutableURLRequest(URL: apiMemesPaging(paging))
request.HTTPMethod = "GET"
NSURLSession.sharedSession().dataTaskWithRequest(request) { (data, response, error) in
if (error != nil) {
print("Error: %@", error?.localizedDescription)
return
}
if (data != nil) {
do {
let persistentStoreCoordinator = self.context?.persistentStoreCoordinator
let asyncContext: NSManagedObjectContext = NSManagedObjectContext(concurrencyType: .PrivateQueueConcurrencyType)
asyncContext.persistentStoreCoordinator = persistentStoreCoordinator

let json = try NSJSONSerialization.JSONObjectWithData(data!, options: .MutableContainers)
let code = json.valueForKey("code") as! Int
if (code == 200) {
let jsonmemes = json.valueForKey("data") as! NSArray
let memesArray = XMeme.getAllMemesFromArray(jsonmemes, context: asyncContext)!
for meme in memesArray {
self.fetchedMemes.addObject(meme)
}
try asyncContext.save()
dispatch_async(dispatch_get_main_queue(), {
self.fetchMemes(paging + 1)
})
}
else {
self.memes = self.fetchedMemes
dispatch_async(dispatch_get_main_queue(), {
SettingsManager.saveLastUpdateDate()
NSNotificationCenter.defaultCenter().postNotificationName(kFetchCompleteNotification, object: nil, userInfo: ["memes": self.memes])
})
return
}
}
catch _ {
print("Unable to parse")
return
}
}
}.resume()

}

}
10 changes: 10 additions & 0 deletions Meme Maker Mac/Models/SettingsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,14 @@ class SettingsManager: NSObject {
return NSDate(timeIntervalSinceNow: (-10 * 86400))
}

class func getLastUpdateDateString() -> String {
if (defaults.objectForKey("lastUpdateDate") != nil) {
let formatter = NSDateFormatter()
formatter.dateFormat = "MMM dd, yyyy hh:mm a"
let date = self.getLastUpdateDate()
return formatter.stringFromDate(date)
}
return ""
}

}
Loading

0 comments on commit 48da012

Please sign in to comment.