From 0d4ae914c60ef96626f88ae60651b78fc1a1c459 Mon Sep 17 00:00:00 2001 From: Vincent Eichhorn Date: Mon, 3 Jun 2024 14:36:08 +0200 Subject: [PATCH] player in layout und so --- src/SpotifyConnect/SPOCApiEndpoint.class.st | 4 +- src/SpotifyConnect/SPOCApp.class.st | 32 +++------ src/SpotifyConnect/SPOCPlayer.class.st | 72 ++++++++++++++------- 3 files changed, 61 insertions(+), 47 deletions(-) diff --git a/src/SpotifyConnect/SPOCApiEndpoint.class.st b/src/SpotifyConnect/SPOCApiEndpoint.class.st index 877b3b4..4b7f453 100644 --- a/src/SpotifyConnect/SPOCApiEndpoint.class.st +++ b/src/SpotifyConnect/SPOCApiEndpoint.class.st @@ -58,7 +58,7 @@ SPOCApiEndpoint >> endpointMethod [ { #category : #'as yet unclassified', - #'squeak_changestamp' : 'TL 5/30/2024 11:48' + #'squeak_changestamp' : 'VE 6/3/2024 14:34' } SPOCApiEndpoint >> execute: aParamDictionary [ | response request contentStream | @@ -73,7 +73,7 @@ SPOCApiEndpoint >> execute: aParamDictionary [ ifFalse: [response code = 200 ifTrue: [contentStream := response content readStream. ^ self tinkerReponseContent: contentStream] - ifFalse: [^ nil]]]] + ifFalse: [^ 'null Object ', response code asString]]]] ] { diff --git a/src/SpotifyConnect/SPOCApp.class.st b/src/SpotifyConnect/SPOCApp.class.st index 3225220..4a400bc 100644 --- a/src/SpotifyConnect/SPOCApp.class.st +++ b/src/SpotifyConnect/SPOCApp.class.st @@ -4,7 +4,8 @@ Class { #instVars : [ 'auth', 'userLogin', - 'searchbar' + 'searchbar', + 'player' ], #category : #SpotifyConnect } @@ -53,10 +54,10 @@ SPOCApp >> auth: anObject [ { #category : #ui, - #'squeak_changestamp' : 'VE 6/3/2024 09:35' + #'squeak_changestamp' : 'VE 6/3/2024 13:58' } SPOCApp >> bottomPanelContent [ - ^ {SPOCIcon new. SPOCIcon new. SPOCIcon new. SPOCIcon new.} + ^ {self player} ] { @@ -108,22 +109,6 @@ SPOCApp >> buildMainTable: aBuilder [ self buildBottomPanel: aBuilder.}. ] -{ - #category : #ui, - #'squeak_changestamp' : 'TL 5/31/2024 17:29' -} -SPOCApp >> buildPlayerPanel: aBuilder [ - - | proportionalSize | - proportionalSize := self proportionalPanelSizeOf: self player. - ^ aBuilder pluggablePanelSpec new - model: self; - children: #playerPanelContent; - layout: #proportional; - frame: (LayoutFrame fractions: (0.1@0 corner: 1@proportionalSize y)); - yourself -] - { #category : #ui, #'squeak_changestamp' : 'VE 6/3/2024 10:29' @@ -166,7 +151,7 @@ SPOCApp >> buildWith: aBuilder [ { #category : #initialization, - #'squeak_changestamp' : 'RK 5/30/2024 21:57' + #'squeak_changestamp' : 'VE 6/3/2024 13:57' } SPOCApp >> initialize [ @@ -175,7 +160,8 @@ SPOCApp >> initialize [ self auth: SPOCAuthorizer new; registerOpenCommand; setupUserLogin; - setupSearchbar. + setupSearchbar; + setupPlayer. ] @@ -242,12 +228,12 @@ SPOCApp >> searchbar: aSPOCSearchbar [ { #category : #initialization, - #'squeak_changestamp' : 'TL 5/30/2024 12:23' + #'squeak_changestamp' : 'VE 6/3/2024 14:04' } SPOCApp >> setupPlayer [ self player: (SPOCPlayer new app: self; yourself). - self auth registerSuccessCallback: [self player enableButtons]. + self auth registerSuccessCallback: [self player updateIsPlaying]. ] { diff --git a/src/SpotifyConnect/SPOCPlayer.class.st b/src/SpotifyConnect/SPOCPlayer.class.st index abc988e..73e76e6 100644 --- a/src/SpotifyConnect/SPOCPlayer.class.st +++ b/src/SpotifyConnect/SPOCPlayer.class.st @@ -4,7 +4,8 @@ Class { #instVars : [ 'button', 'deviceID', - 'icon' + 'icon', + 'isPlaying' ], #category : #SpotifyConnect } @@ -38,17 +39,14 @@ SPOCPlayer class >> skipNextIconPath [ { #category : #initialization, - #'squeak_changestamp' : 'TL 5/30/2024 12:08' + #'squeak_changestamp' : 'VE 6/3/2024 14:08' } SPOCPlayer >> attachPlayPauseButton [ - | iconPath | - self isPlaying - ifTrue: [iconPath := SPOCPlayer pauseIconPath] - ifFalse: [iconPath := SPOCPlayer playIconPath]. - self icon: (SPOCIcon new iconAsset: iconPath; yourself); + self icon: (SPOCIcon new iconAsset: SPOCPlayer playIconPath; yourself); button: (SPOCClickable newUsing: icon onClick: [:enEvent | self switchPlaybackState]); - addMorph: self button + addMorph: self button; + updatePlayPauseIcon. ] { @@ -130,34 +128,35 @@ SPOCPlayer >> icon: anObject [ { #category : #initialization, - #'squeak_changestamp' : 'TL 5/30/2024 12:10' + #'squeak_changestamp' : 'VE 6/3/2024 14:18' } SPOCPlayer >> initialize [ super initialize. self color: Color transparent; + isPlaying: false; attachPlayPauseButton; attachSkipNextButton; + layoutPolicy: TableLayout new; extendFully ] { #category : #'as yet unclassified', - #'squeak_changestamp' : 'TL 5/31/2024 17:33' + #'squeak_changestamp' : 'VE 6/3/2024 14:01' } SPOCPlayer >> isPlaying [ - | apiEndpoint paramDict response | - paramDict := Dictionary new. - paramDict at: #additional_types put: 'track'. - apiEndpoint := SPOCApiPlaybackState new. - apiEndpoint authorizer: self app auth. - response := apiEndpoint execute: paramDict. - Transcript showln: response. - "self deviceID: (response at: 'device')." - self deviceID: 'b704b454bce64526992a3f207723032f5f91e635'. - ^ response at: 'is_playing' + ^ isPlaying +] + +{ + #category : #accessing, + #'squeak_changestamp' : 'VE 6/3/2024 14:01' +} +SPOCPlayer >> isPlaying: anObject [ + isPlaying := anObject ] { @@ -176,16 +175,18 @@ SPOCPlayer >> pause [ { #category : #'as yet unclassified', - #'squeak_changestamp' : 'TL 5/30/2024 12:16' + #'squeak_changestamp' : 'VE 6/3/2024 14:31' } SPOCPlayer >> play [ | paramDict apiEndpoint response | paramDict := Dictionary new. paramDict at: #device_id put: self deviceID. + Transcript showln: self deviceID. apiEndpoint := SPOCApiPlay new. apiEndpoint authorizer: app auth. - response := apiEndpoint execute: paramDict + response := apiEndpoint execute: paramDict. + response explore. ] { @@ -214,3 +215,30 @@ SPOCPlayer >> switchPlaybackState [ ] + +{ + #category : #'as yet unclassified', + #'squeak_changestamp' : 'VE 6/3/2024 14:32' +} +SPOCPlayer >> updateIsPlaying [ + + | apiEndpoint paramDict response | + paramDict := Dictionary new. + paramDict at: #additional_types put: 'track'. + apiEndpoint := SPOCApiPlaybackState new. + apiEndpoint authorizer: self app auth. + response := apiEndpoint execute: paramDict. + self deviceID: ((response at: #device) at: #id). + self isPlaying: (response at: 'is_playing') +] + +{ + #category : #'as yet unclassified', + #'squeak_changestamp' : 'VE 6/3/2024 14:07' +} +SPOCPlayer >> updatePlayPauseIcon [ + + self isPlaying + ifTrue: [self icon iconAsset: SPOCPlayer pauseIconPath] + ifFalse: [self icon iconAsset: SPOCPlayer playIconPath]. +]