Skip to content

Commit

Permalink
fix lastfm usersesion
Browse files Browse the repository at this point in the history
  • Loading branch information
naman14 committed Nov 14, 2016
1 parent 9638430 commit 73ff85d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
<!--use your own api key for fabric-->
<meta-data
android:name="io.fabric.ApiKey"
android:value="@string/fabric_api_key" />
android:value="c8077ebaaaa3a70c39a1ac070dfcfdf2fb48b128" />

<receiver android:name=".widgets.desktop.StandardWidget" android:label="@string/widget_standard">
<intent-filter>
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/com/naman14/timber/MusicService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
35 changes: 22 additions & 13 deletions app/src/main/java/com/naman14/timber/lastfmapi/LastFmClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<ScrobbleInfo>() {
@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<ScrobbleInfo>() {
@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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 73ff85d

Please sign in to comment.