diff --git a/app/build.gradle b/app/build.gradle index 10b9a8458..16fb8a3ac 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,7 +9,7 @@ android { applicationId "naman14.timber" minSdkVersion 16 targetSdkVersion 24 - versionCode 15 + versionCode 16 versionName "0.3b" //renderscript support mode is not supported for 21+ with gradle version 2.0 renderscriptTargetApi 20 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0e114bdd5..b90ab83a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -109,7 +109,7 @@ + android:value="c8077ebaaaa3a70c39a1ac070dfcfdf2fb48b128" /> diff --git a/app/src/main/java/com/naman14/timber/MusicService.java b/app/src/main/java/com/naman14/timber/MusicService.java index 20a166543..48426eac3 100644 --- a/app/src/main/java/com/naman14/timber/MusicService.java +++ b/app/src/main/java/com/naman14/timber/MusicService.java @@ -64,6 +64,7 @@ import com.naman14.timber.helpers.MediaButtonIntentReceiver; import com.naman14.timber.helpers.MusicPlaybackTrack; import com.naman14.timber.lastfmapi.LastFmClient; +import com.naman14.timber.lastfmapi.models.LastfmUserSession; import com.naman14.timber.lastfmapi.models.ScrobbleQuery; import com.naman14.timber.permissions.Nammu; import com.naman14.timber.provider.MusicPlaybackState; @@ -453,8 +454,10 @@ public int onStartCommand(final Intent intent, final int flags, final int startI } void scrobble() { - Log.d("Scrobble","to LastFM"); - LastFmClient.getInstance(this).Scrobble(new ScrobbleQuery(getArtistName(),getTrackName(),(System.currentTimeMillis()-duration())/1000)); + if (LastfmUserSession.getSession(this) != null) { + Log.d("Scrobble", "to LastFM"); + LastFmClient.getInstance(this).Scrobble(new ScrobbleQuery(getArtistName(), getTrackName(), (System.currentTimeMillis() - duration()) / 1000)); + } } private void releaseServiceUiAndStop() { diff --git a/app/src/main/java/com/naman14/timber/lastfmapi/LastFmClient.java b/app/src/main/java/com/naman14/timber/lastfmapi/LastFmClient.java index 1c1dd5ae9..f5b38e9db 100644 --- a/app/src/main/java/com/naman14/timber/lastfmapi/LastFmClient.java +++ b/app/src/main/java/com/naman14/timber/lastfmapi/LastFmClient.java @@ -15,6 +15,7 @@ package com.naman14.timber.lastfmapi; import android.content.Context; +import android.content.SharedPreferences; import android.util.Log; import com.naman14.timber.lastfmapi.callbacks.ArtistInfoListener; @@ -65,7 +66,7 @@ public static LastFmClient getInstance(Context context) { sInstance.mRestService = RestServiceFactory.createStatic(context, BASE_API_URL, LastFmRestService.class); sInstance.mUserRestService = RestServiceFactory.create(context, BASE_SECURE_API_URL, LastFmUserRestService.class); sInstance.mUserSession = LastfmUserSession.getSession(context); - + } return sInstance; } @@ -137,26 +138,34 @@ public void failure(RetrofitError error) { } public void Scrobble(ScrobbleQuery scrobbleQuery) { - mUserRestService.getScrobbleInfo(ScrobbleQuery.Method, API_KEY, generateMD5(scrobbleQuery.getSignature(mUserSession.mToken)), mUserSession.mToken, scrobbleQuery.mArtist, scrobbleQuery.mTrack, scrobbleQuery.mTimestamp, new Callback() { - @Override - public void success(ScrobbleInfo scrobbleInfo, Response response) { + try { + mUserRestService.getScrobbleInfo(ScrobbleQuery.Method, API_KEY, generateMD5(scrobbleQuery.getSignature(mUserSession.mToken)), mUserSession.mToken, scrobbleQuery.mArtist, scrobbleQuery.mTrack, scrobbleQuery.mTimestamp, new Callback() { + @Override + public void success(ScrobbleInfo scrobbleInfo, Response response) { - } + } - @Override - public void failure(RetrofitError error) { + @Override + public void failure(RetrofitError error) { - } - }); + } + }); + } catch (Exception e) { + e.printStackTrace(); + } } - public void logout(){ + public void logout() { this.mUserSession.mToken = null; this.mUserSession.mUsername = null; - this.mUserSession.update(context); + SharedPreferences preferences = context.getSharedPreferences("Lastfm", Context.MODE_PRIVATE); + SharedPreferences.Editor editor = preferences.edit(); + editor.clear(); + editor.apply(); } - public String getUsername(){ - if(mUserSession!=null)return mUserSession.mUsername; + + public String getUsername() { + if (mUserSession != null) return mUserSession.mUsername; return null; } } diff --git a/app/src/main/java/com/naman14/timber/lastfmapi/models/LastfmUserSession.java b/app/src/main/java/com/naman14/timber/lastfmapi/models/LastfmUserSession.java index f99841581..969405af9 100644 --- a/app/src/main/java/com/naman14/timber/lastfmapi/models/LastfmUserSession.java +++ b/app/src/main/java/com/naman14/timber/lastfmapi/models/LastfmUserSession.java @@ -32,7 +32,7 @@ public void update(Context context) { editor.putString(TOKEN, this.mToken); editor.putString(USERNAME, this.mUsername); } - editor.commit(); + editor.apply(); } @SerializedName(USERNAME)