diff --git a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/GeofavoriteAdapter.java b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/GeofavoriteAdapter.java index 8dcb1c5..e28f9a1 100644 --- a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/GeofavoriteAdapter.java +++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/GeofavoriteAdapter.java @@ -82,6 +82,17 @@ public class GeofavoriteAdapter extends RecyclerView.Adapter { + geofavoriteAdapter.removeById(id); + Toast.makeText(MainActivity.this, R.string.list_geofavorite_deleted, Toast.LENGTH_LONG).show(); + }); + } + @Override public void onErrorLoading(String message) { Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show(); @@ -320,12 +329,13 @@ public class MainActivity extends AppCompatActivity implements MainView, OnSorti private void showGeofavoriteDeteleDialog(Geofavorite item) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); - builder.setMessage(R.string.dialog_delete_message) - .setTitle(getString(R.string.dialog_delete_title).replace("{name}", item.getName())) + builder.setMessage(getString(R.string.dialog_delete_message).replace("{name}", item.getName())) + .setTitle(R.string.dialog_delete_title) .setPositiveButton(R.string.dialog_delete_delete, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { presenter.deleteGeofavorite(item.getId()); dialog.dismiss(); + // Callback is onGeofavoriteDeleted } }) .setNegativeButton(R.string.dialog_delete_cancel, new DialogInterface.OnClickListener() { @@ -333,7 +343,8 @@ public class MainActivity extends AppCompatActivity implements MainView, OnSorti dialog.dismiss(); } }); - builder.create(); + AlertDialog ad = builder.create(); + ad.show(); } private void showGeofavoriteDetailActivity(Geofavorite item) { diff --git a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainPresenter.java b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainPresenter.java index 861cfbc..30d25b4 100644 --- a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainPresenter.java +++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainPresenter.java @@ -66,24 +66,18 @@ public class MainPresenter { public void deleteGeofavorite(int id) { view.showLoading(); - Call> call = ApiProvider.getAPI().getGeofavorites(); - call.enqueue(new Callback>() { + Call call = ApiProvider.getAPI().deleteGeofavorite(id); + call.enqueue(new Callback() { @Override - public void onResponse(@NonNull Call> call, @NonNull Response> response) { - ((AppCompatActivity) view).runOnUiThread(() -> { - view.hideLoading(); - if (response.isSuccessful() && response.body() != null) { - view.onGetResult(response.body()); - } - }); + public void onResponse(Call call, Response response) { + view.hideLoading(); + view.onGeofavoriteDeleted(id); } @Override - public void onFailure(@NonNull Call> call, @NonNull Throwable t) { - ((AppCompatActivity) view).runOnUiThread(() -> { - view.hideLoading(); - view.onErrorLoading(t.getLocalizedMessage()); - }); + public void onFailure(Call call, Throwable t) { + view.hideLoading(); + view.onErrorLoading(t.getLocalizedMessage()); } }); } diff --git a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainView.java b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainView.java index 5bdd6ef..de44b00 100644 --- a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainView.java +++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainView.java @@ -28,5 +28,6 @@ public interface MainView { void showLoading(); void hideLoading(); void onGetResult(List geofavorites); + void onGeofavoriteDeleted(int id); void onErrorLoading(String message); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 43dc652..aede1e2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -37,6 +37,7 @@ You are about to delete geobookmark {name}. Proceed? Delete Maintain + Geofavorite deleted Sort by