mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
Reinforced response checks on SearchingRepository
This commit is contained in:
parent
1dac0afa6f
commit
d8b0101d93
1 changed files with 36 additions and 28 deletions
|
|
@ -2,6 +2,7 @@ package com.cappielloantonio.play.repository;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
import com.cappielloantonio.play.App;
|
import com.cappielloantonio.play.App;
|
||||||
|
|
@ -14,7 +15,6 @@ import com.cappielloantonio.play.model.Song;
|
||||||
import com.cappielloantonio.play.subsonic.models.AlbumID3;
|
import com.cappielloantonio.play.subsonic.models.AlbumID3;
|
||||||
import com.cappielloantonio.play.subsonic.models.ArtistID3;
|
import com.cappielloantonio.play.subsonic.models.ArtistID3;
|
||||||
import com.cappielloantonio.play.subsonic.models.Child;
|
import com.cappielloantonio.play.subsonic.models.Child;
|
||||||
import com.cappielloantonio.play.subsonic.models.ResponseStatus;
|
|
||||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||||
import com.cappielloantonio.play.util.MappingUtil;
|
import com.cappielloantonio.play.util.MappingUtil;
|
||||||
|
|
||||||
|
|
@ -27,9 +27,8 @@ import retrofit2.Callback;
|
||||||
import retrofit2.Response;
|
import retrofit2.Response;
|
||||||
|
|
||||||
public class SearchingRepository {
|
public class SearchingRepository {
|
||||||
private RecentSearchDao recentSearchDao;
|
private final RecentSearchDao recentSearchDao;
|
||||||
|
private final Application application;
|
||||||
private Application application;
|
|
||||||
|
|
||||||
public SearchingRepository(Application application) {
|
public SearchingRepository(Application application) {
|
||||||
this.application = application;
|
this.application = application;
|
||||||
|
|
@ -46,15 +45,18 @@ public class SearchingRepository {
|
||||||
.search3(query, 20, 0, 0)
|
.search3(query, 20, 0, 0)
|
||||||
.enqueue(new Callback<SubsonicResponse>() {
|
.enqueue(new Callback<SubsonicResponse>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||||
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
|
List<Song> songs = new ArrayList<>();
|
||||||
List<Song> songs = new ArrayList<>(MappingUtil.mapSong(response.body().getSearchResult3().getSongs()));
|
|
||||||
searchedSongs.setValue(songs);
|
if(response.isSuccessful() && response.body() != null && response.body().getSearchResult3() != null) {
|
||||||
|
songs.addAll(MappingUtil.mapSong(response.body().getSearchResult3().getSongs()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
searchedSongs.setValue(songs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
public void onFailure(@NonNull Call<SubsonicResponse> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -70,15 +72,18 @@ public class SearchingRepository {
|
||||||
.search3(query, 0, 20, 0)
|
.search3(query, 0, 20, 0)
|
||||||
.enqueue(new Callback<SubsonicResponse>() {
|
.enqueue(new Callback<SubsonicResponse>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||||
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
|
List<Album> albums = new ArrayList<>();
|
||||||
List<Album> albums = new ArrayList<>(MappingUtil.mapAlbum(response.body().getSearchResult3().getAlbums()));
|
|
||||||
searchedAlbums.setValue(albums);
|
if(response.isSuccessful() && response.body() != null && response.body().getSearchResult3() != null) {
|
||||||
|
albums.addAll(MappingUtil.mapAlbum(response.body().getSearchResult3().getAlbums()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
searchedAlbums.setValue(albums);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
public void onFailure(@NonNull Call<SubsonicResponse> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -94,15 +99,18 @@ public class SearchingRepository {
|
||||||
.search3(query, 0, 0, 20)
|
.search3(query, 0, 0, 20)
|
||||||
.enqueue(new Callback<SubsonicResponse>() {
|
.enqueue(new Callback<SubsonicResponse>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||||
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
|
List<Artist> artists = new ArrayList<>();
|
||||||
List<Artist> artists = new ArrayList<>(MappingUtil.mapArtist(response.body().getSearchResult3().getArtists()));
|
|
||||||
searchedArtists.setValue(artists);
|
if(response.isSuccessful() && response.body() != null && response.body().getSearchResult3() != null) {
|
||||||
|
artists.addAll(MappingUtil.mapArtist(response.body().getSearchResult3().getArtists()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
searchedArtists.setValue(artists);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
public void onFailure(@NonNull Call<SubsonicResponse> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -118,10 +126,10 @@ public class SearchingRepository {
|
||||||
.search3(query, 5, 5, 5)
|
.search3(query, 5, 5, 5)
|
||||||
.enqueue(new Callback<SubsonicResponse>() {
|
.enqueue(new Callback<SubsonicResponse>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||||
List<String> newSuggestions = new ArrayList();
|
List<String> newSuggestions = new ArrayList();
|
||||||
|
|
||||||
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
|
if (response.isSuccessful() && response.body() != null) {
|
||||||
for (ArtistID3 artistID3 : response.body().getSearchResult3().getArtists()) {
|
for (ArtistID3 artistID3 : response.body().getSearchResult3().getArtists()) {
|
||||||
newSuggestions.add(artistID3.getName());
|
newSuggestions.add(artistID3.getName());
|
||||||
}
|
}
|
||||||
|
|
@ -142,7 +150,7 @@ public class SearchingRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
public void onFailure(@NonNull Call<SubsonicResponse> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -180,8 +188,8 @@ public class SearchingRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class DeleteThreadSafe implements Runnable {
|
private static class DeleteThreadSafe implements Runnable {
|
||||||
private RecentSearchDao recentSearchDao;
|
private final RecentSearchDao recentSearchDao;
|
||||||
private RecentSearch recentSearch;
|
private final RecentSearch recentSearch;
|
||||||
|
|
||||||
public DeleteThreadSafe(RecentSearchDao recentSearchDao, RecentSearch recentSearch) {
|
public DeleteThreadSafe(RecentSearchDao recentSearchDao, RecentSearch recentSearch) {
|
||||||
this.recentSearchDao = recentSearchDao;
|
this.recentSearchDao = recentSearchDao;
|
||||||
|
|
@ -195,8 +203,8 @@ public class SearchingRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class InsertThreadSafe implements Runnable {
|
private static class InsertThreadSafe implements Runnable {
|
||||||
private RecentSearchDao recentSearchDao;
|
private final RecentSearchDao recentSearchDao;
|
||||||
private RecentSearch recentSearch;
|
private final RecentSearch recentSearch;
|
||||||
|
|
||||||
public InsertThreadSafe(RecentSearchDao recentSearchDao, RecentSearch recentSearch) {
|
public InsertThreadSafe(RecentSearchDao recentSearchDao, RecentSearch recentSearch) {
|
||||||
this.recentSearchDao = recentSearchDao;
|
this.recentSearchDao = recentSearchDao;
|
||||||
|
|
@ -210,8 +218,8 @@ public class SearchingRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class RecentThreadSafe implements Runnable {
|
private static class RecentThreadSafe implements Runnable {
|
||||||
private RecentSearchDao recentSearchDao;
|
private final RecentSearchDao recentSearchDao;
|
||||||
private int limit;
|
private final int limit;
|
||||||
private List<String> recent = new ArrayList<>();
|
private List<String> recent = new ArrayList<>();
|
||||||
|
|
||||||
public RecentThreadSafe(RecentSearchDao recentSearchDao, int limit) {
|
public RecentThreadSafe(RecentSearchDao recentSearchDao, int limit) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue