mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Implemented scobble action
This commit is contained in:
parent
4fc29b47be
commit
6f1046b137
5 changed files with 136 additions and 4 deletions
|
|
@ -30,7 +30,8 @@ public class SongRepository {
|
|||
}
|
||||
|
||||
public MutableLiveData<List<Song>> getStarredSongs() {
|
||||
App.getSubsonicClientInstance(application, false).getAlbumSongListClient()
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
.getStarred2()
|
||||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
|
|
@ -51,7 +52,8 @@ public class SongRepository {
|
|||
}
|
||||
|
||||
public void getInstantMix(Song song, int count, MediaCallback callback) {
|
||||
App.getSubsonicClientInstance(application, false).getBrowsingClient()
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
.getSimilarSongs2(song.getId(), count)
|
||||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
|
|
@ -77,7 +79,8 @@ public class SongRepository {
|
|||
}
|
||||
|
||||
public void getRandomSample(int number, MediaCallback callback) {
|
||||
App.getSubsonicClientInstance(application, false).getAlbumSongListClient()
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
.getRandomSongs(number)
|
||||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
|
|
@ -97,4 +100,21 @@ public class SongRepository {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void scrobble(String id) {
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getMediaAnnotationClient()
|
||||
.scrobble(id)
|
||||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -381,6 +381,8 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
|||
nextPosition = getNextPosition();
|
||||
playback.queueDataSource(getSongAt(nextPosition));
|
||||
}
|
||||
|
||||
increaseSongCount();
|
||||
}
|
||||
|
||||
public void initNotification() {
|
||||
|
|
@ -637,7 +639,6 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
|||
saveProgress();
|
||||
break;
|
||||
case QUEUE_CHANGED:
|
||||
// because playing queue size might have changed
|
||||
updateMediaSessionMetadata();
|
||||
saveState();
|
||||
if (playingQueue.size() > 0) {
|
||||
|
|
@ -659,6 +660,11 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
|||
}
|
||||
}
|
||||
|
||||
private void increaseSongCount() {
|
||||
SongRepository songRepository = new SongRepository(App.getInstance());
|
||||
songRepository.scrobble(getCurrentSong().getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStateChanged(int state) {
|
||||
notifyChange(STATE_CHANGED);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.cappielloantonio.play.subsonic;
|
|||
|
||||
import com.cappielloantonio.play.subsonic.api.albumsonglist.AlbumSongListClient;
|
||||
import com.cappielloantonio.play.subsonic.api.browsing.BrowsingClient;
|
||||
import com.cappielloantonio.play.subsonic.api.mediaannotation.MediaAnnotationClient;
|
||||
import com.cappielloantonio.play.subsonic.api.mediaretrieval.MediaRetrievalClient;
|
||||
import com.cappielloantonio.play.subsonic.api.playlist.PlaylistClient;
|
||||
import com.cappielloantonio.play.subsonic.api.searching.SearchingClient;
|
||||
|
|
@ -24,6 +25,7 @@ public class Subsonic {
|
|||
private PlaylistClient playlistClient;
|
||||
private SearchingClient searchingClient;
|
||||
private AlbumSongListClient albumSongListClient;
|
||||
private MediaAnnotationClient mediaAnnotationClient;
|
||||
|
||||
public Subsonic(SubsonicPreferences preferences) {
|
||||
this.preferences = preferences;
|
||||
|
|
@ -75,6 +77,13 @@ public class Subsonic {
|
|||
return albumSongListClient;
|
||||
}
|
||||
|
||||
public MediaAnnotationClient getMediaAnnotationClient() {
|
||||
if (mediaAnnotationClient == null) {
|
||||
mediaAnnotationClient = new MediaAnnotationClient(this);
|
||||
}
|
||||
return mediaAnnotationClient;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return preferences.getServerUrl() + "/rest/";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
package com.cappielloantonio.play.subsonic.api.mediaannotation;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.cappielloantonio.play.subsonic.Subsonic;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.tickaroo.tikxml.TikXml;
|
||||
import com.tickaroo.tikxml.converter.htmlescape.HtmlEscapeStringConverter;
|
||||
import com.tickaroo.tikxml.retrofit.TikXmlConverterFactory;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class MediaAnnotationClient {
|
||||
private static final String TAG = "BrowsingClient";
|
||||
|
||||
private Subsonic subsonic;
|
||||
private Retrofit retrofit;
|
||||
private MediaAnnotationService mediaAnnotationService;
|
||||
|
||||
public MediaAnnotationClient(Subsonic subsonic) {
|
||||
this.subsonic = subsonic;
|
||||
|
||||
this.retrofit = new Retrofit.Builder()
|
||||
.baseUrl(subsonic.getUrl())
|
||||
.addConverterFactory(TikXmlConverterFactory.create(getParser()))
|
||||
.client(getOkHttpClient())
|
||||
.build();
|
||||
|
||||
this.mediaAnnotationService = retrofit.create(MediaAnnotationService.class);
|
||||
}
|
||||
|
||||
public Call<SubsonicResponse> star(String id) {
|
||||
Log.d(TAG, "star()");
|
||||
return mediaAnnotationService.star(subsonic.getParams(), id);
|
||||
}
|
||||
|
||||
public Call<SubsonicResponse> unstar(String id) {
|
||||
Log.d(TAG, "unstar()");
|
||||
return mediaAnnotationService.unstar(subsonic.getParams(), id);
|
||||
}
|
||||
|
||||
public Call<SubsonicResponse> setRating(String id, int star) {
|
||||
Log.d(TAG, "setRating()");
|
||||
return mediaAnnotationService.setRating(subsonic.getParams(), id, star);
|
||||
}
|
||||
|
||||
public Call<SubsonicResponse> scrobble(String id) {
|
||||
Log.d(TAG, "scrobble()");
|
||||
return mediaAnnotationService.scrobble(subsonic.getParams(), id);
|
||||
}
|
||||
|
||||
private TikXml getParser() {
|
||||
return new TikXml.Builder()
|
||||
.addTypeConverter(String.class, new HtmlEscapeStringConverter()) // HtmlEscapeStringConverter encode / decode html characters. This class ships as optional dependency
|
||||
.build();
|
||||
}
|
||||
|
||||
private OkHttpClient getOkHttpClient() {
|
||||
return new OkHttpClient.Builder()
|
||||
.addInterceptor(getHttpLoggingInterceptor())
|
||||
.build();
|
||||
}
|
||||
|
||||
private HttpLoggingInterceptor getHttpLoggingInterceptor() {
|
||||
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
|
||||
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
|
||||
return loggingInterceptor;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package com.cappielloantonio.play.subsonic.api.mediaannotation;
|
||||
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
import retrofit2.http.QueryMap;
|
||||
|
||||
public interface MediaAnnotationService {
|
||||
@GET("star")
|
||||
Call<SubsonicResponse> star(@QueryMap Map<String, String> params, @Query("id") String id);
|
||||
|
||||
@GET("stream")
|
||||
Call<SubsonicResponse> unstar(@QueryMap Map<String, String> params, @Query("id") String id);
|
||||
|
||||
@GET("stream")
|
||||
Call<SubsonicResponse> setRating(@QueryMap Map<String, String> params, @Query("id") String id, @Query("star") int star);
|
||||
|
||||
@GET("scrobble")
|
||||
Call<SubsonicResponse> scrobble(@QueryMap Map<String, String> params, @Query("id") String id);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue