From 812ebfbd593cdd461bb0fd39c14bc14c2023aa4b Mon Sep 17 00:00:00 2001 From: kmikiy Date: Mon, 1 May 2017 12:36:33 +0200 Subject: [PATCH] StatusItemBuilder refactor --- SpotMenu/AppDelegate.swift | 6 ++++- SpotMenu/StatusItemBuilder.swift | 39 ++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/SpotMenu/AppDelegate.swift b/SpotMenu/AppDelegate.swift index 83c7b18..88fb019 100644 --- a/SpotMenu/AppDelegate.swift +++ b/SpotMenu/AppDelegate.swift @@ -69,7 +69,11 @@ class AppDelegate: NSObject, NSApplicationDelegate { } func updateTitle(){ - statusItem.title = StatusItemBuilder().showTitle().showArtist().showPlayingIcon().getString() + statusItem.title = StatusItemBuilder() + .showTitle(v: true) + .showArtist(v: true) + .showPlayingIcon(v: true) + .getString() } diff --git a/SpotMenu/StatusItemBuilder.swift b/SpotMenu/StatusItemBuilder.swift index e3892b5..d16ccdc 100644 --- a/SpotMenu/StatusItemBuilder.swift +++ b/SpotMenu/StatusItemBuilder.swift @@ -19,36 +19,45 @@ class StatusItemBuilder { init() { self.state = Spotify.playerState } - func showTitle() -> StatusItemBuilder { + func showTitle(v: Bool) -> StatusItemBuilder { + if !v { + self.title = "" + return self + } if let title = Spotify.currentTrack.title { self.title = title + " " } return self } - func hideTitle() -> StatusItemBuilder { - self.title = "" - return self - } - func showArtist() -> StatusItemBuilder { + + func showArtist(v: Bool) -> StatusItemBuilder { + if !v { + self.artist = "" + return self + } if let artist = Spotify.currentTrack.artist { self.artist = artist + " " } return self } + - func hideArtist() -> StatusItemBuilder { - self.artist = "" - return self - } - - func showAlbumArtist() -> StatusItemBuilder { + func showAlbumArtist(v: Bool) -> StatusItemBuilder { + if !v { + self.artist = "" + return self + } if let artist = Spotify.currentTrack.albumArtist { self.artist = artist + " " } return self } - func showPlayingIcon() -> StatusItemBuilder { + func showPlayingIcon(v: Bool) -> StatusItemBuilder { + if !v { + playingIcon = "" + return self + } if (state == PlayerState.playing) { playingIcon = "♫ " } else { @@ -56,10 +65,6 @@ class StatusItemBuilder { } return self } - func hidePlayingIcon() -> StatusItemBuilder { - playingIcon = "" - return self - } func getString() -> String { if( artist.characters.count != 0 && title.characters.count != 0 ) {