From 1dac0afa6f3b5dc0a6d33575d7b72ac7c42153f1 Mon Sep 17 00:00:00 2001 From: CappielloAntonio Date: Tue, 24 Aug 2021 13:12:54 +0200 Subject: [PATCH] Reinforced response checks on ScanRepository --- .../play/repository/ScanRepository.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/cappielloantonio/play/repository/ScanRepository.java b/app/src/main/java/com/cappielloantonio/play/repository/ScanRepository.java index e0e864a6..17ef6bf7 100644 --- a/app/src/main/java/com/cappielloantonio/play/repository/ScanRepository.java +++ b/app/src/main/java/com/cappielloantonio/play/repository/ScanRepository.java @@ -2,10 +2,10 @@ package com.cappielloantonio.play.repository; import android.app.Application; +import androidx.annotation.NonNull; + import com.cappielloantonio.play.App; import com.cappielloantonio.play.interfaces.ScanCallback; -import com.cappielloantonio.play.interfaces.SystemCallback; -import com.cappielloantonio.play.subsonic.models.ResponseStatus; import com.cappielloantonio.play.subsonic.models.SubsonicResponse; import retrofit2.Call; @@ -14,7 +14,7 @@ import retrofit2.Callback; public class ScanRepository { private static final String TAG = "SongRepository"; - private Application application; + private final Application application; public ScanRepository(Application application) { this.application = application; @@ -26,14 +26,14 @@ public class ScanRepository { .startScan() .enqueue(new Callback() { @Override - public void onResponse(Call call, retrofit2.Response response) { - if (response.body().getScanStatus() != null) { + public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { + if (response.isSuccessful() && response.body() != null && response.body().getScanStatus() != null) { callback.onSuccess(response.body().getScanStatus().isScanning(), response.body().getScanStatus().getCount()); } } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(@NonNull Call call, @NonNull Throwable t) { callback.onError(new Exception(t.getMessage())); } }); @@ -45,14 +45,14 @@ public class ScanRepository { .startScan() .enqueue(new Callback() { @Override - public void onResponse(Call call, retrofit2.Response response) { - if (response.body().getScanStatus() != null) { + public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { + if (response.isSuccessful() && response.body() != null && response.body().getScanStatus() != null) { callback.onSuccess(response.body().getScanStatus().isScanning(), response.body().getScanStatus().getCount()); } } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(@NonNull Call call, @NonNull Throwable t) { callback.onError(new Exception(t.getMessage())); } });