mirror of
https://github.com/cmclark00/RetroMusicPlayer.git
synced 2025-05-20 00:55:20 +01:00
Layoit fixes
This commit is contained in:
parent
636da3daa8
commit
fdb2ab300e
46 changed files with 594 additions and 1346 deletions
|
@ -15,20 +15,18 @@
|
|||
package code.name.monkey.retromusic.rest;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import code.name.monkey.retromusic.rest.service.LastFMService;
|
||||
import java.io.File;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import code.name.monkey.retromusic.rest.service.LastFMService;
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.ConnectionPool;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
|
@ -53,13 +51,9 @@ public class LastFMRestClient {
|
|||
apiService = restAdapter.create(LastFMService.class);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Cache createDefaultCache(Context context) {
|
||||
File cacheDir = new File(context.getCacheDir().getAbsolutePath(), "/okhttp-lastfm/");
|
||||
if (cacheDir.mkdirs() || cacheDir.isDirectory()) {
|
||||
return new Cache(cacheDir, 1024 * 1024 * 10);
|
||||
}
|
||||
return null;
|
||||
@NonNull
|
||||
public LastFMService getApiService() {
|
||||
return apiService;
|
||||
}
|
||||
|
||||
private static Interceptor createCacheControlInterceptor() {
|
||||
|
@ -71,6 +65,15 @@ public class LastFMRestClient {
|
|||
};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Cache createDefaultCache(Context context) {
|
||||
File cacheDir = new File(context.getCacheDir().getAbsolutePath(), "/okhttp-lastfm/");
|
||||
if (cacheDir.mkdirs() || cacheDir.isDirectory()) {
|
||||
return new Cache(cacheDir, 1024 * 1024 * 10);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static OkHttpClient.Builder createDefaultOkHttpClientBuilder(@NonNull Context context) {
|
||||
return new OkHttpClient.Builder()
|
||||
|
@ -80,11 +83,14 @@ public class LastFMRestClient {
|
|||
.writeTimeout(1, TimeUnit.MINUTES) // write timeout
|
||||
.readTimeout(1, TimeUnit.MINUTES) // read timeout
|
||||
.cache(createDefaultCache(context))
|
||||
.addInterceptor(createCacheControlInterceptor());
|
||||
.addInterceptor(createCacheControlInterceptor())
|
||||
.addInterceptor(createLogInterceptor());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public LastFMService getApiService() {
|
||||
return apiService;
|
||||
private static Interceptor createLogInterceptor() {
|
||||
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
|
||||
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
return interceptor;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,65 +16,22 @@ package code.name.monkey.retromusic.rest.model;
|
|||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LastFmAlbum {
|
||||
@Expose
|
||||
private Album album;
|
||||
|
||||
public Album getAlbum() {
|
||||
return album;
|
||||
}
|
||||
|
||||
public void setAlbum(Album album) {
|
||||
this.album = album;
|
||||
}
|
||||
|
||||
public static class Album {
|
||||
@Expose
|
||||
private Tags tags;
|
||||
@Expose
|
||||
private List<Image> image = new ArrayList<>();
|
||||
@Expose
|
||||
private Wiki wiki;
|
||||
|
||||
public List<Image> getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(List<Image> image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public Wiki getWiki() {
|
||||
return wiki;
|
||||
}
|
||||
|
||||
public void setWiki(Wiki wiki) {
|
||||
this.wiki = wiki;
|
||||
}
|
||||
|
||||
public Tags getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public static class Image {
|
||||
|
||||
@SerializedName("#text")
|
||||
@Expose
|
||||
private String Text;
|
||||
|
||||
@Expose
|
||||
private String size;
|
||||
|
||||
public String getText() {
|
||||
return Text;
|
||||
}
|
||||
|
||||
public void setText(String Text) {
|
||||
this.Text = Text;
|
||||
}
|
||||
|
||||
public String getSize() {
|
||||
return size;
|
||||
}
|
||||
|
@ -82,9 +39,18 @@ public class LastFmAlbum {
|
|||
public void setSize(String size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return Text;
|
||||
}
|
||||
|
||||
public void setText(String Text) {
|
||||
this.Text = Text;
|
||||
}
|
||||
}
|
||||
|
||||
public class Tags {
|
||||
|
||||
@Expose
|
||||
private List<Tag> tag = null;
|
||||
|
||||
|
@ -94,6 +60,7 @@ public class LastFmAlbum {
|
|||
}
|
||||
|
||||
public class Tag {
|
||||
|
||||
@Expose
|
||||
private String name;
|
||||
|
||||
|
@ -110,9 +77,13 @@ public class LastFmAlbum {
|
|||
}
|
||||
|
||||
public class Wiki {
|
||||
|
||||
@Expose
|
||||
private String content;
|
||||
|
||||
@Expose
|
||||
private String published;
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
@ -120,6 +91,87 @@ public class LastFmAlbum {
|
|||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getPublished() {
|
||||
return published;
|
||||
}
|
||||
|
||||
public void setPublished(final String published) {
|
||||
this.published = published;
|
||||
}
|
||||
}
|
||||
|
||||
@Expose
|
||||
public String listeners;
|
||||
|
||||
@Expose
|
||||
public String playcount;
|
||||
|
||||
@Expose
|
||||
private List<Image> image = new ArrayList<>();
|
||||
|
||||
@Expose
|
||||
private String name;
|
||||
|
||||
@Expose
|
||||
private Tags tags;
|
||||
|
||||
@Expose
|
||||
private Wiki wiki;
|
||||
|
||||
public List<Image> getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(List<Image> image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public String getListeners() {
|
||||
return listeners;
|
||||
}
|
||||
|
||||
public void setListeners(final String listeners) {
|
||||
this.listeners = listeners;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getPlaycount() {
|
||||
return playcount;
|
||||
}
|
||||
|
||||
public void setPlaycount(final String playcount) {
|
||||
this.playcount = playcount;
|
||||
}
|
||||
|
||||
public Tags getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public Wiki getWiki() {
|
||||
return wiki;
|
||||
}
|
||||
|
||||
public void setWiki(Wiki wiki) {
|
||||
this.wiki = wiki;
|
||||
}
|
||||
}
|
||||
|
||||
@Expose
|
||||
private Album album;
|
||||
|
||||
public Album getAlbum() {
|
||||
return album;
|
||||
}
|
||||
|
||||
public void setAlbum(Album album) {
|
||||
this.album = album;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,45 +16,66 @@ package code.name.monkey.retromusic.rest.model;
|
|||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LastFmArtist {
|
||||
@Expose
|
||||
private Artist artist;
|
||||
|
||||
public Artist getArtist() {
|
||||
return artist;
|
||||
}
|
||||
|
||||
public void setArtist(Artist artist) {
|
||||
this.artist = artist;
|
||||
}
|
||||
|
||||
public static class Artist {
|
||||
@Expose
|
||||
private List<Image> image = new ArrayList<>();
|
||||
@Expose
|
||||
private Bio bio;
|
||||
|
||||
public List<Image> getImage() {
|
||||
return image;
|
||||
public static class Image {
|
||||
|
||||
@SerializedName("#text")
|
||||
@Expose
|
||||
private String Text;
|
||||
|
||||
@Expose
|
||||
private String size;
|
||||
|
||||
public String getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(String size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return Text;
|
||||
}
|
||||
|
||||
public void setText(String Text) {
|
||||
this.Text = Text;
|
||||
}
|
||||
}
|
||||
|
||||
public void setImage(List<Image> image) {
|
||||
this.image = image;
|
||||
}
|
||||
public static class Stats {
|
||||
|
||||
public Bio getBio() {
|
||||
return bio;
|
||||
}
|
||||
@Expose
|
||||
public String listeners;
|
||||
|
||||
public void setBio(Bio bio) {
|
||||
this.bio = bio;
|
||||
@Expose
|
||||
public String playcount;
|
||||
|
||||
public String getListeners() {
|
||||
return listeners;
|
||||
}
|
||||
|
||||
public void setListeners(final String listeners) {
|
||||
this.listeners = listeners;
|
||||
}
|
||||
|
||||
public String getPlaycount() {
|
||||
return playcount;
|
||||
}
|
||||
|
||||
public void setPlaycount(final String playcount) {
|
||||
this.playcount = playcount;
|
||||
}
|
||||
}
|
||||
|
||||
public class Bio {
|
||||
|
||||
@Expose
|
||||
private String content;
|
||||
|
||||
|
@ -67,28 +88,40 @@ public class LastFmArtist {
|
|||
}
|
||||
}
|
||||
|
||||
public static class Image {
|
||||
@SerializedName("#text")
|
||||
@Expose
|
||||
private String Text;
|
||||
@Expose
|
||||
private String size;
|
||||
@Expose
|
||||
public Stats stats;
|
||||
|
||||
public String getText() {
|
||||
return Text;
|
||||
}
|
||||
@Expose
|
||||
private Bio bio;
|
||||
|
||||
public void setText(String Text) {
|
||||
this.Text = Text;
|
||||
}
|
||||
@Expose
|
||||
private List<Image> image = new ArrayList<>();
|
||||
|
||||
public String getSize() {
|
||||
return size;
|
||||
}
|
||||
public Bio getBio() {
|
||||
return bio;
|
||||
}
|
||||
|
||||
public void setSize(String size) {
|
||||
this.size = size;
|
||||
}
|
||||
public void setBio(Bio bio) {
|
||||
this.bio = bio;
|
||||
}
|
||||
|
||||
public List<Image> getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(List<Image> image) {
|
||||
this.image = image;
|
||||
}
|
||||
}
|
||||
|
||||
@Expose
|
||||
private Artist artist;
|
||||
|
||||
public Artist getArtist() {
|
||||
return artist;
|
||||
}
|
||||
|
||||
public void setArtist(Artist artist) {
|
||||
this.artist = artist;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
package code.name.monkey.retromusic.rest.service
|
||||
|
||||
import code.name.monkey.retromusic.rest.model.LastFmAlbum
|
||||
import code.name.monkey.retromusic.rest.model.LastFmArtist
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Header
|
||||
|
@ -24,14 +25,22 @@ import retrofit2.http.Query
|
|||
*/
|
||||
|
||||
interface LastFMService {
|
||||
|
||||
companion object {
|
||||
const val API_KEY = "c679c8d3efa84613dc7dcb2e8d42da4c"
|
||||
const val BASE_QUERY_PARAMETERS = "?format=json&autocorrect=1&api_key=$API_KEY"
|
||||
}
|
||||
|
||||
@GET("$BASE_QUERY_PARAMETERS&method=artist.getinfo")
|
||||
suspend fun artistInfo(@Query("artist") artistName: String,
|
||||
@Query("lang") language: String?,
|
||||
@Header("Cache-Control") cacheControl: String?
|
||||
suspend fun artistInfo(
|
||||
@Query("artist") artistName: String,
|
||||
@Query("lang") language: String?,
|
||||
@Header("Cache-Control") cacheControl: String?
|
||||
): LastFmArtist
|
||||
|
||||
@GET("$BASE_QUERY_PARAMETERS&method=album.getinfo")
|
||||
suspend fun albumInfo(
|
||||
@Query("artist") artistName: String,
|
||||
@Query("album") albumName: String
|
||||
): LastFmAlbum
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue