mirror of
https://github.com/CappielloAntonio/tempo.git
synced 2026-02-02 15:33:36 +00:00
Implemented scobble action
This commit is contained in:
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user