Skip to content

Commit

Permalink
Añadido dialogo de confirmación al borrar un sitio
Browse files Browse the repository at this point in the history
Close #67
  • Loading branch information
martinlaizg committed Aug 13, 2019
1 parent dc82f65 commit be8dd58
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.martinlaizg.geofind.views.adapter;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -14,6 +15,7 @@

import com.google.android.material.button.MaterialButton;
import com.google.android.material.card.MaterialCardView;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.martinlaizg.geofind.R;
import com.martinlaizg.geofind.data.access.database.entities.Place;
import com.martinlaizg.geofind.views.fragment.creator.CreatePlaceFragment;
Expand Down Expand Up @@ -43,7 +45,9 @@ public void onBindViewHolder(@NonNull final CreatorPlacesViewHolder holder, int
Place place = places.get(position);

holder.place_name.setText(place.getName());
holder.place_delete_button.setOnClickListener(v -> remove(position));
holder.place_delete_button.setOnClickListener(v -> {
showExitDialog(v.getContext(), position);
});
holder.questionaire_icon.setVisibility(View.GONE);
if(place.getQuestion() != null) {
holder.questionaire_icon.setVisibility(View.VISIBLE);
Expand All @@ -56,6 +60,20 @@ public void onBindViewHolder(@NonNull final CreatorPlacesViewHolder holder, int

}

@Override
public int getItemCount() {
return places.size();
}

private void showExitDialog(Context context, int position) {
new MaterialAlertDialogBuilder(context).setTitle(R.string.are_you_sure)
.setMessage(context.getString(R.string.permanent_delete))
.setPositiveButton(context.getString(R.string.ok),
(dialog, which) -> remove(position))
.setNegativeButton(context.getString(R.string.cancel),
(dialogInterface, i) -> dialogInterface.dismiss()).show();
}

private void remove(int position) {
places.remove(position);
for(int i = 0; i < places.size(); i++) {
Expand All @@ -64,11 +82,6 @@ private void remove(int position) {
notifyDataSetChanged();
}

@Override
public int getItemCount() {
return places.size();
}

public CreatorPlacesAdapter() {
places = new ArrayList<>();
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,6 @@
<string name="done">Done</string>
<string name="add_location">Add location</string>
<string name="select_location">Select location</string>
<string name="permanent_delete">It will be deleted permanently</string>
<string name="cancel">Cancel</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,6 @@
<string name="done">Hecho</string>
<string name="add_location">Añadir localización</string>
<string name="select_location">Seleccionar localización</string>
<string name="cancel">Cancelar</string>
<string name="permanent_delete">Se borrará permanentemente</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,6 @@
<string name="done">Done</string>
<string name="add_location">Add location</string>
<string name="select_location">Select location</string>
<string name="permanent_delete">It will be deleted permanently</string>
<string name="cancel">Cancel</string>
</resources>

0 comments on commit be8dd58

Please sign in to comment.