Added deletion, but the dialog is never displayed
This commit is contained in:
		| @@ -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(); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -63,4 +63,28 @@ public class MainPresenter { | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     public void deleteGeofavorite(int id) { | ||||
|         view.showLoading(); | ||||
|         Call<List<Geofavorite>> call = ApiProvider.getAPI().getGeofavorites(); | ||||
|         call.enqueue(new Callback<List<Geofavorite>>() { | ||||
|             @Override | ||||
|             public void onResponse(@NonNull Call<List<Geofavorite>> call, @NonNull Response<List<Geofavorite>> response) { | ||||
|                 ((AppCompatActivity) view).runOnUiThread(() -> { | ||||
|                     view.hideLoading(); | ||||
|                     if (response.isSuccessful() && response.body() != null) { | ||||
|                         view.onGetResult(response.body()); | ||||
|                     } | ||||
|                 }); | ||||
|             } | ||||
|  | ||||
|             @Override | ||||
|             public void onFailure(@NonNull Call<List<Geofavorite>> call, @NonNull Throwable t) { | ||||
|                 ((AppCompatActivity) view).runOnUiThread(() -> { | ||||
|                     view.hideLoading(); | ||||
|                     view.onErrorLoading(t.getLocalizedMessage()); | ||||
|                 }); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -33,6 +33,10 @@ | ||||
|     <string name="share_message">Check out this place: {lat}°N, {lng}°E    https://www.openstreetmap.org/#map=17/{lat}/{lng}</string> | ||||
|     <string name="list_context_menu_detail">Details</string> | ||||
|     <string name="list_context_menu_delete">Delete</string> | ||||
|     <string name="dialog_delete_title">Delete geobookmark</string> | ||||
|     <string name="dialog_delete_message">You are about to delete geobookmark {name}. Proceed?</string> | ||||
|     <string name="dialog_delete_delete">Delete</string> | ||||
|     <string name="dialog_delete_cancel">Maintain</string> | ||||
|  | ||||
|     <!-- Sort dialog --> | ||||
|     <string name="sort_by">Sort by</string> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user