From 62197b8f1ce3c148de09c311498d53db6876e874 Mon Sep 17 00:00:00 2001 From: Foti Dim Date: Sat, 5 Oct 2024 20:38:54 +0200 Subject: [PATCH] Remove isSpotifyAppActive (#222) * Bump iOS SDK to v3.0.0 * Update changelog * Bump example app iOS version to 12 * Remove duplicate checkout * Remove isActive from Android * Remove isActive from iOS * Update gradle * update gradle properties * update example --------- Co-authored-by: Tobias Busch --- CHANGELOG.md | 6 +- README.md | 1 - android/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 5 +- .../minimalme/spotify_sdk/SpotifyPlayerApi.kt | 14 --- .../minimalme/spotify_sdk/SpotifySdkPlugin.kt | 2 - .../gradle/wrapper/gradle-wrapper.properties | 2 +- example/android/settings.gradle | 2 +- example/ios/Flutter/AppFrameworkInfo.plist | 2 +- example/ios/Runner.xcodeproj/project.pbxproj | 14 +-- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- example/ios/Runner/AppDelegate.swift | 2 +- example/lib/main.dart | 89 ++++++------------- ios/Classes/SpotifySdkConstants.swift | 1 - ios/Classes/SwiftSpotifySdkPlugin.swift | 4 - ios/prepare-iOS-SDK.sh | 2 +- lib/platform_channels.dart | 3 - lib/spotify_sdk.dart | 16 ---- 18 files changed, 48 insertions(+), 121 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31f6006e..f494da34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.0.1 +* **BREAKING**: `isSpotifyAppActive` is removed from iOS and Android (#222) and therefore removed from the sdk +* chore: Bump native iOS SDK to 3.0.0 (#222) + ## 3.0.0 * All changes from dev builds * chore: Bump native iOS SDK to 1.2.4 (#208) @@ -13,7 +17,7 @@ * Feat: add set podcastPlaybackSpeed and switchToLocalDevice for android (#160) ## 3.0.0-dev.1 -* **BREAKINg**:feat: update spotify.android:auth from 1.2.6 to 2.1.0 and spotify.app.remote from 0.7.2 to 0.8.0 +* **BREAKING**:feat: update spotify.android:auth from 1.2.6 to 2.1.0 and spotify.app.remote from 0.7.2 to 0.8.0 In the app/build.gradle add the following to the default config for auth to work as described [here](https://github.com/spotify/android-auth#integrating-the-library-into-your-project) ```groovy defaultConfig { diff --git a/README.md b/README.md index 771b5609..865b6e4b 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,6 @@ Token Swap is for now "web only". While the iOS SDK also supports the "token swa | connectToSpotifyRemote | Connects the App to Spotify | ✔ | ✔ | ✔ | | getAccessToken | Gets the Access Token that you can use to work with the [Web Api](https://developer.spotify.com/documentation/web-api/) | ✔ | ✔ | ✔ | | disconnect | Disconnects the app connection | ✔ | ✔ | ✔ | -| isSpotifyAppActive | Checks if the Spotify app is active. The Spotify app will be considered active if music is playing. | ✔ | ✔ | 🚧 | | subscribeConnectionStatus | Subscribes to the current player state. | ✔ | ✔ | 🚧 | #### Player Api diff --git a/android/build.gradle b/android/build.gradle index d211de87..12b4dd18 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -10,7 +10,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:8.1.0' + classpath 'com.android.tools.build:gradle:8.1.4' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index c7631367..dedd5d1e 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ -#Thu Mar 05 21:24:22 CET 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip diff --git a/android/src/main/kotlin/de/minimalme/spotify_sdk/SpotifyPlayerApi.kt b/android/src/main/kotlin/de/minimalme/spotify_sdk/SpotifyPlayerApi.kt index 9f434d8d..f3378b15 100644 --- a/android/src/main/kotlin/de/minimalme/spotify_sdk/SpotifyPlayerApi.kt +++ b/android/src/main/kotlin/de/minimalme/spotify_sdk/SpotifyPlayerApi.kt @@ -21,7 +21,6 @@ class SpotifyPlayerApi(spotifyAppRemote: SpotifyAppRemote?, result: MethodChanne private val errorPodcastPlaybackSpeed = "podcastPlaybackSpeedError" private val errorToggleShuffle = "toggleShuffleError" private val errorToggleRepeat = "toggleRepeatError" - private val errorIsSpotifyAppActive = "isSpotifyAppActiveError" private val playerApi = spotifyAppRemote?.playerApi @@ -208,17 +207,4 @@ class SpotifyPlayerApi(spotifyAppRemote: SpotifyAppRemote?, result: MethodChanne spotifyRemoteAppNotSetError() } } - - internal fun isSpotifyAppActive() { - if (playerApi != null) { - - playerApi.playerState - .setResultCallback { playerState -> result.success(!playerState.isPaused && playerState.playbackSpeed > 0)} - .setErrorCallback { - throwable -> result.error(errorIsSpotifyAppActive, "error when getting if spotify app is currently active/playing", throwable.toString()) - } - } else { - spotifyRemoteAppNotSetError() - } - } } diff --git a/android/src/main/kotlin/de/minimalme/spotify_sdk/SpotifySdkPlugin.kt b/android/src/main/kotlin/de/minimalme/spotify_sdk/SpotifySdkPlugin.kt index cd83605d..4b5dfd3e 100644 --- a/android/src/main/kotlin/de/minimalme/spotify_sdk/SpotifySdkPlugin.kt +++ b/android/src/main/kotlin/de/minimalme/spotify_sdk/SpotifySdkPlugin.kt @@ -85,7 +85,6 @@ class SpotifySdkPlugin : MethodCallHandler, FlutterPlugin, ActivityAware, Plugin private val methodToggleShuffle = "toggleShuffle" private val methodSetShuffle = "setShuffle" private val methodSetRepeatMode = "setRepeatMode" - private val methodIsSpotifyAppActive = "isSpotifyAppActive" //userApi private val methodAddToLibrary = "addToLibrary" @@ -199,7 +198,6 @@ class SpotifySdkPlugin : MethodCallHandler, FlutterPlugin, ActivityAware, Plugin methodSetShuffle -> spotifyPlayerApi?.setShuffle(call.argument(paramShuffle)) methodToggleRepeat -> spotifyPlayerApi?.toggleRepeat() methodSetRepeatMode -> spotifyPlayerApi?.setRepeatMode(call.argument(paramRepeatMode)) - methodIsSpotifyAppActive -> spotifyPlayerApi?.isSpotifyAppActive() //userApi calls methodAddToLibrary -> spotifyUserApi?.addToUserLibrary(call.argument(paramSpotifyUri)) methodRemoveFromLibrary -> spotifyUserApi?.removeFromUserLibrary(call.argument(paramSpotifyUri)) diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index d11cdd90..dedd5d1e 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 01199495..108f7687 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -18,7 +18,7 @@ pluginManagement { plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" - id "com.android.application" version '8.1.0' apply false + id "com.android.application" version '8.7.0' apply false id "org.jetbrains.kotlin.android" version "1.8.22" apply false } diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist index 4f8d4d24..8c6e5614 100644 --- a/example/ios/Flutter/AppFrameworkInfo.plist +++ b/example/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 11.0 + 12.0 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 14e3e62f..5626fc35 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -141,7 +141,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1430; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = ""; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -328,7 +328,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -351,7 +351,7 @@ "$(PROJECT_DIR)/Flutter", ); INFOPLIST_FILE = Runner/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -415,7 +415,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -464,7 +464,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -489,7 +489,7 @@ "$(PROJECT_DIR)/Flutter", ); INFOPLIST_FILE = Runner/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -521,7 +521,7 @@ "$(PROJECT_DIR)/Flutter", ); INFOPLIST_FILE = Runner/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index b52b2e69..e67b2808 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ { Widget _buildBottomBar(BuildContext context) { return BottomAppBar( - height: 125, - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - SizedIconButton( - width: 50, - icon: Icons.queue_music, - onPressed: queue, - ), - SizedIconButton( - width: 50, - icon: Icons.playlist_play, - onPressed: play, - ), - SizedIconButton( - width: 50, - icon: Icons.repeat, - onPressed: toggleRepeat, - ), - SizedIconButton( - width: 50, - icon: Icons.shuffle, - onPressed: toggleShuffle, - ), - ], + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + SizedIconButton( + width: 50, + icon: Icons.queue_music, + onPressed: queue, ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - SizedIconButton( - width: 50, - onPressed: addToLibrary, - icon: Icons.favorite, - ), - SizedIconButton( - width: 50, - onPressed: () => checkIfAppIsActive(context), - icon: Icons.info, - ), - ], + SizedIconButton( + width: 50, + icon: Icons.playlist_play, + onPressed: play, + ), + SizedIconButton( + width: 50, + icon: Icons.repeat, + onPressed: toggleRepeat, + ), + SizedIconButton( + width: 50, + icon: Icons.shuffle, + onPressed: toggleShuffle, + ), + SizedIconButton( + width: 50, + onPressed: addToLibrary, + icon: Icons.favorite, ), ], ), @@ -764,27 +748,6 @@ class HomeState extends State { } } - Future checkIfAppIsActive(BuildContext context) async { - try { - final isActive = await SpotifySdk.isSpotifyAppActive; - _showSnackBar(isActive); - } on PlatformException catch (e) { - setStatus(e.code, message: e.message); - } on MissingPluginException { - setStatus('not implemented'); - } - } - - void _showSnackBar(bool isActive) { - final snackBar = SnackBar( - content: Text(isActive - ? 'Spotify app connection is active (currently playing)' - : 'Spotify app connection is not active (currently not playing)'), - ); - - ScaffoldMessenger.of(context).showSnackBar(snackBar); - } - void setStatus(String code, {String? message}) { var text = message ?? ''; _logger.i('$code$text'); diff --git a/ios/Classes/SpotifySdkConstants.swift b/ios/Classes/SpotifySdkConstants.swift index 1b524f38..ec5550cd 100644 --- a/ios/Classes/SpotifySdkConstants.swift +++ b/ios/Classes/SpotifySdkConstants.swift @@ -6,7 +6,6 @@ public class SpotifySdkConstants public static let methodConnectToSpotify = "connectToSpotify" public static let methodGetAccessToken = "getAccessToken" public static let methodDisconnectFromSpotify = "disconnectFromSpotify" - public static let methodCheckIfSpotifyAppIsActive = "isSpotifyAppActive" //player api public static let methodQueueTrack = "queueTrack" diff --git a/ios/Classes/SwiftSpotifySdkPlugin.swift b/ios/Classes/SwiftSpotifySdkPlugin.swift index bec26276..7580f0be 100644 --- a/ios/Classes/SwiftSpotifySdkPlugin.swift +++ b/ios/Classes/SwiftSpotifySdkPlugin.swift @@ -306,10 +306,6 @@ public class SwiftSpotifySdkPlugin: NSObject, FlutterPlugin { return } appRemote.playerAPI?.setRepeatMode(repeatMode, callback: defaultPlayAPICallback) - case SpotifySdkConstants.methodCheckIfSpotifyAppIsActive: - SPTAppRemote.checkIfSpotifyAppIsActive { isActive in - result(isActive) - } case SpotifySdkConstants.getLibraryState: guard let appRemote = appRemote else { result(FlutterError(code: "Connection Error", message: "AppRemote is null", details: nil)) diff --git a/ios/prepare-iOS-SDK.sh b/ios/prepare-iOS-SDK.sh index db3a0cd5..7f66afd4 100755 --- a/ios/prepare-iOS-SDK.sh +++ b/ios/prepare-iOS-SDK.sh @@ -6,5 +6,5 @@ FRAMEWORK_NAME="SpotifyiOS.xcframework" rm -fR ${REPO_NAME} mkdir ${REPO_NAME} git clone https://github.com/spotify/${REPO_NAME} -git -C ${REPO_NAME} checkout checkout tags/v2.1.7 +git -C ${REPO_NAME} checkout tags/v3.0.0 find ./${REPO_NAME} -mindepth 1 -maxdepth 1 -not -name ${FRAMEWORK_NAME} -exec rm -rf '{}' \; # Keep on only the xcframework folder diff --git a/lib/platform_channels.dart b/lib/platform_channels.dart index 6b8c77a9..419dc6ad 100644 --- a/lib/platform_channels.dart +++ b/lib/platform_channels.dart @@ -33,9 +33,6 @@ class MethodNames { /// method name for [disconnectFromSpotify] static const String disconnectFromSpotify = 'disconnectFromSpotify'; - /// method name for [isSpotifyAppActive] - static const String isSpotifyAppActive = 'isSpotifyAppActive'; - /// method name for [getCrossfadeState] static const String getCrossfadeState = 'getCrossfadeState'; diff --git a/lib/spotify_sdk.dart b/lib/spotify_sdk.dart index 82364a33..af1a2b6a 100644 --- a/lib/spotify_sdk.dart +++ b/lib/spotify_sdk.dart @@ -162,22 +162,6 @@ class SpotifySdk { } } - /// Checks if the Spotify app is active on the user's device. You can use this to determine if maybe you should prompt - /// the user to connect to Spotify (because you know they are already using Spotify if it is active). The Spotify app - /// will be considered active if music is playing. - /// Returns true if Spotify is active, otherwise false. - /// - /// Throws a [MissingPluginException] if the method is not implemented on - /// the native platforms. - static Future get isSpotifyAppActive async { - try { - return await _channel.invokeMethod(MethodNames.isSpotifyAppActive); - } on Exception catch (e) { - _logException(MethodNames.isSpotifyAppActive, e); - rethrow; - } - } - /// Gets the current [CrossfadeState] /// /// Throws a [PlatformException] getting the crossfadeState failed