Skip to content

Commit

Permalink
upgrades to 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
brim-borium committed Jul 8, 2020
1 parent b102c7b commit cf7ed9c
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 184 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.5.0
* adds support for web (thanks [itsMatoosh](https://github.com/itsMatoosh))
* adds custom scopes for the web api (thanks [arnav-sh](https://github.com/arnav-sh))
* adds logout functionality for android
* moved from [pedantic](https://pub.dev/packages/pedantic) to [lint](https://pub.dev/packages/lint) for static analyses
* some minor bug fixing

## 0.3.4

* adds handling of unexpected disconnects from Spotify via subscribeConnectionStatus()-Stream(thanks [itsMatoosh](https://github.com/itsMatoosh))
Expand Down
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# spotify_sdk

[![pub package](https://img.shields.io/badge/pub-0.3.4-orange)](https://pub.dev/packages/spotify_sdk)
[![pub package](https://img.shields.io/badge/pub-0.5.0-orange)](https://pub.dev/packages/spotify_sdk)
[![Dry Run](https://github.com/brim-borium/spotify_sdk/workflows/Dry%20Run/badge.svg?branch=develop)](https://github.com/brim-borium/spotify_sdk/actions?query=workflow%3A%22Dry+Run%22)
[![licence](https://img.shields.io/badge/licence-MIT-blue.svg)](https://github.com/IamTobi/spotify_sdk/blob/master/LICENSE)

Expand Down Expand Up @@ -70,19 +70,17 @@ Important here is the naming so that the package can find the modules.
To start using this package you first have to connect to Spotify. To only connect you can do this with connectToSpotifyRemote(...) or getAuthenticationToken(...) in both of these methods you need the client id, given in the spotify dashboard and the redirect url you set in the settings on the dashboard.

```dart
await SpotifySdk.connectToSpotifyRemote(clientId: "", redirectUrl: "")
await SpotifySdk.connectToSpotifyRemote(clientId: "", redirectUrl: "")
```

If you want to use the web api as well you have to use this method to get the authentication token.
You can specify multiple scopes by seperating 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/scopes/)
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/scopes/)

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

tbd...

Have a look [here](example/lib/main.dart) for a more detailed example.
Have a look [in the example](example/lib/main.dart) for detailed insights on how you can use this package.

### Api

Expand All @@ -92,7 +90,7 @@ Have a look [here](example/lib/main.dart) for a more detailed example.
|---|---|---|---|---|
| connectToSpotifyRemote | Connects the App to Spotify | :heavy_check_mark: | :construction_worker: | :heavy_check_mark: |
| getAuthenticationToken | Gets the Authentication Token that you can use to work with the [Web Api](https://developer.spotify.com/documentation/web-api/) |:heavy_check_mark: | :construction_worker: | :heavy_check_mark: |
| logout | logs the user out and disconnects the app connection |:construction_worker: | :construction_worker: | :heavy_check_mark: |
| logout | logs the user out and disconnects the app connection |:heavy_check_mark: | :construction_worker: | :heavy_check_mark: |

#### Player Api

Expand Down
16 changes: 8 additions & 8 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
include: package:pedantic/analysis_options.yaml
include: package:lint/analysis_options_package.yaml

linter:
rules:
# ------ Disable individual rules ----- #
# --- #
# Turn off what you don't like. #
# ------------------------------------- #
rules:
# ------ Disable individual rules ----- #
# --- #
# Turn off what you don't like. #
# ------------------------------------- #

analyzer:
exclude:
exclude:
# Ignore generated files
- '**/*.g.dart'
- 'lib/src/generated/*.dart'
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.spotify.android.appremote.api.ConnectionParams
import com.spotify.android.appremote.api.Connector.ConnectionListener
import com.spotify.android.appremote.api.SpotifyAppRemote
import com.spotify.android.appremote.api.error.*
import com.spotify.protocol.client.Subscription
import com.spotify.sdk.android.auth.AuthorizationClient
import com.spotify.sdk.android.auth.AuthorizationRequest
import com.spotify.sdk.android.auth.AuthorizationResponse
Expand All @@ -20,7 +19,6 @@ import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.Registrar
import kotlinx.event.SetEvent
import kotlinx.event.event
import java.nio.channels.Channel


class SpotifySdkPlugin(private val registrar: Registrar) : MethodCallHandler, PluginRegistry.ActivityResultListener {
Expand Down Expand Up @@ -164,7 +162,7 @@ class SpotifySdkPlugin(private val registrar: Registrar) : MethodCallHandler, Pl
.build()
var replySubmitted = false
SpotifyAppRemote.disconnect(spotifyAppRemote)
var initiallyConnected = false;
var initiallyConnected = false
SpotifyAppRemote.connect(registrar.context(), connectionParams,
object : ConnectionListener {
override fun onConnected(spotifyAppRemoteValue: SpotifyAppRemote) {
Expand All @@ -174,7 +172,7 @@ class SpotifySdkPlugin(private val registrar: Registrar) : MethodCallHandler, Pl
capabilitiesChannel.setStreamHandler(CapabilitiesChannel(spotifyAppRemote!!.userApi))
userStatusChannel.setStreamHandler(UserStatusChannel(spotifyAppRemote!!.userApi))

initiallyConnected = true;
initiallyConnected = true
// emit connection established event
connStatusEventChannel(ConnectionStatusChannel.ConnectionEvent(true, "Successfully connected to Spotify.", null, null))
// method success
Expand All @@ -185,8 +183,8 @@ class SpotifySdkPlugin(private val registrar: Registrar) : MethodCallHandler, Pl
override fun onFailure(throwable: Throwable) {
val errorDetails = throwable.toString()
// determine the error
var errorMessage: String
var errorCode: String
val errorMessage: String
val errorCode: String
var connected = false
when (throwable) {
is SpotifyDisconnectedException, is SpotifyConnectionTerminatedException -> {
Expand Down Expand Up @@ -238,12 +236,12 @@ class SpotifySdkPlugin(private val registrar: Registrar) : MethodCallHandler, Pl
}
Log.e("SPOTIFY_SDK", errorMessage)
// notify plugin
if (initiallyConnected == true) {
if (initiallyConnected) {
// emit connection error event
connStatusEventChannel(ConnectionStatusChannel.ConnectionEvent(connected, errorMessage, errorCode, errorDetails))
} else {
// throw exception as the connect method
result.error(errorCode, errorMessage, errorDetails);
result.error(errorCode, errorMessage, errorDetails)
}
}
})
Expand Down Expand Up @@ -271,18 +269,21 @@ class SpotifySdkPlugin(private val registrar: Registrar) : MethodCallHandler, Pl
}

private fun logoutFromSpotify(result: Result) {
if (spotifyAppRemote != null) {
if (spotifyAppRemote != null && spotifyAppRemote!!.isConnected) {
SpotifyAppRemote.disconnect(spotifyAppRemote)

// emit connection terminated event
connStatusEventChannel(ConnectionStatusChannel.ConnectionEvent(false, "Successfully disconnected from Spotify.", null, null))
// method success
result.success(true)
} else {
}
else if (!spotifyAppRemote!!.isConnected){
result.error(errorDisconnecting, "could not disconnect spotify remote", "you are not connected, no need to disconnect")
}
else {
result.error(errorDisconnecting, "could not disconnect spotify remote", "spotifyAppRemote is not set")
}
}
//--

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?): Boolean {
if (pendingOperation == null) {
Expand Down
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.android.tools.build:gradle:4.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
4 changes: 2 additions & 2 deletions example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Mar 04 15:55:14 CET 2020
#Wed Jul 08 17:57:20 CEST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
Loading

0 comments on commit cf7ed9c

Please sign in to comment.