mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 09:53:33 +00:00
Centralized Retrofit client policies
This commit is contained in:
parent
d07855a48d
commit
ea151e8438
10 changed files with 77 additions and 336 deletions
|
|
@ -0,0 +1,59 @@
|
||||||
|
package com.cappielloantonio.play.subsonic
|
||||||
|
|
||||||
|
import com.cappielloantonio.play.App
|
||||||
|
import com.cappielloantonio.play.subsonic.utils.CacheUtil
|
||||||
|
import com.google.gson.GsonBuilder
|
||||||
|
import okhttp3.Cache
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.logging.HttpLoggingInterceptor
|
||||||
|
import retrofit2.Retrofit
|
||||||
|
import retrofit2.converter.gson.GsonConverterFactory
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
class RetrofitClient(subsonic: Subsonic) {
|
||||||
|
var retrofit: Retrofit
|
||||||
|
|
||||||
|
init {
|
||||||
|
retrofit = Retrofit.Builder()
|
||||||
|
.baseUrl(subsonic.url)
|
||||||
|
.addConverterFactory(GsonConverterFactory.create(GsonBuilder().setLenient().create()))
|
||||||
|
.client(getOkHttpClient())
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getOkHttpClient(): OkHttpClient {
|
||||||
|
val cacheUtil = CacheUtil(60, 60 * 60 * 24 * 30)
|
||||||
|
|
||||||
|
// BrowsingClient 60
|
||||||
|
// MediaAnnotationClient 0
|
||||||
|
// MediaLibraryScanningClient 0
|
||||||
|
// MediaRetrievalClient 0
|
||||||
|
// PlaylistClient 0
|
||||||
|
// PodcastClient 60
|
||||||
|
// SearchClient 60
|
||||||
|
// SystemClient 60
|
||||||
|
// AlbumSongListClient 60
|
||||||
|
|
||||||
|
return OkHttpClient.Builder()
|
||||||
|
.callTimeout(2, TimeUnit.MINUTES)
|
||||||
|
.connectTimeout(20, TimeUnit.SECONDS)
|
||||||
|
.readTimeout(30, TimeUnit.SECONDS)
|
||||||
|
.writeTimeout(30, TimeUnit.SECONDS)
|
||||||
|
.addInterceptor(getHttpLoggingInterceptor())
|
||||||
|
.addInterceptor(cacheUtil.offlineInterceptor)
|
||||||
|
.addNetworkInterceptor(cacheUtil.onlineInterceptor)
|
||||||
|
.cache(getCache())
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getHttpLoggingInterceptor(): HttpLoggingInterceptor {
|
||||||
|
val loggingInterceptor = HttpLoggingInterceptor()
|
||||||
|
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY)
|
||||||
|
return loggingInterceptor
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getCache(): Cache {
|
||||||
|
val cacheSize = 10 * 1024 * 1024
|
||||||
|
return Cache(App.getContext().cacheDir, cacheSize.toLong())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,7 @@ package com.cappielloantonio.play.subsonic.api.albumsonglist;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.cappielloantonio.play.App;
|
import com.cappielloantonio.play.App;
|
||||||
|
import com.cappielloantonio.play.subsonic.RetrofitClient;
|
||||||
import com.cappielloantonio.play.subsonic.Subsonic;
|
import com.cappielloantonio.play.subsonic.Subsonic;
|
||||||
import com.cappielloantonio.play.subsonic.base.ApiResponse;
|
import com.cappielloantonio.play.subsonic.base.ApiResponse;
|
||||||
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
||||||
|
|
@ -25,14 +26,7 @@ public class AlbumSongListClient {
|
||||||
|
|
||||||
public AlbumSongListClient(Subsonic subsonic) {
|
public AlbumSongListClient(Subsonic subsonic) {
|
||||||
this.subsonic = subsonic;
|
this.subsonic = subsonic;
|
||||||
|
this.albumSongListService = new RetrofitClient(subsonic).getRetrofit().create(AlbumSongListService.class);
|
||||||
Retrofit retrofit = new Retrofit.Builder()
|
|
||||||
.baseUrl(subsonic.getUrl())
|
|
||||||
.addConverterFactory(GsonConverterFactory.create(new GsonBuilder().setLenient().create()))
|
|
||||||
.client(getOkHttpClient())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
this.albumSongListService = retrofit.create(AlbumSongListService.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Call<ApiResponse> getAlbumList(String type, int size, int offset) {
|
public Call<ApiResponse> getAlbumList(String type, int size, int offset) {
|
||||||
|
|
@ -69,35 +63,4 @@ public class AlbumSongListClient {
|
||||||
Log.d(TAG, "getStarred2()");
|
Log.d(TAG, "getStarred2()");
|
||||||
return albumSongListService.getStarred2(subsonic.getParams());
|
return albumSongListService.getStarred2(subsonic.getParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
private OkHttpClient getOkHttpClient() {
|
|
||||||
CacheUtil cacheUtil = new CacheUtil(60, 60 * 60 * 24 * 30);
|
|
||||||
|
|
||||||
return new OkHttpClient.Builder()
|
|
||||||
.callTimeout(2, TimeUnit.MINUTES)
|
|
||||||
.connectTimeout(20, TimeUnit.SECONDS)
|
|
||||||
.readTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.writeTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.callTimeout(2, TimeUnit.MINUTES)
|
|
||||||
.connectTimeout(20, TimeUnit.SECONDS)
|
|
||||||
.readTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.writeTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.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 new Cache(App.getContext().getCacheDir(), cacheSize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,11 @@ package com.cappielloantonio.play.subsonic.api.browsing;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.cappielloantonio.play.App;
|
import com.cappielloantonio.play.subsonic.RetrofitClient;
|
||||||
import com.cappielloantonio.play.subsonic.Subsonic;
|
import com.cappielloantonio.play.subsonic.Subsonic;
|
||||||
import com.cappielloantonio.play.subsonic.base.ApiResponse;
|
import com.cappielloantonio.play.subsonic.base.ApiResponse;
|
||||||
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import okhttp3.Cache;
|
|
||||||
import okhttp3.OkHttpClient;
|
|
||||||
import okhttp3.logging.HttpLoggingInterceptor;
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Retrofit;
|
|
||||||
import retrofit2.converter.gson.GsonConverterFactory;
|
|
||||||
|
|
||||||
public class BrowsingClient {
|
public class BrowsingClient {
|
||||||
private static final String TAG = "BrowsingClient";
|
private static final String TAG = "BrowsingClient";
|
||||||
|
|
@ -25,14 +16,7 @@ public class BrowsingClient {
|
||||||
|
|
||||||
public BrowsingClient(Subsonic subsonic) {
|
public BrowsingClient(Subsonic subsonic) {
|
||||||
this.subsonic = subsonic;
|
this.subsonic = subsonic;
|
||||||
|
this.browsingService = new RetrofitClient(subsonic).getRetrofit().create(BrowsingService.class);
|
||||||
Retrofit retrofit = new Retrofit.Builder()
|
|
||||||
.baseUrl(subsonic.getUrl())
|
|
||||||
.addConverterFactory(GsonConverterFactory.create(new GsonBuilder().setLenient().create()))
|
|
||||||
.client(getOkHttpClient())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
this.browsingService = retrofit.create(BrowsingService.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Call<ApiResponse> getMusicFolders() {
|
public Call<ApiResponse> getMusicFolders() {
|
||||||
|
|
@ -119,31 +103,4 @@ public class BrowsingClient {
|
||||||
Log.d(TAG, "getTopSongs()");
|
Log.d(TAG, "getTopSongs()");
|
||||||
return browsingService.getTopSongs(subsonic.getParams(), artist, count);
|
return browsingService.getTopSongs(subsonic.getParams(), artist, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
private OkHttpClient getOkHttpClient() {
|
|
||||||
CacheUtil cacheUtil = new CacheUtil(60, 60 * 60 * 24 * 30);
|
|
||||||
|
|
||||||
return new OkHttpClient.Builder()
|
|
||||||
.callTimeout(2, TimeUnit.MINUTES)
|
|
||||||
.connectTimeout(20, TimeUnit.SECONDS)
|
|
||||||
.readTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.writeTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.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 new Cache(App.getContext().getCacheDir(), cacheSize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,11 @@ package com.cappielloantonio.play.subsonic.api.mediaannotation;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.cappielloantonio.play.App;
|
import com.cappielloantonio.play.subsonic.RetrofitClient;
|
||||||
import com.cappielloantonio.play.subsonic.Subsonic;
|
import com.cappielloantonio.play.subsonic.Subsonic;
|
||||||
import com.cappielloantonio.play.subsonic.base.ApiResponse;
|
import com.cappielloantonio.play.subsonic.base.ApiResponse;
|
||||||
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import okhttp3.Cache;
|
|
||||||
import okhttp3.OkHttpClient;
|
|
||||||
import okhttp3.logging.HttpLoggingInterceptor;
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Retrofit;
|
|
||||||
import retrofit2.converter.gson.GsonConverterFactory;
|
|
||||||
|
|
||||||
public class MediaAnnotationClient {
|
public class MediaAnnotationClient {
|
||||||
private static final String TAG = "BrowsingClient";
|
private static final String TAG = "BrowsingClient";
|
||||||
|
|
@ -25,14 +16,7 @@ public class MediaAnnotationClient {
|
||||||
|
|
||||||
public MediaAnnotationClient(Subsonic subsonic) {
|
public MediaAnnotationClient(Subsonic subsonic) {
|
||||||
this.subsonic = subsonic;
|
this.subsonic = subsonic;
|
||||||
|
this.mediaAnnotationService = new RetrofitClient(subsonic).getRetrofit().create(MediaAnnotationService.class);
|
||||||
Retrofit retrofit = new Retrofit.Builder()
|
|
||||||
.baseUrl(subsonic.getUrl())
|
|
||||||
.addConverterFactory(GsonConverterFactory.create(new GsonBuilder().setLenient().create()))
|
|
||||||
.client(getOkHttpClient())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
this.mediaAnnotationService = retrofit.create(MediaAnnotationService.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Call<ApiResponse> star(String id, String albumId, String artistId) {
|
public Call<ApiResponse> star(String id, String albumId, String artistId) {
|
||||||
|
|
@ -54,30 +38,4 @@ public class MediaAnnotationClient {
|
||||||
Log.d(TAG, "scrobble()");
|
Log.d(TAG, "scrobble()");
|
||||||
return mediaAnnotationService.scrobble(subsonic.getParams(), id);
|
return mediaAnnotationService.scrobble(subsonic.getParams(), id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private OkHttpClient getOkHttpClient() {
|
|
||||||
CacheUtil cacheUtil = new CacheUtil(0, 60 * 60 * 24 * 30);
|
|
||||||
|
|
||||||
return new OkHttpClient.Builder()
|
|
||||||
.callTimeout(2, TimeUnit.MINUTES)
|
|
||||||
.connectTimeout(20, TimeUnit.SECONDS)
|
|
||||||
.readTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.writeTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.addInterceptor(getHttpLoggingInterceptor())
|
|
||||||
.addInterceptor(cacheUtil.offlineInterceptor)
|
|
||||||
.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 new Cache(App.getContext().getCacheDir(), cacheSize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.cappielloantonio.play.subsonic.api.medialibraryscanning;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.cappielloantonio.play.App;
|
import com.cappielloantonio.play.App;
|
||||||
|
import com.cappielloantonio.play.subsonic.RetrofitClient;
|
||||||
import com.cappielloantonio.play.subsonic.Subsonic;
|
import com.cappielloantonio.play.subsonic.Subsonic;
|
||||||
import com.cappielloantonio.play.subsonic.base.ApiResponse;
|
import com.cappielloantonio.play.subsonic.base.ApiResponse;
|
||||||
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
||||||
|
|
@ -25,14 +26,7 @@ public class MediaLibraryScanningClient {
|
||||||
|
|
||||||
public MediaLibraryScanningClient(Subsonic subsonic) {
|
public MediaLibraryScanningClient(Subsonic subsonic) {
|
||||||
this.subsonic = subsonic;
|
this.subsonic = subsonic;
|
||||||
|
this.mediaLibraryScanningService = new RetrofitClient(subsonic).getRetrofit().create(MediaLibraryScanningService.class);
|
||||||
Retrofit retrofit = new Retrofit.Builder()
|
|
||||||
.baseUrl(subsonic.getUrl())
|
|
||||||
.addConverterFactory(GsonConverterFactory.create(new GsonBuilder().setLenient().create()))
|
|
||||||
.client(getOkHttpClient())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
this.mediaLibraryScanningService = retrofit.create(MediaLibraryScanningService.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Call<ApiResponse> startScan() {
|
public Call<ApiResponse> startScan() {
|
||||||
|
|
@ -44,30 +38,4 @@ public class MediaLibraryScanningClient {
|
||||||
Log.d(TAG, "getScanStatus()");
|
Log.d(TAG, "getScanStatus()");
|
||||||
return mediaLibraryScanningService.getScanStatus(subsonic.getParams());
|
return mediaLibraryScanningService.getScanStatus(subsonic.getParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
private OkHttpClient getOkHttpClient() {
|
|
||||||
CacheUtil cacheUtil = new CacheUtil(0, 60 * 60 * 24 * 30);
|
|
||||||
|
|
||||||
return new OkHttpClient.Builder()
|
|
||||||
.callTimeout(2, TimeUnit.MINUTES)
|
|
||||||
.connectTimeout(20, TimeUnit.SECONDS)
|
|
||||||
.readTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.writeTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.addInterceptor(getHttpLoggingInterceptor())
|
|
||||||
.addInterceptor(cacheUtil.offlineInterceptor)
|
|
||||||
.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 new Cache(App.getContext().getCacheDir(), cacheSize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.cappielloantonio.play.subsonic.api.mediaretrieval;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.cappielloantonio.play.App;
|
import com.cappielloantonio.play.App;
|
||||||
|
import com.cappielloantonio.play.subsonic.RetrofitClient;
|
||||||
import com.cappielloantonio.play.subsonic.Subsonic;
|
import com.cappielloantonio.play.subsonic.Subsonic;
|
||||||
import com.cappielloantonio.play.subsonic.base.ApiResponse;
|
import com.cappielloantonio.play.subsonic.base.ApiResponse;
|
||||||
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
||||||
|
|
@ -25,14 +26,7 @@ public class MediaRetrievalClient {
|
||||||
|
|
||||||
public MediaRetrievalClient(Subsonic subsonic) {
|
public MediaRetrievalClient(Subsonic subsonic) {
|
||||||
this.subsonic = subsonic;
|
this.subsonic = subsonic;
|
||||||
|
this.mediaRetrievalService = new RetrofitClient(subsonic).getRetrofit().create(MediaRetrievalService.class);
|
||||||
Retrofit retrofit = new Retrofit.Builder()
|
|
||||||
.baseUrl(subsonic.getUrl())
|
|
||||||
.addConverterFactory(GsonConverterFactory.create(new GsonBuilder().setLenient().create()))
|
|
||||||
.client(getOkHttpClient())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
this.mediaRetrievalService = retrofit.create(MediaRetrievalService.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Call<ApiResponse> stream(String id, Integer maxBitRate, String format) {
|
public Call<ApiResponse> stream(String id, Integer maxBitRate, String format) {
|
||||||
|
|
@ -49,31 +43,4 @@ public class MediaRetrievalClient {
|
||||||
Log.d(TAG, "getLyrics()");
|
Log.d(TAG, "getLyrics()");
|
||||||
return mediaRetrievalService.getLyrics(subsonic.getParams(), artist, title);
|
return mediaRetrievalService.getLyrics(subsonic.getParams(), artist, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
private OkHttpClient getOkHttpClient() {
|
|
||||||
CacheUtil cacheUtil = new CacheUtil(0, 60 * 60 * 24 * 30);
|
|
||||||
|
|
||||||
return new OkHttpClient.Builder()
|
|
||||||
.callTimeout(2, TimeUnit.MINUTES)
|
|
||||||
.connectTimeout(20, TimeUnit.SECONDS)
|
|
||||||
.readTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.writeTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.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 new Cache(App.getContext().getCacheDir(), cacheSize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.cappielloantonio.play.subsonic.api.playlist;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.cappielloantonio.play.App;
|
import com.cappielloantonio.play.App;
|
||||||
|
import com.cappielloantonio.play.subsonic.RetrofitClient;
|
||||||
import com.cappielloantonio.play.subsonic.Subsonic;
|
import com.cappielloantonio.play.subsonic.Subsonic;
|
||||||
import com.cappielloantonio.play.subsonic.base.ApiResponse;
|
import com.cappielloantonio.play.subsonic.base.ApiResponse;
|
||||||
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
||||||
|
|
@ -26,14 +27,7 @@ public class PlaylistClient {
|
||||||
|
|
||||||
public PlaylistClient(Subsonic subsonic) {
|
public PlaylistClient(Subsonic subsonic) {
|
||||||
this.subsonic = subsonic;
|
this.subsonic = subsonic;
|
||||||
|
this.playlistService = new RetrofitClient(subsonic).getRetrofit().create(PlaylistService.class);
|
||||||
Retrofit retrofit = new Retrofit.Builder()
|
|
||||||
.baseUrl(subsonic.getUrl())
|
|
||||||
.addConverterFactory(GsonConverterFactory.create(new GsonBuilder().setLenient().create()))
|
|
||||||
.client(getOkHttpClient())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
this.playlistService = retrofit.create(PlaylistService.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Call<ApiResponse> getPlaylists() {
|
public Call<ApiResponse> getPlaylists() {
|
||||||
|
|
@ -60,30 +54,4 @@ public class PlaylistClient {
|
||||||
Log.d(TAG, "deletePlaylist()");
|
Log.d(TAG, "deletePlaylist()");
|
||||||
return playlistService.deletePlaylist(subsonic.getParams(), id);
|
return playlistService.deletePlaylist(subsonic.getParams(), id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private OkHttpClient getOkHttpClient() {
|
|
||||||
CacheUtil cacheUtil = new CacheUtil(0, 60 * 60 * 24 * 30);
|
|
||||||
|
|
||||||
return new OkHttpClient.Builder()
|
|
||||||
.callTimeout(2, TimeUnit.MINUTES)
|
|
||||||
.connectTimeout(20, TimeUnit.SECONDS)
|
|
||||||
.readTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.writeTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.addInterceptor(getHttpLoggingInterceptor())
|
|
||||||
.addInterceptor(cacheUtil.offlineInterceptor)
|
|
||||||
.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 new Cache(App.getContext().getCacheDir(), cacheSize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.cappielloantonio.play.subsonic.api.podcast;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.cappielloantonio.play.App;
|
import com.cappielloantonio.play.App;
|
||||||
|
import com.cappielloantonio.play.subsonic.RetrofitClient;
|
||||||
import com.cappielloantonio.play.subsonic.Subsonic;
|
import com.cappielloantonio.play.subsonic.Subsonic;
|
||||||
import com.cappielloantonio.play.subsonic.base.ApiResponse;
|
import com.cappielloantonio.play.subsonic.base.ApiResponse;
|
||||||
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
||||||
|
|
@ -25,14 +26,7 @@ public class PodcastClient {
|
||||||
|
|
||||||
public PodcastClient(Subsonic subsonic) {
|
public PodcastClient(Subsonic subsonic) {
|
||||||
this.subsonic = subsonic;
|
this.subsonic = subsonic;
|
||||||
|
this.podcastService = new RetrofitClient(subsonic).getRetrofit().create(PodcastService.class);
|
||||||
Retrofit retrofit = new Retrofit.Builder()
|
|
||||||
.baseUrl(subsonic.getUrl())
|
|
||||||
.addConverterFactory(GsonConverterFactory.create(new GsonBuilder().setLenient().create()))
|
|
||||||
.client(getOkHttpClient())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
this.podcastService = retrofit.create(PodcastService.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Call<ApiResponse> getPodcasts(boolean includeEpisodes, String channelId) {
|
public Call<ApiResponse> getPodcasts(boolean includeEpisodes, String channelId) {
|
||||||
|
|
@ -49,31 +43,4 @@ public class PodcastClient {
|
||||||
Log.d(TAG, "refreshPodcasts()");
|
Log.d(TAG, "refreshPodcasts()");
|
||||||
return podcastService.refreshPodcasts(subsonic.getParams());
|
return podcastService.refreshPodcasts(subsonic.getParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
private OkHttpClient getOkHttpClient() {
|
|
||||||
CacheUtil cacheUtil = new CacheUtil(60, 60 * 60 * 24 * 30);
|
|
||||||
|
|
||||||
return new OkHttpClient.Builder()
|
|
||||||
.callTimeout(2, TimeUnit.MINUTES)
|
|
||||||
.connectTimeout(20, TimeUnit.SECONDS)
|
|
||||||
.readTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.writeTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.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 new Cache(App.getContext().getCacheDir(), cacheSize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.cappielloantonio.play.subsonic.api.searching;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.cappielloantonio.play.App;
|
import com.cappielloantonio.play.App;
|
||||||
|
import com.cappielloantonio.play.subsonic.RetrofitClient;
|
||||||
import com.cappielloantonio.play.subsonic.Subsonic;
|
import com.cappielloantonio.play.subsonic.Subsonic;
|
||||||
import com.cappielloantonio.play.subsonic.base.ApiResponse;
|
import com.cappielloantonio.play.subsonic.base.ApiResponse;
|
||||||
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
||||||
|
|
@ -25,14 +26,7 @@ public class SearchingClient {
|
||||||
|
|
||||||
public SearchingClient(Subsonic subsonic) {
|
public SearchingClient(Subsonic subsonic) {
|
||||||
this.subsonic = subsonic;
|
this.subsonic = subsonic;
|
||||||
|
this.searchingService = new RetrofitClient(subsonic).getRetrofit().create(SearchingService.class);
|
||||||
Retrofit retrofit = new Retrofit.Builder()
|
|
||||||
.baseUrl(subsonic.getUrl())
|
|
||||||
.addConverterFactory(GsonConverterFactory.create(new GsonBuilder().setLenient().create()))
|
|
||||||
.client(getOkHttpClient())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
this.searchingService = retrofit.create(SearchingService.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Call<ApiResponse> search2(String query, int songCount, int albumCount, int artistCount) {
|
public Call<ApiResponse> search2(String query, int songCount, int albumCount, int artistCount) {
|
||||||
|
|
@ -44,31 +38,4 @@ public class SearchingClient {
|
||||||
Log.d(TAG, "search3()");
|
Log.d(TAG, "search3()");
|
||||||
return searchingService.search3(subsonic.getParams(), query, songCount, albumCount, artistCount);
|
return searchingService.search3(subsonic.getParams(), query, songCount, albumCount, artistCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
private OkHttpClient getOkHttpClient() {
|
|
||||||
CacheUtil cacheUtil = new CacheUtil(60, 60 * 60 * 24 * 30);
|
|
||||||
|
|
||||||
return new OkHttpClient.Builder()
|
|
||||||
.callTimeout(2, TimeUnit.MINUTES)
|
|
||||||
.connectTimeout(20, TimeUnit.SECONDS)
|
|
||||||
.readTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.writeTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.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 new Cache(App.getContext().getCacheDir(), cacheSize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.cappielloantonio.play.subsonic.api.system;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.cappielloantonio.play.App;
|
import com.cappielloantonio.play.App;
|
||||||
|
import com.cappielloantonio.play.subsonic.RetrofitClient;
|
||||||
import com.cappielloantonio.play.subsonic.Subsonic;
|
import com.cappielloantonio.play.subsonic.Subsonic;
|
||||||
import com.cappielloantonio.play.subsonic.base.ApiResponse;
|
import com.cappielloantonio.play.subsonic.base.ApiResponse;
|
||||||
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
||||||
|
|
@ -25,14 +26,7 @@ public class SystemClient {
|
||||||
|
|
||||||
public SystemClient(Subsonic subsonic) {
|
public SystemClient(Subsonic subsonic) {
|
||||||
this.subsonic = subsonic;
|
this.subsonic = subsonic;
|
||||||
|
this.systemService = new RetrofitClient(subsonic).getRetrofit().create(SystemService.class);
|
||||||
Retrofit retrofit = new Retrofit.Builder()
|
|
||||||
.baseUrl(subsonic.getUrl())
|
|
||||||
.addConverterFactory(GsonConverterFactory.create(new GsonBuilder().setLenient().create()))
|
|
||||||
.client(getOkHttpClient())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
this.systemService = retrofit.create(SystemService.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Call<ApiResponse> ping() {
|
public Call<ApiResponse> ping() {
|
||||||
|
|
@ -44,31 +38,4 @@ public class SystemClient {
|
||||||
Log.d(TAG, "getLicense()");
|
Log.d(TAG, "getLicense()");
|
||||||
return systemService.getLicense(subsonic.getParams());
|
return systemService.getLicense(subsonic.getParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
private OkHttpClient getOkHttpClient() {
|
|
||||||
CacheUtil cacheUtil = new CacheUtil(0, 60 * 60 * 24 * 30);
|
|
||||||
|
|
||||||
return new OkHttpClient.Builder()
|
|
||||||
.callTimeout(2, TimeUnit.MINUTES)
|
|
||||||
.connectTimeout(20, TimeUnit.SECONDS)
|
|
||||||
.readTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.writeTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.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 new Cache(App.getContext().getCacheDir(), cacheSize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue