|
3 | 3 | import android.graphics.BitmapFactory; |
4 | 4 | import android.graphics.Color; |
5 | 5 | import android.os.Bundle; |
6 | | -import androidx.annotation.NonNull; |
7 | | -import androidx.appcompat.app.AppCompatActivity; |
8 | 6 | import android.widget.Toast; |
9 | 7 |
|
10 | 8 | import com.mapbox.api.directions.v5.DirectionsCriteria; |
|
29 | 27 | import java.util.ArrayList; |
30 | 28 | import java.util.List; |
31 | 29 |
|
| 30 | +import androidx.annotation.NonNull; |
| 31 | +import androidx.appcompat.app.AppCompatActivity; |
32 | 32 | import retrofit2.Call; |
33 | 33 | import retrofit2.Callback; |
34 | 34 | import retrofit2.Response; |
@@ -113,7 +113,7 @@ private void initMarkerIconSymbolLayer(@NonNull Style loadedMapStyle) { |
113 | 113 | iconSize(1f), |
114 | 114 | iconAllowOverlap(true), |
115 | 115 | iconIgnorePlacement(true), |
116 | | - iconOffset(new Float[] {0f, -4f}) |
| 116 | + iconOffset(new Float[] {0f, -7f}) |
117 | 117 | )); |
118 | 118 | } |
119 | 119 |
|
@@ -212,22 +212,32 @@ private void getOptimizedRoute(@NonNull final Style style, List<Point> coordinat |
212 | 212 | @Override |
213 | 213 | public void onResponse(Call<OptimizationResponse> call, Response<OptimizationResponse> response) { |
214 | 214 | if (!response.isSuccessful()) { |
215 | | - Timber.d( getString(R.string.no_success)); |
| 215 | + Timber.d(getString(R.string.no_success)); |
216 | 216 | Toast.makeText(OptimizationActivity.this, R.string.no_success, Toast.LENGTH_SHORT).show(); |
217 | | - return; |
218 | 217 | } else { |
219 | | - if (response.body().trips().isEmpty()) { |
220 | | - Timber.d("%s size = %s", getString(R.string.successful_but_no_routes), response.body().trips().size()); |
221 | | - |
222 | | - Toast.makeText(OptimizationActivity.this, R.string.successful_but_no_routes, |
223 | | - Toast.LENGTH_SHORT).show(); |
224 | | - return; |
| 218 | + if (response.body() != null) { |
| 219 | + List<DirectionsRoute> routes = response.body().trips(); |
| 220 | + if (routes != null) { |
| 221 | + if (routes.isEmpty()) { |
| 222 | + Timber.d("%s size = %s", getString(R.string.successful_but_no_routes), routes.size()); |
| 223 | + Toast.makeText(OptimizationActivity.this, R.string.successful_but_no_routes, |
| 224 | + Toast.LENGTH_SHORT).show(); |
| 225 | + } else { |
| 226 | + // Get most optimized route from API response |
| 227 | + optimizedRoute = routes.get(0); |
| 228 | + drawOptimizedRoute(style, optimizedRoute); |
| 229 | + } |
| 230 | + } else { |
| 231 | + Timber.d("list of routes in the response is null"); |
| 232 | + Toast.makeText(OptimizationActivity.this, String.format(getString(R.string.null_in_response), |
| 233 | + "The Optimization API response's list of routes"), Toast.LENGTH_SHORT).show(); |
| 234 | + } |
| 235 | + } else { |
| 236 | + Timber.d("response.body() is null"); |
| 237 | + Toast.makeText(OptimizationActivity.this, String.format(getString(R.string.null_in_response), |
| 238 | + "The Optimization API response's body"), Toast.LENGTH_SHORT).show(); |
225 | 239 | } |
226 | 240 | } |
227 | | - |
228 | | - // Get most optimized route from API response |
229 | | - optimizedRoute = response.body().trips().get(0); |
230 | | - drawOptimizedRoute(style, optimizedRoute); |
231 | 241 | } |
232 | 242 |
|
233 | 243 | @Override |
|
0 commit comments