├── .gitignore
├── .idea
├── caches
│ ├── build_file_checksums.ser
│ └── gradle_models.ser
├── codeStyles
│ └── Project.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── .project
├── .settings
└── org.eclipse.buildship.core.prefs
├── LICENSE
├── README.md
├── app
├── .classpath
├── .gitignore
├── .project
├── .settings
│ └── org.eclipse.buildship.core.prefs
├── build.gradle
├── libs
│ ├── spotify-android-auth-1.0.0.aar
│ ├── spotify-player-24-noconnect-2.20b.aar
│ └── spotify-web-api-android-0.4.1.aar
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── sodastudio
│ │ └── jun
│ │ └── spotify_demo
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── sodastudio
│ │ │ └── jun
│ │ │ └── spotify_demo
│ │ │ ├── MainActivity.java
│ │ │ ├── SplashActivity.java
│ │ │ ├── SpotifyLoginActivity.java
│ │ │ ├── TrackDetailActivity.java
│ │ │ ├── manager
│ │ │ ├── ListManager.java
│ │ │ ├── PlaybackManager.java
│ │ │ └── SearchPager.java
│ │ │ ├── model
│ │ │ ├── AlbumNew.java
│ │ │ ├── ArtistSearch.java
│ │ │ ├── Music.java
│ │ │ ├── SimplePlaylist.java
│ │ │ ├── TopArtist.java
│ │ │ └── TopTrack.java
│ │ │ └── ui
│ │ │ ├── BrowseFragment.java
│ │ │ ├── HomeFragment.java
│ │ │ ├── LibraryFragment.java
│ │ │ ├── MainFragment.java
│ │ │ ├── RadioFragment.java
│ │ │ ├── SearchFragment.java
│ │ │ └── SearchResultFragment.java
│ └── res
│ │ ├── anim
│ │ ├── alpha.xml
│ │ ├── fragment_slide_left_enter.xml
│ │ ├── fragment_slide_right_exit.xml
│ │ ├── hold.xml
│ │ ├── nav_click.xml
│ │ ├── pull_up_from_bottom.xml
│ │ ├── push_out_to_bottom.xml
│ │ └── translate.xml
│ │ ├── drawable-v24
│ │ ├── ic_home_white_24dp.xml
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── create_account_button.xml
│ │ ├── create_account_normal.xml
│ │ ├── create_account_pressed.xml
│ │ ├── follow_rect.xml
│ │ ├── ic_add_black_24dp.xml
│ │ ├── ic_arrow_back_black_24dp.xml
│ │ ├── ic_arrow_back_white_24dp.xml
│ │ ├── ic_close_black_24dp.xml
│ │ ├── ic_file_upload_black_24dp.xml
│ │ ├── ic_home_black_24dp.xml
│ │ ├── ic_launcher_background.xml
│ │ ├── ic_library_music_black_24dp.xml
│ │ ├── ic_more_horiz_black_24dp.xml
│ │ ├── ic_open_in_browser_black_24dp.xml
│ │ ├── ic_playlist_add_black_24dp.xml
│ │ ├── ic_radio_black_24dp.xml
│ │ ├── ic_search_black_24dp.xml
│ │ ├── ic_surround_sound_black_24dp.xml
│ │ ├── login_button.xml
│ │ ├── login_normal.xml
│ │ ├── login_pressed.xml
│ │ ├── main_logo_white.png
│ │ ├── maroon_sample_album.jpeg
│ │ ├── round_rect.xml
│ │ └── sodastudio_logo.png
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── activity_splashscreen.xml
│ │ ├── activity_spotify_login.xml
│ │ ├── activity_track_detail.xml
│ │ ├── album_view.xml
│ │ ├── artist_search.xml
│ │ ├── artist_view.xml
│ │ ├── fragment_browse.xml
│ │ ├── fragment_home.xml
│ │ ├── fragment_library.xml
│ │ ├── fragment_main.xml
│ │ ├── fragment_radio.xml
│ │ ├── fragment_search.xml
│ │ ├── fragment_search_result.xml
│ │ ├── icon_navbar.xml
│ │ ├── music.xml
│ │ ├── new_album_view.xml
│ │ └── track_view.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── sodastudio
│ └── jun
│ └── spotify_demo
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── sample.json
├── screenshot
├── demo-first.gif
└── screens.png
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
11 | # Built application files
12 | *.apk
13 | *.ap_
14 |
15 | # Files for the ART/Dalvik VM
16 | *.dex
17 |
18 | # Java class files
19 | *.class
20 |
21 | # Generated files
22 | bin/
23 | gen/
24 | out/
25 |
26 | # Gradle files
27 | .gradle/
28 | build/
29 |
30 | # Local configuration file (sdk path, etc)
31 | local.properties
32 |
33 | # Proguard folder generated by Eclipse
34 | proguard/
35 |
36 | # Log Files
37 | *.log
38 |
39 | # Android Studio Navigation editor temp files
40 | .navigation/
41 |
42 | # Android Studio captures folder
43 | captures/
44 |
45 | # Intellij
46 | *.iml
47 | .idea/workspace.xml
48 | .idea/tasks.xml
49 | .idea/gradle.xml
50 | .idea/dictionaries
51 | .idea/libraries
52 |
53 | # Keystore files
54 | *.jks
55 |
56 | # External native build folder generated in Android Studio 2.2 and later
57 | .externalNativeBuild
58 |
59 | # Google Services (e.g. APIs or Firebase)
60 | google-services.json
61 |
62 | # Freeline
63 | freeline.py
64 | freeline/
65 | freeline_project_description.json
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junlee91/android-spotify-demo/c7e88a7095fce7f67883e53d0cd586fa694f0a35/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/.idea/caches/gradle_models.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junlee91/android-spotify-demo/c7e88a7095fce7f67883e53d0cd586fa694f0a35/.idea/caches/gradle_models.ser
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | xmlns:android
14 |
15 | ^$
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | xmlns:.*
25 |
26 | ^$
27 |
28 |
29 | BY_NAME
30 |
31 |
32 |
33 |
34 |
35 |
36 | .*:id
37 |
38 | http://schemas.android.com/apk/res/android
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | .*:name
48 |
49 | http://schemas.android.com/apk/res/android
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | name
59 |
60 | ^$
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | style
70 |
71 | ^$
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | .*
81 |
82 | ^$
83 |
84 |
85 | BY_NAME
86 |
87 |
88 |
89 |
90 |
91 |
92 | .*
93 |
94 | http://schemas.android.com/apk/res/android
95 |
96 |
97 | ANDROID_ATTRIBUTE_ORDER
98 |
99 |
100 |
101 |
102 |
103 |
104 | .*
105 |
106 | .*
107 |
108 |
109 | BY_NAME
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
24 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | spotify-demo
4 | Project spotify-demo created by Buildship.
5 |
6 |
7 |
8 |
9 | org.eclipse.buildship.core.gradleprojectbuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.buildship.core.gradleprojectnature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.buildship.core.prefs:
--------------------------------------------------------------------------------
1 | #Tue Dec 26 18:09:44 CST 2017
2 | connection.project.dir=
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Jun
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | **This project is paused!!** 🙏
2 |
3 | Some components may not work and some packages/dependencies are deprecated.
4 |
5 | # spotify-demo
6 | Music player app using the Spotify Android SDK and Spotify Web API.
7 |
8 | [](https://github.com/junlee91/android-spotify-demo/blob/master/screenshot/screens.png)
9 |
10 |
11 | ## Getting Started
12 | - Clone this repo:
13 | ```sh
14 | https://github.com/junlee91/android-spotify-demo.git
15 | ```
16 | - Open the project in Android Studio
17 | - Make sure to have `buildToolsVersion "26.0.2"`
18 |
19 | ## Installing Spotify Android SDK
20 | You can follow the [Spotify Android SDK Tutorial](https://developer.spotify.com/technologies/spotify-android-sdk/tutorial/) to start the set up.
21 |
22 | ### Quick step
23 | - Download the [Spotify Android playback library zip](https://github.com/spotify/android-sdk/) and [Spotify Android auth library zip](https://github.com/spotify/android-auth/) from GitHub and unzip them.
24 | - In a file explorer (not Android Studio), drag the unzipped spotify-auth-version.aar and spotify-player-version.aar files into the /app/libs directory in your project’s root directory.
25 | - Playback library can be found when you unzip the zipfile. And simply copy this .aar into app/libs
26 | - Auth library needs some more steps.
27 |
28 | ### Build .aar for auth library
29 | - Download and unzip
30 | - Remove the auth-sample directory since it is not needed to create .aar file
31 | - In the `\android-auth-1.0\settings.gradle` file, include `':app'`
32 | - Create `\android-auth-1.0\local.properties` and add `sdk.dir=/Users/%YOUR_PC_USERNAME%/Library/Android/sdk` for path to the Android SDK
33 | - Run `./gradlew build` and grab an artifact from `auth-lib/build/outputs/aar/`.
34 |
35 | ## Generate SHA1
36 | This step is needed for registering application fingerprint
37 | ```sh
38 | echo -n password | shasum -a 1 | awk '{print $1}'
39 | ```
40 |
41 | ## Get data from Spotify Web API
42 | - [Spotify Web API for Android](https://github.com/kaaes/spotify-web-api-android)
43 | - [Documentation](http://kaaes.github.io/spotify-web-api-android/)
44 |
45 | ## ScalingLayout
46 | - Follow the instructions from [here](https://github.com/iammert/ScalingLayout)
47 |
48 | ## Dependency
49 | If you use Android Studio as recommended, the following dependencies will automatically be installed by Gradle.
50 | ```sh
51 | android{
52 | vectorDrawables.useSupportLibrary = true
53 | }
54 |
55 | repositories {
56 | mavenCentral()
57 | flatDir {
58 | dirs 'libs'
59 | }
60 | maven { url "https://jitpack.io" }
61 | }
62 |
63 | dependencies {
64 | ...
65 | compile 'com.github.iammert:ScalingLayout:1.1'
66 | compile 'com.android.support:recyclerview-v7:26.1.0'
67 | compile 'com.squareup.picasso:picasso:2.5.2'
68 | compile 'de.hdodenhof:circleimageview:2.2.0'
69 |
70 | compile 'com.spotify.sdk:spotify-android-auth-1.0.0@aar'
71 | compile 'com.spotify.sdk:spotify-player-24-noconnect-2.20b@aar'
72 | compile 'com.github.kaaes:spotify-web-api-android:0.4.1'
73 | }
74 | ```
75 |
--------------------------------------------------------------------------------
/app/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | app
4 | Project app created by Buildship.
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.buildship.core.gradleprojectbuilder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.buildship.core.gradleprojectnature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/.settings/org.eclipse.buildship.core.prefs:
--------------------------------------------------------------------------------
1 | #Tue Dec 26 18:09:45 CST 2017
2 | connection.project.dir=..
3 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion "26.0.2"
6 | defaultConfig {
7 | applicationId "com.sodastudio.jun.spotify_demo"
8 | minSdkVersion 23
9 | targetSdkVersion 26
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | vectorDrawables.useSupportLibrary = true
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | debug {
21 | }
22 | }
23 | }
24 |
25 | repositories {
26 | mavenCentral()
27 | flatDir {
28 | dirs 'libs'
29 | }
30 | maven { url "https://jitpack.io" }
31 | }
32 |
33 | dependencies {
34 | implementation fileTree(include: ['*.jar'], dir: 'libs')
35 | implementation 'com.android.support:appcompat-v7:26.1.0'
36 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
37 | testImplementation 'junit:junit:4.12'
38 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
39 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
40 |
41 | implementation 'com.github.iammert:ScalingLayout:1.1'
42 | implementation 'com.android.support:recyclerview-v7:26.1.0'
43 | implementation 'com.squareup.picasso:picasso:2.5.2'
44 | implementation 'de.hdodenhof:circleimageview:2.2.0'
45 |
46 | implementation 'com.spotify.sdk:spotify-android-auth-1.0.0@aar'
47 | implementation 'com.spotify.sdk:spotify-player-24-noconnect-2.20b@aar'
48 | implementation 'com.github.kaaes:spotify-web-api-android:0.4.1'
49 | }
50 |
--------------------------------------------------------------------------------
/app/libs/spotify-android-auth-1.0.0.aar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junlee91/android-spotify-demo/c7e88a7095fce7f67883e53d0cd586fa694f0a35/app/libs/spotify-android-auth-1.0.0.aar
--------------------------------------------------------------------------------
/app/libs/spotify-player-24-noconnect-2.20b.aar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junlee91/android-spotify-demo/c7e88a7095fce7f67883e53d0cd586fa694f0a35/app/libs/spotify-player-24-noconnect-2.20b.aar
--------------------------------------------------------------------------------
/app/libs/spotify-web-api-android-0.4.1.aar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junlee91/android-spotify-demo/c7e88a7095fce7f67883e53d0cd586fa694f0a35/app/libs/spotify-web-api-android-0.4.1.aar
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/sodastudio/jun/spotify_demo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.sodastudio.jun.spotify_demo;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.sodastudio.jun.spotify_demo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sodastudio/jun/spotify_demo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.sodastudio.jun.spotify_demo;
2 |
3 | import android.app.FragmentManager;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.util.Log;
7 | import android.widget.Toast;
8 |
9 | import com.sodastudio.jun.spotify_demo.manager.PlaybackManager;
10 | import com.sodastudio.jun.spotify_demo.manager.SearchPager;
11 | import com.sodastudio.jun.spotify_demo.ui.MainFragment;
12 | import com.spotify.sdk.android.player.Config;
13 | import com.spotify.sdk.android.player.ConnectionStateCallback;
14 | import com.spotify.sdk.android.player.Error;
15 | import com.spotify.sdk.android.player.PlaybackState;
16 | import com.spotify.sdk.android.player.Spotify;
17 | import com.spotify.sdk.android.player.SpotifyPlayer;
18 |
19 | import kaaes.spotify.webapi.android.SpotifyApi;
20 | import kaaes.spotify.webapi.android.SpotifyService;
21 | public class MainActivity extends AppCompatActivity
22 | implements ConnectionStateCallback
23 | {
24 |
25 | private static final String TAG = "Spotify MainActivity";
26 |
27 | // _____ _ _ _
28 | // | ___(_) ___| | __| |___
29 | // | |_ | |/ _ \ |/ _` / __|
30 | // | _| | | __/ | (_| \__ \
31 | // |_| |_|\___|_|\__,_|___/
32 | //
33 |
34 | public static SpotifyPlayer mPlayer;
35 | public static PlaybackState mCurrentPlaybackState;
36 |
37 | private Toast mToast;
38 |
39 | private String AUTH_TOKEN;
40 |
41 | public static SpotifyService spotifyService;
42 |
43 | @Override
44 | protected void onCreate(Bundle savedInstanceState) {
45 | super.onCreate(savedInstanceState);
46 | setContentView(R.layout.activity_main);
47 |
48 | FragmentManager manager = getFragmentManager();
49 | manager.beginTransaction().replace(R.id.fragment_container, new MainFragment()).commit();
50 |
51 | AUTH_TOKEN = getIntent().getStringExtra(SpotifyLoginActivity.AUTH_TOKEN);
52 |
53 | onAuthenticationComplete(AUTH_TOKEN);
54 |
55 | }
56 |
57 | private void onAuthenticationComplete(final String auth_token) {
58 |
59 | Log.d(TAG,"Got authentication token");
60 |
61 | if(mPlayer == null)
62 | {
63 | Config playerConfig = new Config(this, auth_token, SpotifyLoginActivity.CLIENT_ID);
64 |
65 | Spotify.getPlayer(playerConfig, this, new SpotifyPlayer.InitializationObserver() {
66 | @Override
67 | public void onInitialized(SpotifyPlayer spotifyPlayer) {
68 | Log.d(TAG,"-- Player initialized --");
69 | mPlayer = spotifyPlayer;
70 | mPlayer.addConnectionStateCallback(MainActivity.this);
71 | //mPlayer.addNotificationCallback(MainActivity.this);
72 |
73 | Log.d(TAG, "AccessToken: " + auth_token);
74 |
75 | // Set API
76 | setServiceAPI();
77 | }
78 |
79 | @Override
80 | public void onError(Throwable throwable) {
81 | Log.e(TAG, "Could not initialize player: " + throwable.getMessage());
82 | }
83 | });
84 | } else {
85 | mPlayer.login(auth_token);
86 | }
87 |
88 | }
89 |
90 | private void setServiceAPI(){
91 | Log.d(TAG, "Setting Spotify API Service");
92 | SpotifyApi api = new SpotifyApi();
93 | api.setAccessToken(AUTH_TOKEN);
94 |
95 | spotifyService = api.getService();
96 | }
97 |
98 | // _ _ ___ _____ _
99 | // | | | |_ _| | ____|_ _____ _ __ | |_ ___
100 | // | | | || | | _| \ \ / / _ \ '_ \| __/ __|
101 | // | |_| || | | |___ \ V / __/ | | | |_\__ \
102 | // \___/|___| |_____| \_/ \___|_| |_|\__|___/
103 | //
104 |
105 |
106 | private boolean isLoggedIn() {
107 | return mPlayer != null && mPlayer.isLoggedIn();
108 | }
109 |
110 |
111 | private void showToast(String text) {
112 | if (mToast != null) {
113 | mToast.cancel();
114 | }
115 | mToast = Toast.makeText(this, text, Toast.LENGTH_SHORT);
116 | mToast.show();
117 | }
118 |
119 | // ____ _ _ _ _ __ __ _ _ _
120 | // / ___|__ _| | | |__ __ _ ___| | __ | \/ | ___| |_| |__ ___ __| |___
121 | // | | / _` | | | '_ \ / _` |/ __| |/ / | |\/| |/ _ \ __| '_ \ / _ \ / _` / __|
122 | // | |__| (_| | | | |_) | (_| | (__| < | | | | __/ |_| | | | (_) | (_| \__ \
123 | // \____\__,_|_|_|_.__/ \__,_|\___|_|\_\ |_| |_|\___|\__|_| |_|\___/ \__,_|___/
124 | //
125 |
126 | @Override
127 | public void onLoggedIn() {
128 | Log.d(TAG, "User logged in");
129 | //showToast("Login Success!");
130 |
131 | SearchPager.getInstance(this).getNewRelease(null);
132 | SearchPager.getInstance(this).getMyTopTracks(null);
133 | SearchPager.getInstance(this).getFeatured();
134 | }
135 |
136 | @Override
137 | public void onLoggedOut() {
138 | Log.d(TAG, "User logged out");
139 | }
140 |
141 | @Override
142 | public void onLoginFailed(Error error) {
143 | Log.d(TAG, "Login failed");
144 | showToast("Login failed. You need Spotify Premium to use the app.");
145 | }
146 |
147 | @Override
148 | public void onTemporaryError() {
149 | Log.d(TAG, "Temporary error occurred");
150 | }
151 |
152 | @Override
153 | public void onConnectionMessage(String message) {
154 | Log.d(TAG, "Received connection message: " + message);
155 | }
156 |
157 | // ____ _ _ _
158 | // | _ \ ___ ___| |_ _ __ _ _ ___| |_(_) ___ _ __
159 | // | | | |/ _ \/ __| __| '__| | | |/ __| __| |/ _ \| '_ \
160 | // | |_| | __/\__ \ |_| | | |_| | (__| |_| | (_) | | | |
161 | // |____/ \___||___/\__|_| \__,_|\___|\__|_|\___/|_| |_|
162 | //
163 |
164 | @Override
165 | protected void onPause() {
166 | super.onPause();
167 |
168 | if (mPlayer != null) {
169 | //mPlayer.removeNotificationCallback(MainActivity.this);
170 | mPlayer.removeConnectionStateCallback(MainActivity.this);
171 | }
172 | }
173 |
174 | @Override
175 | protected void onDestroy() {
176 | Log.d(TAG, "onDestroy");
177 | Spotify.destroyPlayer(this);
178 | super.onDestroy();
179 | }
180 |
181 |
182 | @Override
183 | public void onBackPressed() {
184 | super.onBackPressed();
185 |
186 | PlaybackManager playbackManager = PlaybackManager.getInstance();
187 | playbackManager.setSearchResultFragmentAdded(false);
188 | }
189 | }
190 |
191 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sodastudio/jun/spotify_demo/SplashActivity.java:
--------------------------------------------------------------------------------
1 | package com.sodastudio.jun.spotify_demo;
2 |
3 | import android.content.Intent;
4 | import android.graphics.PixelFormat;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.Window;
8 | import android.view.animation.Animation;
9 | import android.view.animation.AnimationUtils;
10 | import android.widget.ImageView;
11 | import android.widget.LinearLayout;
12 |
13 | /**
14 | * Created by jun on 12/27/17.
15 | */
16 |
17 | public class SplashActivity extends AppCompatActivity {
18 |
19 | public void onAttachedToWindow(){
20 | super.onAttachedToWindow();
21 | Window window = getWindow();
22 | window.setFormat(PixelFormat.RGBA_8888);
23 | }
24 |
25 |
26 | @Override
27 | public void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_splashscreen);
30 | StartAnimations();
31 | }
32 |
33 | private void StartAnimations(){
34 | Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
35 | anim.reset();
36 | LinearLayout l = (LinearLayout)findViewById(R.id.lin_lay);
37 | l.clearAnimation();
38 | l.startAnimation(anim);
39 |
40 | anim = AnimationUtils.loadAnimation(this, R.anim.translate);
41 | anim.reset();
42 | ImageView iv = (ImageView)findViewById(R.id.splash);
43 | iv.clearAnimation();
44 | iv.startAnimation(anim);
45 |
46 | Thread splashTread = new Thread() {
47 | @Override
48 | public void run() {
49 | try {
50 | int waited = 0;
51 | // Splash screen pause time
52 | while (waited < 2500) {
53 | sleep(100);
54 | waited += 100;
55 | }
56 |
57 | Intent intent = new Intent(SplashActivity.this,
58 | SpotifyLoginActivity.class);
59 | intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
60 |
61 | startActivity(intent);
62 | overridePendingTransition(R.anim.pull_up_from_bottom, R.anim.hold);
63 |
64 | SplashActivity.this.finish();
65 | } catch (InterruptedException e) {
66 | // do nothing
67 | } finally {
68 | SplashActivity.this.finish();
69 | }
70 |
71 | }
72 | };
73 | splashTread.start();
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sodastudio/jun/spotify_demo/SpotifyLoginActivity.java:
--------------------------------------------------------------------------------
1 | package com.sodastudio.jun.spotify_demo;
2 |
3 | import android.content.Intent;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.util.Log;
7 | import android.view.View;
8 | import android.widget.Button;
9 |
10 | import com.spotify.sdk.android.authentication.AuthenticationClient;
11 | import com.spotify.sdk.android.authentication.AuthenticationRequest;
12 | import com.spotify.sdk.android.authentication.AuthenticationResponse;
13 |
14 | public class SpotifyLoginActivity extends AppCompatActivity {
15 |
16 | // ____ _ _
17 | // / ___|___ _ __ ___| |_ __ _ _ __ | |_ ___
18 | // | | / _ \| '_ \/ __| __/ _` | '_ \| __/ __|
19 | // | |__| (_) | | | \__ \ || (_| | | | | |_\__ \
20 | // \____\___/|_| |_|___/\__\__,_|_| |_|\__|___/
21 | //
22 |
23 | @SuppressWarnings("SpellCheckingInspection")
24 | public static final String CLIENT_ID = "5de6930c8a744270851a5064c7ff6333";
25 | @SuppressWarnings("SpellCheckingInspection")
26 | private static final String REDIRECT_URI = "http://localhost:8888/callback";
27 |
28 | private static final String TAG = "Spotify " + SpotifyLoginActivity.class.getSimpleName();
29 |
30 | /**
31 | * Request code that will be passed together with authentication result to the onAuthenticationResult
32 | */
33 | private static final int REQUEST_CODE = 1337;
34 |
35 | public static final String AUTH_TOKEN = "AUTH_TOKEN";
36 |
37 | // ___ _ _ _ _ _ _ _
38 | // |_ _|_ __ (_) |_(_) __ _| (_)______ _| |_(_) ___ _ __
39 | // | || '_ \| | __| |/ _` | | |_ / _` | __| |/ _ \| '_ \
40 | // | || | | | | |_| | (_| | | |/ / (_| | |_| | (_) | | | |
41 | // |___|_| |_|_|\__|_|\__,_|_|_/___\__,_|\__|_|\___/|_| |_|
42 | //
43 |
44 | @Override
45 | protected void onCreate(Bundle savedInstanceState) {
46 | super.onCreate(savedInstanceState);
47 | setContentView(R.layout.activity_spotify_login);
48 |
49 | Button mLoginButton = (Button)findViewById(R.id.login_button);
50 | mLoginButton.setOnClickListener(mListener);
51 |
52 | }
53 |
54 | // _ _ _ _ _ _ _
55 | // / \ _ _| |_| |__ ___ _ __ | |_(_) ___ __ _| |_(_) ___ _ __
56 | // / _ \| | | | __| '_ \ / _ \ '_ \| __| |/ __/ _` | __| |/ _ \| '_ \
57 | // / ___ \ |_| | |_| | | | __/ | | | |_| | (_| (_| | |_| | (_) | | | |
58 | // /_/ \_\__,_|\__|_| |_|\___|_| |_|\__|_|\___\__,_|\__|_|\___/|_| |_|
59 | //
60 |
61 |
62 | private void openLoginWindow() {
63 |
64 | AuthenticationRequest.Builder builder = new AuthenticationRequest.Builder(CLIENT_ID, AuthenticationResponse.Type.TOKEN,REDIRECT_URI);
65 |
66 | builder.setScopes(new String[]{"user-read-private", "streaming", "user-top-read", "user-read-recently-played"});
67 | AuthenticationRequest request = builder.build();
68 |
69 | AuthenticationClient.openLoginActivity(this, REQUEST_CODE, request);
70 | }
71 |
72 |
73 | @Override
74 | protected void onActivityResult(int requestCode, final int resultCode, Intent data) {
75 | super.onActivityResult(requestCode, resultCode, data);
76 |
77 | if(requestCode == REQUEST_CODE)
78 | {
79 | final AuthenticationResponse response = AuthenticationClient.getResponse(resultCode, data);
80 |
81 | switch (response.getType()) {
82 | // Response was successful and contains auth token
83 | case TOKEN:
84 |
85 | Intent intent = new Intent(SpotifyLoginActivity.this,
86 | MainActivity.class);
87 |
88 | intent.putExtra(AUTH_TOKEN, response.getAccessToken());
89 |
90 | startActivity(intent);
91 |
92 | destroy();
93 |
94 | break;
95 |
96 | // Auth flow returned an error
97 | case ERROR:
98 | Log.e(TAG,"Auth error: " + response.getError());
99 | break;
100 |
101 | // Most likely auth flow was cancelled
102 | default:
103 | Log.d(TAG,"Auth result: " + response.getType());
104 | }
105 | }
106 | }
107 |
108 | View.OnClickListener mListener = new View.OnClickListener(){
109 |
110 | @Override
111 | public void onClick(View view) {
112 | switch (view.getId()){
113 | case R.id.login_button:
114 | openLoginWindow();
115 | break;
116 | }
117 | }
118 | };
119 |
120 | public void destroy(){
121 | SpotifyLoginActivity.this.finish();
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sodastudio/jun/spotify_demo/TrackDetailActivity.java:
--------------------------------------------------------------------------------
1 | package com.sodastudio.jun.spotify_demo;
2 |
3 | import android.graphics.Bitmap;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.util.Log;
7 | import android.view.View;
8 | import android.widget.ImageView;
9 | import android.widget.TextView;
10 |
11 | import com.sodastudio.jun.spotify_demo.model.Music;
12 | import com.sodastudio.jun.spotify_demo.ui.SearchResultFragment;
13 | import com.squareup.picasso.Picasso;
14 | import com.squareup.picasso.Transformation;
15 |
16 | public class TrackDetailActivity extends AppCompatActivity {
17 |
18 | private static final String TAG = "Spotify TrackDetail";
19 |
20 | private Music detailMusic;
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_track_detail);
26 |
27 | detailMusic = getIntent().getParcelableExtra(SearchResultFragment.DETAIL_MUSIC);
28 |
29 | final ImageView albumImage = findViewById(R.id.detail_album_image_field);
30 | final TextView titleView = findViewById(R.id.detail_track_title_field);
31 | final TextView artistView = findViewById(R.id.detail_artist_field);
32 | final TextView albumView = findViewById(R.id.detail_album_field);
33 |
34 | final TextView cancelView =findViewById(R.id.detail_cancel_button);
35 | cancelView.setOnClickListener(new View.OnClickListener(){
36 |
37 | @Override
38 | public void onClick(View view) {
39 | TrackDetailActivity.this.finish();
40 | }
41 | });
42 |
43 | Picasso.with(this)
44 | .load(detailMusic.getAlbum_image())
45 | .transform(new Transformation() {
46 | @Override
47 | public Bitmap transform(Bitmap source) {
48 | // really ugly darkening trick
49 | final Bitmap copy = source.copy(source.getConfig(), true);
50 | source.recycle();
51 | return copy;
52 | }
53 |
54 | @Override
55 | public String key() {
56 | return "darken";
57 | }
58 | })
59 | .into(albumImage);
60 |
61 | String title = detailMusic.getTitle();
62 | String album = detailMusic.getAlbum();
63 | String artist = detailMusic.getArtist();
64 |
65 | if(title.length() > 40){
66 | title = title.substring(0, 40);
67 | title += "...";
68 | }
69 |
70 | if(album.length() > 40){
71 | album = album.substring(0,40);
72 | album += "...";
73 | }
74 |
75 | if(artist.length() > 40){
76 | artist = artist.substring(0,40);
77 | artist += "...";
78 | }
79 |
80 | titleView.setText(title);
81 | artistView.setText(artist);
82 | albumView.setText(album);
83 |
84 | Log.d(TAG, detailMusic.getTitle());
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sodastudio/jun/spotify_demo/manager/ListManager.java:
--------------------------------------------------------------------------------
1 | package com.sodastudio.jun.spotify_demo.manager;
2 |
3 | import com.sodastudio.jun.spotify_demo.model.AlbumNew;
4 | import com.sodastudio.jun.spotify_demo.model.ArtistSearch;
5 | import com.sodastudio.jun.spotify_demo.model.Music;
6 | import com.sodastudio.jun.spotify_demo.model.SimplePlaylist;
7 | import com.sodastudio.jun.spotify_demo.model.TopArtist;
8 | import com.sodastudio.jun.spotify_demo.model.TopTrack;
9 |
10 | import java.util.ArrayList;
11 |
12 | /**
13 | * Created by jun on 12/30/17.
14 | */
15 |
16 | public class ListManager {
17 |
18 | private static ListManager listManager;
19 |
20 | private ArrayList trackLists;
21 | private ArrayList artistSearches;
22 | private ArrayList albumNewArrayList;
23 | private ArrayList topArtists;
24 | private ArrayList topTracks;
25 | private ArrayList simplePlaylists;
26 |
27 | private String current_playing_title;
28 | private String current_playing_album;
29 |
30 | public static ListManager getInstance(){
31 | if(listManager == null){
32 | listManager = new ListManager();
33 | }
34 |
35 | return listManager;
36 | }
37 |
38 | private ListManager(){
39 | trackLists = new ArrayList<>();
40 | artistSearches = new ArrayList<>();
41 | albumNewArrayList = new ArrayList<>();
42 | topArtists = new ArrayList<>();
43 | topTracks = new ArrayList<>();
44 | simplePlaylists = new ArrayList<>();
45 |
46 | current_playing_title = null;
47 | current_playing_album = null;
48 | }
49 |
50 | public ArrayList getSimplePlaylists(){
51 | return simplePlaylists;
52 | }
53 |
54 | public void addSimpleList(SimplePlaylist simple){
55 | simplePlaylists.add(simple);
56 | }
57 |
58 | public ArrayList getTopTracks(){
59 | return topTracks;
60 | }
61 |
62 | public void addTopTrack(TopTrack track){
63 |
64 | topTracks.add(track);
65 | }
66 |
67 | public void addTopArtist(TopArtist artist){
68 | topArtists.add(artist);
69 | }
70 |
71 | public ArrayList getTopArtists(){
72 | return topArtists;
73 | }
74 |
75 | public void addNewAlbum(AlbumNew albumNew){
76 | albumNewArrayList.add(albumNew);
77 | }
78 |
79 | public ArrayList getAlbumNewArrayList(){
80 | return albumNewArrayList;
81 | }
82 |
83 | public ArrayList getArtists() {
84 | return artistSearches;
85 | }
86 |
87 | public void addArtist(ArtistSearch search){
88 |
89 | ArtistSearch found = null;
90 |
91 | for(ArtistSearch artistSearch : artistSearches)
92 | {
93 | if(artistSearch.getName().equals(search.getName()))
94 | {
95 | found = artistSearch;
96 | }
97 | }
98 |
99 | if(found != null)
100 | artistSearches.remove(found);
101 |
102 | artistSearches.add(0, search);
103 | }
104 |
105 | public ArrayList getTrackLists() {
106 | return trackLists;
107 | }
108 |
109 | public void addTrack(Music music){
110 | trackLists.add(music);
111 | }
112 |
113 | public void clearList(){
114 | trackLists.clear();
115 | }
116 |
117 | public Music findCurrentMusic(String title, String album){
118 | for(Music m : trackLists){
119 | if(m.getTitle().equals(title) && m.getAlbum().equals(album)){
120 | return m;
121 | }
122 | }
123 |
124 | return null;
125 | }
126 |
127 | public String getCurrent_playing_title() {
128 | return current_playing_title;
129 | }
130 |
131 | public void setCurrent_playing_title(String current_playing_title) {
132 | this.current_playing_title = current_playing_title;
133 | }
134 |
135 | public String getCurrent_playing_album() {
136 | return current_playing_album;
137 | }
138 |
139 | public void setCurrent_playing_album(String current_playing_album) {
140 | this.current_playing_album = current_playing_album;
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sodastudio/jun/spotify_demo/manager/PlaybackManager.java:
--------------------------------------------------------------------------------
1 | package com.sodastudio.jun.spotify_demo.manager;
2 |
3 | import android.os.Parcelable;
4 |
5 | import com.sodastudio.jun.spotify_demo.model.Music;
6 |
7 | /**
8 | * Created by jun on 12/31/17.
9 | */
10 |
11 | public class PlaybackManager {
12 |
13 | private static PlaybackManager manager;
14 |
15 | private Music music;
16 | private Parcelable state;
17 | private boolean SearchResultFragmentAdded = false;
18 |
19 | public static PlaybackManager getInstance(){
20 | if(manager == null){
21 | manager = new PlaybackManager();
22 | }
23 |
24 | return manager;
25 | }
26 |
27 | public Music getMusic() {
28 | return music;
29 | }
30 |
31 | public void setMusic(Music music) {
32 | this.music = music;
33 | }
34 |
35 | public Parcelable getState() {
36 | return state;
37 | }
38 |
39 | public void setState(Parcelable state) {
40 | this.state = state;
41 | }
42 |
43 | public boolean isSearchResultFragmentAdded() {
44 | return SearchResultFragmentAdded;
45 | }
46 |
47 | public void setSearchResultFragmentAdded(boolean searchResultFragmentAdded) {
48 | SearchResultFragmentAdded = searchResultFragmentAdded;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sodastudio/jun/spotify_demo/manager/SearchPager.java:
--------------------------------------------------------------------------------
1 | package com.sodastudio.jun.spotify_demo.manager;
2 |
3 | import android.content.Context;
4 | import android.util.Log;
5 |
6 | import com.sodastudio.jun.spotify_demo.MainActivity;
7 | import com.sodastudio.jun.spotify_demo.model.AlbumNew;
8 | import com.sodastudio.jun.spotify_demo.model.SimplePlaylist;
9 | import com.sodastudio.jun.spotify_demo.model.TopArtist;
10 | import com.sodastudio.jun.spotify_demo.model.TopTrack;
11 |
12 | import java.util.ArrayList;
13 | import java.util.HashMap;
14 | import java.util.List;
15 | import java.util.Map;
16 |
17 | import kaaes.spotify.webapi.android.SpotifyCallback;
18 | import kaaes.spotify.webapi.android.SpotifyError;
19 | import kaaes.spotify.webapi.android.SpotifyService;
20 | import kaaes.spotify.webapi.android.models.Album;
21 | import kaaes.spotify.webapi.android.models.AlbumSimple;
22 | import kaaes.spotify.webapi.android.models.Artist;
23 | import kaaes.spotify.webapi.android.models.ArtistSimple;
24 | import kaaes.spotify.webapi.android.models.FeaturedPlaylists;
25 | import kaaes.spotify.webapi.android.models.NewReleases;
26 | import kaaes.spotify.webapi.android.models.Pager;
27 | import kaaes.spotify.webapi.android.models.PlaylistSimple;
28 | import kaaes.spotify.webapi.android.models.Track;
29 | import kaaes.spotify.webapi.android.models.TracksPager;
30 | import retrofit.client.Response;
31 |
32 | /**
33 | * Created by jun on 12/29/17.
34 | */
35 |
36 | public class SearchPager {
37 |
38 | private static SearchPager searchPager;
39 |
40 | private SpotifyService spotifyService = MainActivity.spotifyService;
41 |
42 | public interface CompleteListener {
43 | void onComplete(List