Skip to content

Commit

Permalink
player in layout und so
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Eichhorn committed Jun 3, 2024
1 parent f1e47e9 commit 0d4ae91
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 47 deletions.
4 changes: 2 additions & 2 deletions src/SpotifyConnect/SPOCApiEndpoint.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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]]]]
]

{
Expand Down
32 changes: 9 additions & 23 deletions src/SpotifyConnect/SPOCApp.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Class {
#instVars : [
'auth',
'userLogin',
'searchbar'
'searchbar',
'player'
],
#category : #SpotifyConnect
}
Expand Down Expand Up @@ -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}
]

{
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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 [

Expand All @@ -175,7 +160,8 @@ SPOCApp >> initialize [
self auth: SPOCAuthorizer new;
registerOpenCommand;
setupUserLogin;
setupSearchbar.
setupSearchbar;
setupPlayer.


]
Expand Down Expand Up @@ -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].
]

{
Expand Down
72 changes: 50 additions & 22 deletions src/SpotifyConnect/SPOCPlayer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Class {
#instVars : [
'button',
'deviceID',
'icon'
'icon',
'isPlaying'
],
#category : #SpotifyConnect
}
Expand Down Expand Up @@ -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.
]

{
Expand Down Expand Up @@ -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
]

{
Expand All @@ -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.
]

{
Expand Down Expand Up @@ -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].
]

0 comments on commit 0d4ae91

Please sign in to comment.