Skip to content

Commit

Permalink
Merge pull request #9 from skiptomyliu/2018-10-27-searchfree
Browse files Browse the repository at this point in the history
Remove album and playlist from search results on free version
  • Loading branch information
skiptomyliu authored Oct 27, 2018
2 parents af5dc11 + 8bc810c commit 070ea16
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 11 deletions.
Binary file modified App/Milkshake.dmg
Binary file not shown.
Binary file not shown.
6 changes: 5 additions & 1 deletion Milkshake/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ class API: NSObject {
}

func search(txt:String, callbackHandler: @escaping(_ Dictionary:[String:AnyObject]) -> ()) {
let types = ["AL","AR","CO","TR","SF","PL"]
let appDelegate = NSApplication.shared.delegate as! AppDelegate
var types = ["AL","AR","CO","TR","SF","PL"]
if appDelegate.isPremium == false {
types = ["AR","CO","TR"]
}
let params: [String: Any] = [
"query": txt,
"types": types,
Expand Down
17 changes: 14 additions & 3 deletions Milkshake/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, LoginProtocol {
@IBOutlet weak var menuCrossFade: NSMenuItem!
@IBOutlet weak var menuShuffle: NSMenuItem!
@IBOutlet weak var menuSpectrum: NSMenuItem!
@IBOutlet weak var menuPlaylist: NSMenuItem!
@IBOutlet weak var menuArtists: NSMenuItem!

private var hotKey: HotKey? {
didSet {
Expand All @@ -58,8 +60,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, LoginProtocol {
let modifier = hotKey.keyCombo.carbonModifiers
let mainVc = self?.windowController?.contentViewController as! MainViewController
if keyCode == 0x12 && modifier == 0x100 { mainVc.loadNowPlaying(self!) }
else if keyCode == 0x13 && modifier == 0x100 { mainVc.loadStationResults(self!) }
else if keyCode == 0x14 && modifier == 0x100 { mainVc.loadPlaylistResults(self!) }
else if keyCode == 0x13 && modifier == 0x100 {
mainVc.loadStationResults(self!)
}
else if keyCode == 0x14 && modifier == 0x100 && self!.isPremium {
mainVc.loadPlaylistResults(self!)
}
// u
else if keyCode == 0x31 && modifier == 0x1100 { mainVc.showWindow() }
// p
Expand Down Expand Up @@ -191,12 +197,17 @@ class AppDelegate: NSObject, NSApplicationDelegate, LoginProtocol {
}
}


func handleSuccessLogin(results: Dictionary<String, AnyObject>) {
print(results)
let authToken = results["authToken"] as! String
let config = results["config"] as! [String: AnyObject]
self.isPremium = (config["branding"] as! String).lowercased() == "pandorapremium"


if self.isPremium == false {
self.menuArtists.isHidden = true
self.menuPlaylist.isHidden = true
}
// Setting
let defaults = UserDefaults.standard
defaults.set(authToken, forKey: "authToken")
Expand Down
2 changes: 2 additions & 0 deletions Milkshake/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,10 @@
</application>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="Milkshake" customModuleProvider="target">
<connections>
<outlet property="menuArtists" destination="mjV-xy-KI5" id="vHt-WY-2i8"/>
<outlet property="menuCrossFade" destination="NtY-pt-7Kk" id="aPv-1I-B1q"/>
<outlet property="menuKeepWindowFront" destination="FhU-Ke-a4p" id="9wp-u3-rtj"/>
<outlet property="menuPlaylist" destination="9VX-WE-gVg" id="SR4-l4-s2d"/>
<outlet property="menuShuffle" destination="pkH-kS-bb6" id="gbL-7H-doI"/>
<outlet property="menuSpectrum" destination="Kww-k5-3sZ" id="u4L-2D-zGw"/>
</connections>
Expand Down
2 changes: 1 addition & 1 deletion Milkshake/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>3</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.music</string>
<key>LSMinimumSystemVersion</key>
Expand Down
8 changes: 7 additions & 1 deletion Milkshake/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,13 @@ extension MainViewController: CellSelectedProtocol {
self.cellArtistSelectedProtocol(item: item)
}
else if type == MusicType.ARTIST {
appDelegate.api.catalogDetails(pandoraId: item.artistId!, callbackHandler: callbackArtist)
if self.appDelegate.isPremium == false {
cell.setPlaying(isPlaying: true, isFocus: true)
appDelegate.radio.playerPause()
appDelegate.api.createStation(pandoraId:item.pandoraId!, callbackHandler: createStationCallback)
} else {
appDelegate.api.catalogDetails(pandoraId: item.artistId!, callbackHandler: callbackArtist)
}
}
else if type == MusicType.STATION {
// if playing already, pause
Expand Down
17 changes: 12 additions & 5 deletions Milkshake/SearchTableCellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,18 @@ class SearchTableCellView: NSTableCellView {
}

func show_play() -> Bool {
return (
self.item.hasInteractive == true &&
(self.appDelegate.isPremium || (self.appDelegate.isPremium == false && self.item.cellType != CellType.ARTIST)) &&
(self.item.type == MusicType.TRACK || self.item.type == MusicType.PLAYLIST || self.item.type == MusicType.ALBUM || self.item.type == MusicType.STATION)
)
if self.appDelegate.isPremium {
return (
self.item.hasInteractive == true &&
(self.item.type == MusicType.TRACK || self.item.type == MusicType.PLAYLIST || self.item.type == MusicType.ALBUM || self.item.type == MusicType.STATION)
)
} else {
return (
self.item.hasInteractive == true &&
(self.item.cellType != CellType.ARTIST) &&
(self.item.type == MusicType.TRACK || self.item.type == MusicType.PLAYLIST || self.item.type == MusicType.ALBUM || self.item.type == MusicType.STATION || self.item.type == MusicType.ARTIST)
)
}
}
override func mouseEntered(with event: NSEvent) {
let row:NSTableRowView = self.superview as! NSTableRowView
Expand Down

0 comments on commit 070ea16

Please sign in to comment.