Connection error management
This commit is contained in:
parent
e558fa28b5
commit
6bca4462a3
@ -113,17 +113,26 @@ public class GeofavoriteDetailActivity extends AppCompatActivity implements Loca
|
||||
call.enqueue(new Callback<Geofavorite>() {
|
||||
@Override
|
||||
public void onResponse(Call<Geofavorite> call, Response<Geofavorite> response) {
|
||||
finish();
|
||||
if (response.isSuccessful())
|
||||
finish();
|
||||
else
|
||||
onGeofavoriteSaveFailed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Geofavorite> call, Throwable t) {
|
||||
Toast.makeText(GeofavoriteDetailActivity.this, R.string.error_saving_geofavorite, Toast.LENGTH_SHORT).show();
|
||||
onGeofavoriteSaveFailed();
|
||||
Log.e(TAG, "Unable to update geofavorite: " + t.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void onGeofavoriteSaveFailed() {
|
||||
runOnUiThread(() ->
|
||||
Toast.makeText(GeofavoriteDetailActivity.this, R.string.error_saving_geofavorite, Toast.LENGTH_SHORT).show()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the current location (requesting user's permission, if necessary)
|
||||
* and calls updateLocationField()
|
||||
|
@ -22,6 +22,7 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
@ -65,6 +66,8 @@ public class MainActivity extends AppCompatActivity implements MainView, OnSorti
|
||||
private static final int INTENT_ADD = 100;
|
||||
private static final int INTENT_EDIT = 200;
|
||||
|
||||
private static final String TAG = "MainActivity";
|
||||
|
||||
private static final String NAVIGATION_KEY_ADD_GEOFAVORITE = "add";
|
||||
private static final String NAVIGATION_KEY_SHOW_ABOUT = "about";
|
||||
private static final String NAVIGATION_KEY_SWITCH_ACCOUNT = "switch_account";
|
||||
@ -292,7 +295,8 @@ public class MainActivity extends AppCompatActivity implements MainView, OnSorti
|
||||
|
||||
@Override
|
||||
public void onErrorLoading(String message) {
|
||||
Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(MainActivity.this, R.string.list_geofavorite_connection_error, Toast.LENGTH_LONG).show();
|
||||
Log.e(TAG, "Unable to obtain geofavorites list: " + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -50,6 +50,11 @@ public class MainPresenter {
|
||||
view.hideLoading();
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
view.onGetResult(response.body());
|
||||
} else {
|
||||
((AppCompatActivity) view).runOnUiThread(() -> {
|
||||
view.hideLoading();
|
||||
view.onErrorLoading(response.raw().message());
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -38,6 +38,7 @@
|
||||
<string name="dialog_delete_delete">Delete</string>
|
||||
<string name="dialog_delete_cancel">Maintain</string>
|
||||
<string name="list_geofavorite_deleted">Geofavorite deleted</string>
|
||||
<string name="list_geofavorite_connection_error">Unable to obtain geofavorites list</string>
|
||||
|
||||
<!-- Sort dialog -->
|
||||
<string name="sort_by">Sort by</string>
|
||||
|
Loading…
Reference in New Issue
Block a user