Skip to content

Commit

Permalink
Chore!: update spotify packages (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
brim-borium authored Aug 12, 2023
1 parent 54d1258 commit 856a905
Show file tree
Hide file tree
Showing 20 changed files with 151 additions and 67 deletions.
16 changes: 16 additions & 0 deletions .github/scripts/verify_pub_score.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# Runs `pana . --no-warning` and verifies that the package score
# is greater or equal to the desired score. By default the desired score is
# a perfect score but it can be overridden by passing the desired score as an argument.
#
# Ensure the package has a score of at least a 100
# `./verify_pub_score.sh 100`
#
# Ensure the package has a perfect score
# `./verify_pub_score.sh`

PANA=$(pana . --no-warning); PANA_SCORE=$(echo $PANA | sed -n "s/.*Points: \([0-9]*\)\/\([0-9]*\)./\1\/\2/p")
echo "score: $PANA_SCORE"
IFS='/'; read -a SCORE_ARR <<< "$PANA_SCORE"; SCORE=SCORE_ARR[0]; TOTAL=SCORE_ARR[1]
if [ -z "$1" ]; then MINIMUM_SCORE=TOTAL; else MINIMUM_SCORE=$1; fi
if (( $SCORE < $MINIMUM_SCORE )); then echo "minimum score $MINIMUM_SCORE was not met!"; exit 1; fi
15 changes: 15 additions & 0 deletions .github/workflows/spotify_sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,18 @@ jobs:
run: |
cd example
flutter build web
pana:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2

- name: Install Dependencies
run: |
flutter packages get
flutter pub global activate pana
sudo apt-get install webp
- name: Verify Pub Score
run: ./.github/scripts/verify_pub_score.sh
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 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
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 {
manifestPlaceholders = [redirectSchemeName: "spotify-sdk", redirectHostName: "auth"]
...
}
```

## 2.3.1
* Fix: null album when getting advertisement on android (#179)
* Fix: queue endpoint for web (#167)
Expand Down
43 changes: 24 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
# spotify_sdk

[![pub package](https://img.shields.io/badge/pub-2.3.1-orange)](https://pub.dev/packages/spotify_sdk)
[![stars](https://img.shields.io/github/stars/brim-borium/spotify_sdk?color=deeppink)](https://github.com/brim-borium/spotify_sdk)
[![build](https://img.shields.io/github/actions/workflow/status/brim-borium/spotify_sdk/spotify_sdk.yml)](https://github.com/brim-borium/spotify_sdk/actions?query=workflow%3Aspotify_sdk)
[![licence](https://img.shields.io/github/license/brim-borium/spotify_sdk?color=blue)](https://github.com/brim-borium/spotify_sdk/blob/main/LICENSE)
<p align="center">
<a href="https://pub.dev/packages/spotify_sdk"><img src="https://img.shields.io/badge/pub-3.0.0-dev.1-orange" alt="build"></a>
<a href="https://github.com/brim-borium/spotify_sdk"><img src="https://img.shields.io/github/stars/brim-borium/spotify_sdk?color=deeppink" alt="build"></a>
<a href="https://github.com/brim-borium/spotify_sdk/actions?query=workflow%3Aspotify_sdk"><img src="https://img.shields.io/github/actions/workflow/status/brim-borium/spotify_sdk/spotify_sdk.yml" alt="build"></a>
<a href="https://github.com/brim-borium/spotify_sdk/blob/main/LICENSE"><img src="https://img.shields.io/github/license/brim-borium/spotify_sdk?color=blue" alt="build"></a>
</p>

![Screenshot](screenshots/flutter_spotify_sdk_screenshot_1.png)
![Screenshot](screenshots/flutter_spotify_sdk_screenshot_2.png)
---

## Description

This is a flutter package that wraps the native [iOS](https://github.com/spotify/ios-sdk) and [Android](https://github.com/spotify/android-sdk) Spotify "remote" SDKs as well as the [Spotify Web Playback SDK](https://developer.spotify.com/documentation/web-playback-sdk/) for web. Since it wraps the native SDKs it has the same features and limitations.

## Installation

To use this plugin, add `spotify_sdk` as a [dependency](https://flutter.io/using-packages/) in your `pubspec.yaml` file like this

```yaml
dependencies:
spotify_sdk:
```
This will get you the latest version.
## Setup

### Android
Expand All @@ -44,15 +35,27 @@ Since Android Studio 4.2 you need to manually perform these steps in order to ad
![image](https://user-images.githubusercontent.com/42183561/125422846-24e03bf0-ec7f-409f-b382-0ef2d0213d08.png)

3. Content of the `spotify-app-remote/build.gradle` file:
```

```groovy
configurations.maybeCreate("default")
artifacts.add("default", file('spotify-app-remote-release-x.x.x.aar'))
```

4. In the android root folder find `settings.gradle` file, open it and add the following line at the top of the file:
```

```groovy
include ':spotify-app-remote'
```

5. In the app/build.gradle add the following to the default config

```groovy
defaultConfig {
manifestPlaceholders = [redirectSchemeName: "spotify-sdk", redirectHostName: "auth"]
...
}
```

### iOS

Register your app in the [spotify developer portal](https://developer.spotify.com/dashboard/). You also need to register your Bundle ID as well as a Redirect URI.
Expand Down Expand Up @@ -112,7 +115,7 @@ If you want to use the web api as well you have to use this method to get the ac
You can specify multiple scopes by separating them with a comma "," as shown below. For more information on scopes you can refer to [Spotify Authorization Scopes Guide](https://developer.spotify.com/documentation/general/guides/authorization/scopes/)

```dart
var accessToken = await SpotifySdk.getAccessToken(clientId: "", redirectUrl: "", scope: "app-remote-control,user-modify-playback-state,playlist-read-private");
final accessToken = await SpotifySdk.getAccessToken(clientId: "", redirectUrl: "", scope: "app-remote-control,user-modify-playback-state,playlist-read-private");
```

On Web you can use the token that you get from `getAccessToken(...)` and then pass it to `connectToSpotifyRemote(...)`. This will avoid having to send user through two Spotify OAuth prompts. You should not persist this token, nor supply a different token, because the refresh token is only set interally by `getAccessToken` or `connectToSpotifyRemote`.
Expand Down Expand Up @@ -217,3 +220,5 @@ On Web, an automatic call to play may not work due to media activation policies
- [Auth](https://spotify.github.io/android-sdk/auth-lib/docs/index.html)
- [App Remote](https://spotify.github.io/android-sdk/app-remote-lib/docs/index.html)
- [Web Playback SDK](https://developer.spotify.com/documentation/web-playback-sdk/)


10 changes: 5 additions & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ group 'de.minimalme.spotify_sdk'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.8.22'
repositories {
google()
mavenCentral()
Expand All @@ -27,13 +27,13 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 30
compileSdk 33

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
minSdkVersion 16
minSdkVersion 21
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
Expand All @@ -44,9 +44,9 @@ android {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// -- spotify
implementation "com.spotify.android:auth:1.2.6"
implementation "com.spotify.android:auth:2.1.0"
implementation project(':spotify-app-remote')
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.google.code.gson:gson:2.10'
// -- events
implementation "com.github.stuhlmeier:kotlin-events:v2.0"
}
29 changes: 29 additions & 0 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at
# https://dart-lang.github.io/linter/lints/index.html.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
11 changes: 6 additions & 5 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 32
compileSdk 33

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -35,11 +35,12 @@ android {

defaultConfig {
applicationId "de.minimalme.spotify_sdk_example"
minSdkVersion 16
targetSdkVersion 32
minSdkVersion 21
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
manifestPlaceholders = [redirectSchemeName: "spotify-sdk", redirectHostName: "auth"]
}

buildTypes {
Expand All @@ -61,6 +62,6 @@ flutter {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test:runner:1.5.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
6 changes: 3 additions & 3 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.8.22'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.0'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
2 changes: 1 addition & 1 deletion example/android/spotify-app-remote/build.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configurations.maybeCreate("default")
artifacts.add("default", file('spotify-app-remote-release-0.7.2.aar'))
artifacts.add("default", file('spotify-app-remote-release-0.8.0.aar'))
Binary file not shown.
Binary file not shown.
17 changes: 9 additions & 8 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);

@override
_HomeState createState() => _HomeState();
HomeState createState() => HomeState();
}

class _HomeState extends State<Home> {
class HomeState extends State<Home> {
bool _loading = false;
bool _connected = false;
final Logger _logger = Logger(
Expand Down Expand Up @@ -625,13 +625,14 @@ class _HomeState extends State<Home> {

Future<void> checkIfAppIsActive(BuildContext context) async {
try {
var isActive = await SpotifySdk.isSpotifyAppActive;
final snackBar = SnackBar(
content: Text(isActive
? 'Spotify app connection is active (currently playing)'
: 'Spotify app connection is not active (currently not playing)'));
await SpotifySdk.isSpotifyAppActive.then((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);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
});
} on PlatformException catch (e) {
setStatus(e.code, message: e.message);
} on MissingPluginException {
Expand Down
19 changes: 12 additions & 7 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,26 @@ description: Demonstrates how to use the spotify_sdk plugin.
publish_to: 'none'

environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=3.0.6 <4.0.0"

dependencies:
flutter:
sdk: flutter
logger: ^1.1.0
flutter_dotenv: ^5.0.2
cupertino_icons: ^1.0.4
logger: ^2.0.1
flutter_dotenv: ^5.1.0
cupertino_icons: ^1.0.5
spotify_sdk:
# When depending on this package from a real application you should use:
# spotify_sdk: ^x.y.z
# See https://dart.dev/tools/pub/dependencies#version-constraints
# The example app is bundled with the plugin so we use a path dependency on
# the parent directory to use the current plugin's version.
path: ../

dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^1.0.4
spotify_sdk:
path: ../
flutter_lints: ^2.0.2

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
Expand Down
2 changes: 1 addition & 1 deletion lib/models/player_options.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions lib/spotify_sdk_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ class SpotifySdkPlugin {
try {
var res = await _authDio.fetch(req);
authResponse = res.data;
} on DioError catch (e) {
} on DioException catch (e) {
log('Spotify auth error: ${e.response?.data}');
rethrow;
}
Expand Down Expand Up @@ -578,7 +578,7 @@ class SpotifySdkPlugin {
var d = res.data;
d['refresh_token'] = refreshToken;
return d;
} on DioError catch (e) {
} on DioException catch (e) {
log('Token refresh error: ${e.response?.data}');
rethrow;
}
Expand All @@ -605,10 +605,10 @@ class SpotifySdkPlugin {

/// Creates a cryptographically random string.
String _createRandomString(int length) {
const _chars =
const chars =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~';
return List.generate(
128, (i) => _chars[math.Random.secure().nextInt(_chars.length)]).join();
128, (i) => chars[math.Random.secure().nextInt(chars.length)]).join();
}

/// Starts track playback on the device.
Expand Down
Loading

0 comments on commit 856a905

Please sign in to comment.