From 9161b61b6ebe800d6781b92e8e64889145b54ddd Mon Sep 17 00:00:00 2001 From: Daniele Date: Tue, 7 Sep 2021 21:22:30 +0200 Subject: [PATCH] Added deletion, but the dialog is never displayed --- .../activity/main/MainActivity.java | 22 ++++++++++++++++- .../activity/main/MainPresenter.java | 24 +++++++++++++++++++ app/src/main/res/values/strings.xml | 4 ++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainActivity.java b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainActivity.java index 6fcd5a3..3468418 100644 --- a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainActivity.java +++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainActivity.java @@ -17,6 +17,7 @@ package it.danieleverducci.nextcloudmaps.activity.main; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; @@ -25,6 +26,7 @@ import android.util.Log; import android.view.View; import android.widget.Toast; +import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.AppCompatImageButton; import androidx.appcompat.widget.AppCompatImageView; @@ -130,7 +132,7 @@ public class MainActivity extends AppCompatActivity implements MainView, OnSorti @Override public void onItemDeleteClick(Geofavorite item) { - Log.d("MENU", "Delete "+item.getName()); + showGeofavoriteDeteleDialog(item); } }; @@ -318,4 +320,22 @@ public class MainActivity extends AppCompatActivity implements MainView, OnSorti viewButton.setImageResource(gridEnabled ? R.drawable.ic_view_list : R.drawable.ic_view_module); } + 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())) + .setPositiveButton(R.string.dialog_delete_delete, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + presenter.deleteGeofavorite(item.getId()); + dialog.dismiss(); + } + }) + .setNegativeButton(R.string.dialog_delete_cancel, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.dismiss(); + } + }); + builder.create(); + } + } \ No newline at end of file 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 6ed5c6c..861cfbc 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 @@ -63,4 +63,28 @@ public class MainPresenter { } }); } + + public void deleteGeofavorite(int id) { + view.showLoading(); + Call> call = ApiProvider.getAPI().getGeofavorites(); + 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()); + } + }); + } + + @Override + public void onFailure(@NonNull Call> call, @NonNull Throwable t) { + ((AppCompatActivity) view).runOnUiThread(() -> { + view.hideLoading(); + view.onErrorLoading(t.getLocalizedMessage()); + }); + } + }); + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a4a8456..43dc652 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -33,6 +33,10 @@ Check out this place: {lat}°N, {lng}°E https://www.openstreetmap.org/#map=17/{lat}/{lng} Details Delete + Delete geobookmark + You are about to delete geobookmark {name}. Proceed? + Delete + Maintain Sort by