mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 09:53:33 +00:00
feat: check and save usable OpenSubsonic APIs
This commit is contained in:
parent
234c9a10d2
commit
b9462d7374
5 changed files with 65 additions and 7 deletions
|
|
@ -6,7 +6,11 @@ import androidx.lifecycle.MutableLiveData;
|
||||||
import com.cappielloantonio.tempo.App;
|
import com.cappielloantonio.tempo.App;
|
||||||
import com.cappielloantonio.tempo.interfaces.SystemCallback;
|
import com.cappielloantonio.tempo.interfaces.SystemCallback;
|
||||||
import com.cappielloantonio.tempo.subsonic.base.ApiResponse;
|
import com.cappielloantonio.tempo.subsonic.base.ApiResponse;
|
||||||
|
import com.cappielloantonio.tempo.subsonic.models.OpenSubsonicExtension;
|
||||||
import com.cappielloantonio.tempo.subsonic.models.ResponseStatus;
|
import com.cappielloantonio.tempo.subsonic.models.ResponseStatus;
|
||||||
|
import com.cappielloantonio.tempo.subsonic.models.SubsonicResponse;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
|
|
@ -43,8 +47,8 @@ public class SystemRepository {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public MutableLiveData<Boolean> ping() {
|
public MutableLiveData<SubsonicResponse> ping() {
|
||||||
MutableLiveData<Boolean> pingResult = new MutableLiveData<>();
|
MutableLiveData<SubsonicResponse> pingResult = new MutableLiveData<>();
|
||||||
|
|
||||||
App.getSubsonicClientInstance(false)
|
App.getSubsonicClientInstance(false)
|
||||||
.getSystemClient()
|
.getSystemClient()
|
||||||
|
|
@ -53,16 +57,39 @@ public class SystemRepository {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<ApiResponse> call, @NonNull Response<ApiResponse> response) {
|
public void onResponse(@NonNull Call<ApiResponse> call, @NonNull Response<ApiResponse> response) {
|
||||||
if (response.isSuccessful() && response.body() != null) {
|
if (response.isSuccessful() && response.body() != null) {
|
||||||
pingResult.postValue(true);
|
pingResult.postValue(response.body().getSubsonicResponse());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<ApiResponse> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<ApiResponse> call, @NonNull Throwable t) {
|
||||||
pingResult.postValue(false);
|
pingResult.postValue(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return pingResult;
|
return pingResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MutableLiveData<List<OpenSubsonicExtension>> getOpenSubsonicExtensions() {
|
||||||
|
MutableLiveData<List<OpenSubsonicExtension>> extensionsResult = new MutableLiveData<>();
|
||||||
|
|
||||||
|
App.getSubsonicClientInstance(false)
|
||||||
|
.getSystemClient()
|
||||||
|
.getOpenSubsonicExtensions()
|
||||||
|
.enqueue(new Callback<ApiResponse>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<ApiResponse> call, @NonNull Response<ApiResponse> response) {
|
||||||
|
if (response.isSuccessful() && response.body() != null) {
|
||||||
|
extensionsResult.postValue(response.body().getSubsonicResponse().getOpenSubsonicExtensions());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<ApiResponse> call, @NonNull Throwable t) {
|
||||||
|
extensionsResult.postValue(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return extensionsResult;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,4 +28,9 @@ public class SystemClient {
|
||||||
Log.d(TAG, "getLicense()");
|
Log.d(TAG, "getLicense()");
|
||||||
return systemService.getLicense(subsonic.getParams());
|
return systemService.getLicense(subsonic.getParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Call<ApiResponse> getOpenSubsonicExtensions() {
|
||||||
|
Log.d(TAG, "getOpenSubsonicExtensions()");
|
||||||
|
return systemService.getOpenSubsonicExtensions(subsonic.getParams());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,4 +14,7 @@ public interface SystemService {
|
||||||
|
|
||||||
@GET("getLicense")
|
@GET("getLicense")
|
||||||
Call<ApiResponse> getLicense(@QueryMap Map<String, String> params);
|
Call<ApiResponse> getLicense(@QueryMap Map<String, String> params);
|
||||||
|
|
||||||
|
@GET("getOpenSubsonicExtensions")
|
||||||
|
Call<ApiResponse> getOpenSubsonicExtensions(@QueryMap Map<String, String> params);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ public class MainActivity extends BaseActivity {
|
||||||
|
|
||||||
init();
|
init();
|
||||||
checkConnectionType();
|
checkConnectionType();
|
||||||
|
getOpenSubsonicExtensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -334,11 +335,25 @@ public class MainActivity extends BaseActivity {
|
||||||
|
|
||||||
private void pingServer() {
|
private void pingServer() {
|
||||||
if (Preferences.getToken() != null) {
|
if (Preferences.getToken() != null) {
|
||||||
mainViewModel.ping().observe(this, isPingSuccessfull -> {
|
mainViewModel.ping().observe(this, subsonicResponse -> {
|
||||||
if (!isPingSuccessfull && Preferences.showServerUnreachableDialog()) {
|
if (subsonicResponse == null && Preferences.showServerUnreachableDialog()) {
|
||||||
ServerUnreachableDialog dialog = new ServerUnreachableDialog();
|
ServerUnreachableDialog dialog = new ServerUnreachableDialog();
|
||||||
dialog.show(getSupportFragmentManager(), null);
|
dialog.show(getSupportFragmentManager(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (subsonicResponse != null) {
|
||||||
|
Preferences.setOpenSubsonic(subsonicResponse.getOpenSubsonic() != null && subsonicResponse.getOpenSubsonic());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getOpenSubsonicExtensions() {
|
||||||
|
if (Preferences.getToken() != null) {
|
||||||
|
mainViewModel.getOpenSubsonicExtensions().observe(this, openSubsonicExtensions -> {
|
||||||
|
if (openSubsonicExtensions != null) {
|
||||||
|
Preferences.setOpenSubsonicExtensions(openSubsonicExtensions);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,10 @@ import androidx.lifecycle.LiveData;
|
||||||
|
|
||||||
import com.cappielloantonio.tempo.repository.QueueRepository;
|
import com.cappielloantonio.tempo.repository.QueueRepository;
|
||||||
import com.cappielloantonio.tempo.repository.SystemRepository;
|
import com.cappielloantonio.tempo.repository.SystemRepository;
|
||||||
|
import com.cappielloantonio.tempo.subsonic.models.OpenSubsonicExtension;
|
||||||
|
import com.cappielloantonio.tempo.subsonic.models.SubsonicResponse;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class MainViewModel extends AndroidViewModel {
|
public class MainViewModel extends AndroidViewModel {
|
||||||
private static final String TAG = "SearchViewModel";
|
private static final String TAG = "SearchViewModel";
|
||||||
|
|
@ -25,7 +29,11 @@ public class MainViewModel extends AndroidViewModel {
|
||||||
return queueRepository.count() != 0;
|
return queueRepository.count() != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<Boolean> ping() {
|
public LiveData<SubsonicResponse> ping() {
|
||||||
return systemRepository.ping();
|
return systemRepository.ping();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LiveData<List<OpenSubsonicExtension>> getOpenSubsonicExtensions() {
|
||||||
|
return systemRepository.getOpenSubsonicExtensions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue