Add dialog when server is unreachable

This commit is contained in:
CappielloAntonio 2021-09-04 21:14:43 +02:00
parent 652aa1426d
commit 33512eec2d
6 changed files with 141 additions and 2 deletions

View file

@ -3,6 +3,7 @@ package com.cappielloantonio.play.repository;
import android.app.Application;
import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
import com.cappielloantonio.play.App;
import com.cappielloantonio.play.interfaces.SystemCallback;
@ -11,6 +12,7 @@ import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class SystemRepository {
private static final String TAG = "SongRepository";
@ -49,4 +51,27 @@ public class SystemRepository {
}
});
}
public MutableLiveData<Boolean> ping() {
MutableLiveData<Boolean> pingResult = new MutableLiveData<>();
App.getSubsonicClientInstance(application, false)
.getSystemClient()
.ping()
.enqueue(new Callback<SubsonicResponse>() {
@Override
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
if (response.isSuccessful() && response.body() != null) {
pingResult.postValue(true);
}
}
@Override
public void onFailure(@NonNull Call<SubsonicResponse> call, @NonNull Throwable t) {
pingResult.postValue(false);
}
});
return pingResult;
}
}