mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Strict check on onResponse
This commit is contained in:
parent
67895494e6
commit
5c4a348e28
1 changed files with 10 additions and 12 deletions
|
|
@ -14,12 +14,11 @@ import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import com.cappielloantonio.play.App;
|
import com.cappielloantonio.play.App;
|
||||||
import com.cappielloantonio.play.databinding.FragmentLoginBinding;
|
import com.cappielloantonio.play.databinding.FragmentLoginBinding;
|
||||||
|
import com.cappielloantonio.play.subsonic.models.ResponseStatus;
|
||||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
|
|
||||||
|
|
@ -85,26 +84,25 @@ public class LoginFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void authenticate() {
|
private void authenticate() {
|
||||||
App.getSubsonicClientInstance(requireContext())
|
App.getSubsonicClientInstance(requireContext(), true)
|
||||||
.getSystemClient()
|
.getSystemClient()
|
||||||
.ping()
|
.ping()
|
||||||
.enqueue(new Callback<SubsonicResponse>() {
|
.enqueue(new Callback<SubsonicResponse>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<SubsonicResponse> call, retrofit2.Response<SubsonicResponse> response) {
|
public void onResponse(Call<SubsonicResponse> call, retrofit2.Response<SubsonicResponse> response) {
|
||||||
if (!response.isSuccessful()) {
|
if (response.body().getStatus() == ResponseStatus.FAILED) {
|
||||||
Log.d(TAG, "+++ onResponse() unsuccesful");
|
int code = response.body().getError().getCode().value();
|
||||||
Log.d(TAG, "+++ " + response.message());
|
String message = response.body().getError().getMessage();
|
||||||
Toast.makeText(requireContext(), response.message(), Toast.LENGTH_LONG).show();
|
Toast.makeText(requireContext(), code + " - " + message, Toast.LENGTH_LONG).show();
|
||||||
return;
|
} else if (response.body().getStatus() == ResponseStatus.OK) {
|
||||||
|
Toast.makeText(requireContext(), response.body().getStatus().value(), Toast.LENGTH_LONG).show();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(requireContext(), "Empty response", Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d(TAG, "+++ onResponse() succesful");
|
|
||||||
Toast.makeText(requireContext(), "Login succesful", Toast.LENGTH_LONG).show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
||||||
Log.d(TAG, "+++ onFailure()");
|
|
||||||
Log.d(TAG, "+++ " + t.getMessage());
|
Log.d(TAG, "+++ " + t.getMessage());
|
||||||
Toast.makeText(requireContext(), t.getMessage(), Toast.LENGTH_LONG).show();
|
Toast.makeText(requireContext(), t.getMessage(), Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue