StatusItemBuilder refactor

This commit is contained in:
kmikiy
2017-05-01 12:36:33 +02:00
parent b2d7276088
commit 812ebfbd59
2 changed files with 27 additions and 18 deletions
+5 -1
View File
@@ -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()
}
+22 -17
View File
@@ -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 ) {