Added deletion, but the dialog is never displayed

This commit is contained in:
Daniele 2021-09-07 21:22:30 +02:00
parent 9c83707bfc
commit 9161b61b6e
3 changed files with 49 additions and 1 deletions

View File

@ -17,6 +17,7 @@
package it.danieleverducci.nextcloudmaps.activity.main; package it.danieleverducci.nextcloudmaps.activity.main;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
@ -25,6 +26,7 @@ import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Toast; import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatImageButton; import androidx.appcompat.widget.AppCompatImageButton;
import androidx.appcompat.widget.AppCompatImageView; import androidx.appcompat.widget.AppCompatImageView;
@ -130,7 +132,7 @@ public class MainActivity extends AppCompatActivity implements MainView, OnSorti
@Override @Override
public void onItemDeleteClick(Geofavorite item) { 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); 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();
}
} }

View File

@ -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());
});
}
});
}
} }

View File

@ -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="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_detail">Details</string>
<string name="list_context_menu_delete">Delete</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 --> <!-- Sort dialog -->
<string name="sort_by">Sort by</string> <string name="sort_by">Sort by</string>