public void loadMyMuvi(){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://192.168.0.105:8000")
.addConverterFactory(GsonConverterFactory.create())
.build();
final MyApiRequestInterface request = retrofit.create(MyApiRequestInterface.class);
Call<MyMuviResponse> call = request.getMyMuvi();
call.enqueue(new Callback<MyMuviResponse>() {
@Override
public void onResponse(Call<MyMuviResponse> call, Response<MyMuviResponse> response) {
MyMuviResponse myMuviResponse = response.body();
if (myMuviResponse.getStatus() == "true") {
data = new ArrayList<>(Arrays.asList(myMuviResponse.getMyMuvi()));
} else {
Log.d(TAG, "нет данных по запросу");
}
}
@Override
public void onFailure(Call<MyMuviResponse> call, Throwable t) {
Log.d("Error", t.getMessage());
}
});
}
@Override
public Response load(Uri uri, int networkPolicy) throws IOException {
final AtomicReference<Object> notifier = new AtomicReference<>();
serverId = "https://" + Utils.API_SERVER_HTTP + "/download/" + serverId;
fileDownloader = new FileDownloader(serverId, outPath, true, new FileDownloader.IFileDownloaderListener() {
@Override
public void onProgress(int progress) {
}
@Override
public void onSuccess() {
synchronized (notifier) {
try {
notifier.set(new Response(decodeBitmap(outPath), false));
} catch (Exception ex) {
ex.printStackTrace();
notifier.set(new Exception());
} finally {
notifier.notify();
}
}
}
@Override
public void onError() {
synchronized (notifier) {
notifier.set(new Exception());
notifier.notify();
}
}
}, staticHandler);
fileDownloader.execute();
synchronized (notifier) {
try {
while (notifier.get() == null)
notifier.wait();
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (notifier.get() instanceof Exception)
{
throw new ResponseException("File cannot be downloaded", 0, 404);
}
return (Response) notifier.get();
}