mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Integrate subsonic APIs for podcasts via retrofit
This commit is contained in:
parent
3e58ec928e
commit
afae06cc01
2 changed files with 94 additions and 0 deletions
|
|
@ -0,0 +1,73 @@
|
|||
package com.cappielloantonio.play.subsonic.api.podcast;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.cappielloantonio.play.subsonic.Subsonic;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
||||
import com.tickaroo.tikxml.retrofit.TikXmlConverterFactory;
|
||||
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class PodcastClient {
|
||||
private static final String TAG = "SystemClient";
|
||||
|
||||
private final Context context;
|
||||
private final Subsonic subsonic;
|
||||
private final PodcastService podcastService;
|
||||
|
||||
public PodcastClient(Context context, Subsonic subsonic) {
|
||||
this.context = context;
|
||||
this.subsonic = subsonic;
|
||||
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl(subsonic.getUrl())
|
||||
.addConverterFactory(TikXmlConverterFactory.create())
|
||||
.client(getOkHttpClient())
|
||||
.build();
|
||||
|
||||
this.podcastService = retrofit.create(PodcastService.class);
|
||||
}
|
||||
|
||||
public Call<SubsonicResponse> getPodcasts(boolean includeEpisodes, String channelId) {
|
||||
Log.d(TAG, "getPodcasts()");
|
||||
return podcastService.getPodcasts(subsonic.getParams(), includeEpisodes, channelId);
|
||||
}
|
||||
|
||||
public Call<SubsonicResponse> getNewestPodcasts(int count) {
|
||||
Log.d(TAG, "getNewestPodcasts()");
|
||||
return podcastService.getNewestPodcasts(subsonic.getParams(), count);
|
||||
}
|
||||
|
||||
public Call<SubsonicResponse> refreshPodcasts() {
|
||||
Log.d(TAG, "refreshPodcasts()");
|
||||
return podcastService.refreshPodcasts(subsonic.getParams());
|
||||
}
|
||||
private OkHttpClient getOkHttpClient() {
|
||||
CacheUtil cacheUtil = new CacheUtil(context, 0, 60 * 60 * 24 * 30);
|
||||
|
||||
return new OkHttpClient.Builder()
|
||||
.addInterceptor(getHttpLoggingInterceptor())
|
||||
.addInterceptor(cacheUtil.offlineInterceptor)
|
||||
.addNetworkInterceptor(cacheUtil.onlineInterceptor)
|
||||
.cache(getCache())
|
||||
.build();
|
||||
}
|
||||
|
||||
private HttpLoggingInterceptor getHttpLoggingInterceptor() {
|
||||
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
|
||||
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
|
||||
return loggingInterceptor;
|
||||
}
|
||||
|
||||
private Cache getCache() {
|
||||
int cacheSize = 10 * 1024 * 1024;
|
||||
return context != null ? new Cache(context.getCacheDir(), cacheSize) : null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.cappielloantonio.play.subsonic.api.podcast;
|
||||
|
||||
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 PodcastService {
|
||||
@GET("getPodcasts")
|
||||
Call<SubsonicResponse> getPodcasts(@QueryMap Map<String, String> params, @Query("includeEpisodes") boolean includeEpisodes, @Query("id") String id);
|
||||
|
||||
@GET("getNewestPodcasts")
|
||||
Call<SubsonicResponse> getNewestPodcasts(@QueryMap Map<String, String> params, @Query("count") int count);
|
||||
|
||||
@GET("refreshPodcasts")
|
||||
Call<SubsonicResponse> refreshPodcasts(@QueryMap Map<String, String> params);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue