From 5178b155680290bfca0f241773c3203f069ce454 Mon Sep 17 00:00:00 2001 From: Vincent Eichhorn Date: Mon, 8 Jul 2024 17:15:14 +0200 Subject: [PATCH] =?UTF-8?q?refacotring=20und=20so=20dinge=20hier,=20ich=20?= =?UTF-8?q?wei=C3=9F=20schon=20nicht=20mehr=20wo=20ich=20=C3=BCberall=20wa?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SpotifyConnect/SPOCApiEndpoint.class.st | 26 +++++-- src/SpotifyConnect/SPOCApiSearch.class.st | 41 ++++++----- src/SpotifyConnect/SPOCApp.class.st | 13 ++-- src/SpotifyConnect/SPOCArtist.class.st | 9 --- .../SPOCAssetImageMorph.class.st | 46 ------------- src/SpotifyConnect/SPOCAuthorizer.class.st | 23 +++++-- src/SpotifyConnect/SPOCBoxedText.class.st | 68 +++++++++++++++---- src/SpotifyConnect/SPOCIcon.class.st | 4 +- src/SpotifyConnect/SPOCImage.class.st | 38 ++++++++--- .../SPOCResultListItem.class.st | 2 +- src/SpotifyConnect/SPOCUserLogin.class.st | 6 +- 11 files changed, 156 insertions(+), 120 deletions(-) delete mode 100644 src/SpotifyConnect/SPOCAssetImageMorph.class.st diff --git a/src/SpotifyConnect/SPOCApiEndpoint.class.st b/src/SpotifyConnect/SPOCApiEndpoint.class.st index 4fafe54..79f8f36 100644 --- a/src/SpotifyConnect/SPOCApiEndpoint.class.st +++ b/src/SpotifyConnect/SPOCApiEndpoint.class.st @@ -21,6 +21,15 @@ SPOCApiEndpoint class >> apiHost [ ^ 'https://api.spotify.com/' ] +{ + #category : #constants, + #'squeak_changestamp' : 'VE 7/8/2024 16:21' +} +SPOCApiEndpoint class >> cannotRefreshErrorMessage [ + + ^ 'Refreshing Access Token failed' +] + { #category : #constants, #'squeak_changestamp' : 'OW 7/7/2024 16:28' @@ -39,6 +48,15 @@ SPOCApiEndpoint class >> mockdataBasepath [ ^ 'assets/mockdata/' ] +{ + #category : #constants, + #'squeak_changestamp' : 'VE 7/8/2024 16:20' +} +SPOCApiEndpoint class >> noAuthorizerErrorMessage [ + + ^ 'Authorizer needed' +] + { #category : #accessing, #'squeak_changestamp' : 'TL 6/10/2024 03:37' @@ -86,7 +104,7 @@ SPOCApiEndpoint >> endpointMethod [ { #category : #'api-call', - #'squeak_changestamp' : 'TL 7/7/2024 02:41' + #'squeak_changestamp' : 'VE 7/8/2024 16:21' } SPOCApiEndpoint >> execute: aParamDictionary [ @@ -94,7 +112,7 @@ SPOCApiEndpoint >> execute: aParamDictionary [ self returnsTestContent ifTrue: [^ self tinkerReponseContent: self executeTest]. self authorizer - ifNil: [^ SPOCApiEndpointResult new error: 'Authorizer needed']. + ifNil: [^ SPOCApiEndpointResult new error: self class noAuthorizerErrorMessage]. response := self executeRequest: self tinkerRequest withParams: aParamDictionary. response code = 401 ifTrue: [^ self refreshAccessTokenAndExecute: aParamDictionary]. @@ -146,14 +164,14 @@ SPOCApiEndpoint >> loadMockdataFromAsset: anAsset [ { #category : #'api-call', - #'squeak_changestamp' : 'TL 7/7/2024 02:45' + #'squeak_changestamp' : 'VE 7/8/2024 16:21' } SPOCApiEndpoint >> refreshAccessTokenAndExecute: aParamDictionary [ self authorizer refreshAccessToken. self authorizer isAuthorized ifTrue: [^ self execute: aParamDictionary] - ifFalse: [^ SPOCApiEndpointResult new error: 'Access Token Refresh Failed'] + ifFalse: [^ SPOCApiEndpointResult new error: self class cannotRefreshErrorMessage] ] { diff --git a/src/SpotifyConnect/SPOCApiSearch.class.st b/src/SpotifyConnect/SPOCApiSearch.class.st index 31355e4..b29bbb7 100644 --- a/src/SpotifyConnect/SPOCApiSearch.class.st +++ b/src/SpotifyConnect/SPOCApiSearch.class.st @@ -8,6 +8,19 @@ Class { #'squeak_changestamp' : 'OW 7/4/2024 12:00' } +{ + #category : #response, + #'squeak_changestamp' : 'VE 7/8/2024 16:44' +} +SPOCApiSearch >> contentItemsAt: aSymbol in: aJsonContent [ + + (aJsonContent includesKey: aSymbol) + ifTrue: [^ (aJsonContent at: aSymbol) at: #items]. + ^ OrderedCollection new + + +] + { #category : #parameters, #'squeak_changestamp' : 'RK 5/16/2024 19:01' @@ -57,27 +70,19 @@ SPOCApiSearch >> search: aString withFilter: aFilter [ { #category : #response, - #'squeak_changestamp' : 'RK 7/7/2024 13:53' + #'squeak_changestamp' : 'VE 7/8/2024 16:43' } SPOCApiSearch >> tinkerReponseContent: aContentStream [ - | content results index | + | content results | content := Json readFrom: aContentStream readStream. results := OrderedCollection new. - index := 0. - (content includesKey: #tracks) - ifTrue: [((content at: #tracks) at: #items) - do: [:aTrack | results add: ((self tinkerTrack: aTrack) offset: index + 1). - index := index + 1]. - ^ results]. - (content includesKey: #albums) - ifTrue: [((content at: #albums) at: #items) - do: [:anAlbum | results add: ((self tinkerAlbum: anAlbum) offset: index + 1). - index := index + 1]. - ^ results]. - (content includesKey: #playlists) - ifTrue: [((content at: #playlists) at: #items) - do: [:aPlaylist | results add: ((self tinkerPlaylist: aPlaylist) offset: index + 1). - index := index + 1]. - ^ results] + (self contentItemsAt: #tracks in: content) + do: [:aTrack | results add: (self tinkerTrack: aTrack)]. + (self contentItemsAt: #albums in: content) + do: [:anAlbum | results add: (self tinkerAlbum: anAlbum)]. + (self contentItemsAt: #playlists in: content) + do: [:aPlaylist | results add: (self tinkerPlaylist: aPlaylist)]. + results withIndexDo: [:aDataPiece :anIndex | aDataPiece offset: anIndex]. + ^ results ] diff --git a/src/SpotifyConnect/SPOCApp.class.st b/src/SpotifyConnect/SPOCApp.class.st index e78329d..05a30cf 100644 --- a/src/SpotifyConnect/SPOCApp.class.st +++ b/src/SpotifyConnect/SPOCApp.class.st @@ -323,16 +323,15 @@ SPOCApp >> logout [ { #category : #ui, - #'squeak_changestamp' : 'VE 6/20/2024 19:00' + #'squeak_changestamp' : 'VE 7/8/2024 16:39' } SPOCApp >> open [ - | a | - a := ToolBuilder open: self. - a color: SPOCStyle spotifyBlack. - a borderColor: SPOCStyle spotifyBlack. - a paneColor: SPOCStyle spotifyBlack. - ^ a + ^ (ToolBuilder open: self) + color: SPOCStyle spotifyBlack; + borderColor: SPOCStyle spotifyBlack; + paneColor: SPOCStyle spotifyBlack; + yourself ] { diff --git a/src/SpotifyConnect/SPOCArtist.class.st b/src/SpotifyConnect/SPOCArtist.class.st index a57dbd0..2b471a2 100644 --- a/src/SpotifyConnect/SPOCArtist.class.st +++ b/src/SpotifyConnect/SPOCArtist.class.st @@ -8,15 +8,6 @@ Class { #'squeak_changestamp' : 'OW 7/4/2024 11:53' } -{ - #category : #actions, - #'squeak_changestamp' : 'RK 6/7/2024 11:19' -} -SPOCArtist >> clickAction [ - - ^ ["To do: show artist page"] -] - { #category : #testing, #'squeak_changestamp' : 'TL 6/12/2024 01:10' diff --git a/src/SpotifyConnect/SPOCAssetImageMorph.class.st b/src/SpotifyConnect/SPOCAssetImageMorph.class.st deleted file mode 100644 index 1f11c05..0000000 --- a/src/SpotifyConnect/SPOCAssetImageMorph.class.st +++ /dev/null @@ -1,46 +0,0 @@ -" -A morph with an image from an asset. -" -Class { - #name : #SPOCAssetImageMorph, - #superclass : #ImageMorph, - #category : #'SpotifyConnect-UI', - #'squeak_changestamp' : 'OW 7/4/2024 12:29' -} - -{ - #category : #constants, - #'squeak_changestamp' : 'TL 5/27/2024 01:31' -} -SPOCAssetImageMorph class >> gitRepoName [ - - ^ 'SpotifyConnect' -] - -{ - #category : #'as yet unclassified', - #'squeak_changestamp' : 'TL 5/27/2024 12:12' -} -SPOCAssetImageMorph >> assetPath: anAssetPath [ - - self image: (self loadAsset: anAssetPath). - self changed -] - -{ - #category : #'as yet unclassified', - #'squeak_changestamp' : 'TL 5/27/2024 12:12' -} -SPOCAssetImageMorph >> loadAsset: anAssetPath [ - - ^ (GitAssetLoader for: self class gitRepoName) loadAsset: anAssetPath -] - -{ - #category : #'as yet unclassified', - #'squeak_changestamp' : 'TL 5/27/2024 01:32' -} -SPOCAssetImageMorph >> magnifyBy: aMagnification [ - - self image: (self form magnifyBy: aMagnification) -] diff --git a/src/SpotifyConnect/SPOCAuthorizer.class.st b/src/SpotifyConnect/SPOCAuthorizer.class.st index 31c231d..cb0d76f 100644 --- a/src/SpotifyConnect/SPOCAuthorizer.class.st +++ b/src/SpotifyConnect/SPOCAuthorizer.class.st @@ -192,6 +192,17 @@ SPOCAuthorizer >> accessToken: aToken [ accessToken := aToken ] +{ + #category : #authorization, + #'squeak_changestamp' : 'VE 7/8/2024 16:17' +} +SPOCAuthorizer >> authorizeByRefresh [ + + self refreshAccessToken. + self isAuthorized + ifTrue: [self callSuccessCallbacks] +] + { #category : #authorization, #'squeak_changestamp' : 'VE 6/4/2024 09:30' @@ -325,7 +336,7 @@ SPOCAuthorizer >> randomState: aState [ { #category : #utilities, - #'squeak_changestamp' : 'TL 7/7/2024 02:19' + #'squeak_changestamp' : 'VE 7/8/2024 16:17' } SPOCAuthorizer >> randomString: aLength [ @@ -333,8 +344,8 @@ SPOCAuthorizer >> randomString: aLength [ chars := Character alphabet asArray. randomString := String new: aLength. 1 to: aLength - do: [:i | index := (1 to: chars size) atRandom. - randomString at: i put: (chars at: index)]. + do: [:anIndex | index := (1 to: chars size) atRandom. + randomString at: anIndex put: (chars at: index)]. ^ randomString ] @@ -452,15 +463,13 @@ SPOCAuthorizer >> spotifyRefreshApiContent [ { #category : #authorization, - #'squeak_changestamp' : 'TL 7/7/2024 02:24' + #'squeak_changestamp' : 'VE 7/8/2024 16:16' } SPOCAuthorizer >> startAuthorization [ | url | self canRefresh - ifTrue: [self refreshAccessToken. - self isAuthorized - ifTrue: [self callSuccessCallbacks]. + ifTrue: [self authorizeByRefresh. ^ self]. self setupCallbackService. url := self buildAuthorizationUrl. diff --git a/src/SpotifyConnect/SPOCBoxedText.class.st b/src/SpotifyConnect/SPOCBoxedText.class.st index f048321..e00565c 100644 --- a/src/SpotifyConnect/SPOCBoxedText.class.st +++ b/src/SpotifyConnect/SPOCBoxedText.class.st @@ -15,11 +15,11 @@ Class { { #category : #constants, - #'squeak_changestamp' : 'TL 6/10/2024 05:10' + #'squeak_changestamp' : 'VE 7/8/2024 17:14' } SPOCBoxedText class >> defaultContent [ - ^ 'SPOCBoxedText' + ^ '' ] { @@ -108,13 +108,14 @@ SPOCBoxedText >> circleMorph [ { #category : #updating, - #'squeak_changestamp' : 'VE 5/27/2024 20:33' + #'squeak_changestamp' : 'VE 7/8/2024 17:14' } SPOCBoxedText >> color: aColor [ + super color: Color transparent. self centerBox color: aColor. self leftBorderCircle color: aColor. - self rightBorderCircle color: aColor. + self rightBorderCircle color: aColor ] { @@ -137,12 +138,12 @@ SPOCBoxedText >> contents [ { #category : #updating, - #'squeak_changestamp' : 'VE 6/10/2024 21:54' + #'squeak_changestamp' : 'VE 7/8/2024 17:14' } SPOCBoxedText >> contents: aString [ self label contents: aString. - self updateAlignments. + self updateAlignments ] { @@ -270,14 +271,57 @@ SPOCBoxedText >> rightBorderCircle [ { #category : #updating, - #'squeak_changestamp' : 'VE 5/27/2024 21:11' + #'squeak_changestamp' : 'VE 7/8/2024 16:49' } SPOCBoxedText >> updateAlignments [ - self extent: (self label width + SPOCBoxedText horizontalSpacing + SPOCBoxedText height @ SPOCBoxedText height). - self centerBox extent: (self label width + SPOCBoxedText horizontalSpacing @ SPOCBoxedText height). - self centerBox position: self topLeft + (SPOCBoxedText height / 2 @ 0). - self label position: self topLeft + (SPOCBoxedText height + SPOCBoxedText horizontalSpacing @ (SPOCBoxedText height - self label height) / 2). - self rightBorderCircle position: self topRight - (SPOCBoxedText height @ 0). + + self updateExtent; + updateCenterBoxExtent; + updateLabelPosition; + updateRightBorderCirclePosition + +] + +{ + #category : #updating, + #'squeak_changestamp' : 'VE 7/8/2024 16:49' +} +SPOCBoxedText >> updateCenterBoxExtent [ + + self centerBox extent: (self label width + self class horizontalSpacing @ self class height). + self centerBox position: self topLeft + (self class height / 2 @ 0) + + +] + +{ + #category : #updating, + #'squeak_changestamp' : 'VE 7/8/2024 16:49' +} +SPOCBoxedText >> updateExtent [ + + self extent: (self label width + self class horizontalSpacing + self class height @ self class height) + +] + +{ + #category : #updating, + #'squeak_changestamp' : 'VE 7/8/2024 16:50' +} +SPOCBoxedText >> updateLabelPosition [ + + self label position: self topLeft + (self class height + self class horizontalSpacing @ (self class height - self label height) / 2) + + +] + +{ + #category : #updating, + #'squeak_changestamp' : 'VE 7/8/2024 16:48' +} +SPOCBoxedText >> updateRightBorderCirclePosition [ + + self rightBorderCircle position: self topRight - (SPOCBoxedText height @ 0) ] diff --git a/src/SpotifyConnect/SPOCIcon.class.st b/src/SpotifyConnect/SPOCIcon.class.st index a778a67..ff124b7 100644 --- a/src/SpotifyConnect/SPOCIcon.class.st +++ b/src/SpotifyConnect/SPOCIcon.class.st @@ -40,11 +40,11 @@ SPOCIcon class >> size [ { #category : #initialization, - #'squeak_changestamp' : 'TL 7/7/2024 01:11' + #'squeak_changestamp' : 'VE 7/8/2024 17:06' } SPOCIcon >> attachButton [ - self icon: SPOCAssetImageMorph new. + self icon: SPOCImage new. self addMorph: self icon. self icon position: (self icon position + 8 asPoint) ] diff --git a/src/SpotifyConnect/SPOCImage.class.st b/src/SpotifyConnect/SPOCImage.class.st index cce5d8f..32eefb1 100644 --- a/src/SpotifyConnect/SPOCImage.class.st +++ b/src/SpotifyConnect/SPOCImage.class.st @@ -7,27 +7,27 @@ Class { #instVars : [ 'url' ], + #classInstVars : [ + 'form' + ], #category : #'SpotifyConnect-UI', #'squeak_changestamp' : 'OW 7/4/2024 12:29' } { #category : #constructor, - #'squeak_changestamp' : 'TL 6/10/2024 05:14' + #'squeak_changestamp' : 'VE 7/8/2024 17:01' } SPOCImage class >> newWithPath: aString [ - | form | - form := (GitAssetLoader for: SPOCStyle gitRepoName) loadForm: aString. - form := form scaledToSize: (SPOCStyle resultListItemHeight - (2 * SPOCStyle defaultMargin)). ^ SPOCImage new - image: form; + image: ((GitAssetLoader for: SPOCStyle gitRepoName) loadForm: aString); yourself ] { #category : #constructor, - #'squeak_changestamp' : 'TL 6/10/2024 05:14' + #'squeak_changestamp' : 'VE 7/8/2024 17:01' } SPOCImage class >> newWithUrl: aString [ @@ -37,6 +37,16 @@ SPOCImage class >> newWithUrl: aString [ yourself ] +{ + #category : #accessing, + #'squeak_changestamp' : 'VE 7/8/2024 17:08' +} +SPOCImage >> assetPath: anAssetPath [ + + self image: ((GitAssetLoader for: SPOCStyle gitRepoName) loadAsset: anAssetPath). + self changed +] + { #category : #testing, #'squeak_changestamp' : 'TL 6/23/2024 16:28' @@ -46,17 +56,23 @@ SPOCImage >> equals: anImage [ ^ (self url = anImage url) ] +{ + #category : #accessing, + #'squeak_changestamp' : 'VE 7/8/2024 17:08' +} +SPOCImage >> magnifyBy: aMagnification [ + + self image: (self form magnifyBy: aMagnification) +] + { #category : #formatting, - #'squeak_changestamp' : 'TL 7/7/2024 00:40' + #'squeak_changestamp' : 'VE 7/8/2024 17:03' } SPOCImage >> scaledTo: aNumber [ - self url - ifNil: [^ self]. ^ SPOCImage new - image: ((Form fromBinaryStream: (HTTPSocket httpGet: self url)) - scaledToSize: aNumber) + image: (self image scaledToSize: aNumber) ] { diff --git a/src/SpotifyConnect/SPOCResultListItem.class.st b/src/SpotifyConnect/SPOCResultListItem.class.st index 654796b..4b963ff 100644 --- a/src/SpotifyConnect/SPOCResultListItem.class.st +++ b/src/SpotifyConnect/SPOCResultListItem.class.st @@ -78,7 +78,7 @@ SPOCResultListItem >> buildCenterBox [ { #category : #building, - #'squeak_changestamp' : 'RK 6/16/2024 14:31' + #'squeak_changestamp' : 'VE 7/8/2024 16:57' } SPOCResultListItem >> buildImage [ diff --git a/src/SpotifyConnect/SPOCUserLogin.class.st b/src/SpotifyConnect/SPOCUserLogin.class.st index d1f23f8..890a98f 100644 --- a/src/SpotifyConnect/SPOCUserLogin.class.st +++ b/src/SpotifyConnect/SPOCUserLogin.class.st @@ -15,11 +15,11 @@ Class { { #category : #initialization, - #'squeak_changestamp' : 'TL 6/10/2024 04:32' + #'squeak_changestamp' : 'VE 7/8/2024 17:14' } SPOCUserLogin >> attachButton [ - self text: (SPOCBoxedText new contents: ''; yourself); + self text: (SPOCBoxedText new); button: (SPOCClickable newUsing: self text onClick: [:anEvent | self app auth startAuthorization]); addMorph: self button ] @@ -53,7 +53,7 @@ SPOCUserLogin >> buttonLabel [ { #category : #accessing, - #'squeak_changestamp' : 'TL 6/10/2024 04:33' + #'squeak_changestamp' : 'VE 7/8/2024 17:13' } SPOCUserLogin >> buttonLabel: aString [