mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-18 04:30:48 +01:00
Use new subsonic api method for getIndexes().
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
parent
b57a425e9d
commit
b02df33b9c
@ -56,6 +56,7 @@ import org.apache.http.protocol.ExecutionContext;
|
|||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
import org.moire.ultrasonic.R;
|
import org.moire.ultrasonic.R;
|
||||||
import org.moire.ultrasonic.api.subsonic.SubsonicAPIClient;
|
import org.moire.ultrasonic.api.subsonic.SubsonicAPIClient;
|
||||||
|
import org.moire.ultrasonic.api.subsonic.response.GetIndexesResponse;
|
||||||
import org.moire.ultrasonic.api.subsonic.response.LicenseResponse;
|
import org.moire.ultrasonic.api.subsonic.response.LicenseResponse;
|
||||||
import org.moire.ultrasonic.api.subsonic.response.MusicFoldersResponse;
|
import org.moire.ultrasonic.api.subsonic.response.MusicFoldersResponse;
|
||||||
import org.moire.ultrasonic.api.subsonic.response.SubsonicResponse;
|
import org.moire.ultrasonic.api.subsonic.response.SubsonicResponse;
|
||||||
@ -117,6 +118,7 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import retrofit2.Response;
|
import retrofit2.Response;
|
||||||
@ -232,60 +234,40 @@ public class RESTMusicService implements MusicService
|
|||||||
return musicFolders;
|
return musicFolders;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Indexes getIndexes(String musicFolderId, boolean refresh, Context context, ProgressListener progressListener) throws Exception
|
public Indexes getIndexes(String musicFolderId,
|
||||||
{
|
boolean refresh,
|
||||||
Indexes cachedIndexes = readCachedIndexes(context, musicFolderId);
|
Context context,
|
||||||
if (cachedIndexes != null && !refresh)
|
ProgressListener progressListener) throws Exception {
|
||||||
{
|
Indexes cachedIndexes = readCachedIndexes(context, musicFolderId);
|
||||||
return cachedIndexes;
|
if (cachedIndexes != null && !refresh) {
|
||||||
}
|
return cachedIndexes;
|
||||||
|
}
|
||||||
|
|
||||||
List<String> parameterNames = new ArrayList<String>();
|
updateProgressListener(progressListener, R.string.parser_reading);
|
||||||
List<Object> parameterValues = new ArrayList<Object>();
|
Response<GetIndexesResponse> response = subsonicAPIClient.getApi()
|
||||||
|
.getIndexes(musicFolderId == null ? null : Long.valueOf(musicFolderId), null).execute();
|
||||||
|
checkResponseSuccessful(response);
|
||||||
|
|
||||||
if (musicFolderId != null)
|
Indexes indexes = APIConverter.toDomainEntity(response.body().getIndexes());
|
||||||
{
|
writeCachedIndexes(context, indexes, musicFolderId);
|
||||||
parameterNames.add("musicFolderId");
|
return indexes;
|
||||||
parameterValues.add(musicFolderId);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Reader reader = getReader(context, progressListener, "getIndexes", null, parameterNames, parameterValues);
|
private static Indexes readCachedIndexes(Context context, String musicFolderId) {
|
||||||
|
String filename = getCachedIndexesFilename(context, musicFolderId);
|
||||||
|
return FileUtil.deserialize(context, filename);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
private static void writeCachedIndexes(Context context, Indexes indexes, String musicFolderId) {
|
||||||
{
|
String filename = getCachedIndexesFilename(context, musicFolderId);
|
||||||
Indexes indexes = new IndexesParser(context).parse(reader, progressListener);
|
FileUtil.serialize(context, indexes, filename);
|
||||||
if (indexes != null)
|
}
|
||||||
{
|
|
||||||
writeCachedIndexes(context, indexes, musicFolderId);
|
|
||||||
return indexes;
|
|
||||||
}
|
|
||||||
|
|
||||||
return cachedIndexes != null ? cachedIndexes : new Indexes(0, null, new ArrayList<org.moire.ultrasonic.domain.Artist>(), new ArrayList<org.moire.ultrasonic.domain.Artist>());
|
private static String getCachedIndexesFilename(Context context, String musicFolderId) {
|
||||||
}
|
String s = Util.getRestUrl(context, null) + musicFolderId;
|
||||||
finally
|
return String.format(Locale.US, "indexes-%d.ser", Math.abs(s.hashCode()));
|
||||||
{
|
}
|
||||||
Util.close(reader);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Indexes readCachedIndexes(Context context, String musicFolderId)
|
|
||||||
{
|
|
||||||
String filename = getCachedIndexesFilename(context, musicFolderId);
|
|
||||||
return FileUtil.deserialize(context, filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void writeCachedIndexes(Context context, Indexes indexes, String musicFolderId)
|
|
||||||
{
|
|
||||||
String filename = getCachedIndexesFilename(context, musicFolderId);
|
|
||||||
FileUtil.serialize(context, indexes, filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getCachedIndexesFilename(Context context, String musicFolderId)
|
|
||||||
{
|
|
||||||
String s = Util.getRestUrl(context, null) + musicFolderId;
|
|
||||||
return String.format("indexes-%d.ser", Math.abs(s.hashCode()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Indexes getArtists(boolean refresh, Context context, ProgressListener progressListener) throws Exception
|
public Indexes getArtists(boolean refresh, Context context, ProgressListener progressListener) throws Exception
|
||||||
|
Loading…
x
Reference in New Issue
Block a user