1 |
|
package net.sourceforge.subsonic.androidapp.service; |
2 |
|
|
3 |
|
import android.content.Context; |
4 |
|
import android.util.Log; |
5 |
|
import net.sourceforge.subsonic.androidapp.util.Util; |
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
@author |
11 |
|
@version |
12 |
|
|
|
|
| 83,3% |
Uncovered Elements: 5 (30) |
Complexity: 12 |
Complexity Density: 0,75 |
|
13 |
|
public class Scrobbler { |
14 |
|
|
15 |
|
private static final String TAG = Scrobbler.class.getSimpleName(); |
16 |
|
|
17 |
|
private String lastSubmission; |
18 |
|
private String lastNowPlaying; |
19 |
|
|
|
|
| 89,5% |
Uncovered Elements: 2 (19) |
Complexity: 8 |
Complexity Density: 0,73 |
|
20 |
31
|
public void scrobble(final Context context, final DownloadFile song, final boolean submission) {... |
21 |
31
|
if (song == null || !Util.isScrobblingEnabled(context)) { |
22 |
26
|
return; |
23 |
|
} |
24 |
5
|
final String id = song.getSong().getId(); |
25 |
|
|
26 |
|
|
27 |
5
|
if (submission && id.equals(lastSubmission)) { |
28 |
0
|
return; |
29 |
|
} |
30 |
5
|
if (!submission && id.equals(lastNowPlaying)) { |
31 |
1
|
return; |
32 |
|
} |
33 |
4
|
if (submission) { |
34 |
1
|
lastSubmission = id; |
35 |
|
} else { |
36 |
3
|
lastNowPlaying = id; |
37 |
|
} |
38 |
|
|
39 |
4
|
new Thread("Scrobble " + song) { |
|
|
| 66,7% |
Uncovered Elements: 3 (9) |
Complexity: 4 |
Complexity Density: 0,8 |
|
40 |
4
|
@Override... |
41 |
|
public void run() { |
42 |
4
|
MusicService service = MusicServiceFactory.getMusicService(context); |
43 |
4
|
try { |
44 |
4
|
service.scrobble(id, submission, context, null); |
45 |
0
|
Log.i(TAG, "Scrobbled '" + (submission ? "submission" : "now playing") + "' for " + song); |
46 |
|
} catch (Exception x) { |
47 |
4
|
Log.i(TAG, "Failed to scrobble'" + (submission ? "submission" : "now playing") + "' for " + song, x); |
48 |
|
} |
49 |
|
} |
50 |
|
}.start(); |
51 |
|
} |
52 |
|
} |