mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-02 10:23:33 +00:00
Fix app asking for credential on every startup
This commit is contained in:
parent
a21a051cb5
commit
7bd2b10165
6 changed files with 116 additions and 52 deletions
|
|
@ -0,0 +1,46 @@
|
|||
package com.cappielloantonio.play.repository;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.interfaces.SystemCallback;
|
||||
import com.cappielloantonio.play.subsonic.api.system.SystemClient;
|
||||
import com.cappielloantonio.play.subsonic.models.ResponseStatus;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
|
||||
public class SystemRepository {
|
||||
private static final String TAG = "SongRepository";
|
||||
|
||||
private SystemClient systemClient;
|
||||
|
||||
public SystemRepository(Application application) {
|
||||
systemClient = App.getSubsonicClientInstance(application, false).getSystemClient();
|
||||
}
|
||||
|
||||
public void checkUserCredential(SystemCallback callback) {
|
||||
systemClient
|
||||
.ping()
|
||||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(Call<SubsonicResponse> call, retrofit2.Response<SubsonicResponse> response) {
|
||||
if (response.body().getStatus().getValue().equals(ResponseStatus.FAILED)) {
|
||||
callback.onError(new Exception(response.body().getError().getCode().getValue() + " - " + response.body().getError().getMessage()));
|
||||
} else if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
|
||||
String salt = response.raw().request().url().queryParameter("s");
|
||||
String token = response.raw().request().url().queryParameter("t");
|
||||
callback.onSuccess(token, salt);
|
||||
} else {
|
||||
callback.onError(new Exception("Empty response"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
||||
callback.onError(new Exception(t.getMessage()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue