diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt index 8b6ffb1720..728480323c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt @@ -29,7 +29,7 @@ class AutomationFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - eventListAdapter = EventListAdapter(AutomationPlugin.automationEvents, fragmentManager) + eventListAdapter = EventListAdapter(AutomationPlugin.automationEvents, fragmentManager, activity) automation_eventListView.layoutManager = LinearLayoutManager(context) automation_eventListView.adapter = eventListAdapter diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/EventListAdapter.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/EventListAdapter.java index fba54aefbd..08079a9110 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/EventListAdapter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/EventListAdapter.java @@ -1,5 +1,6 @@ package info.nightscout.androidaps.plugins.general.automation; +import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; @@ -26,14 +27,17 @@ import info.nightscout.androidaps.plugins.general.automation.actions.Action; import info.nightscout.androidaps.plugins.general.automation.dialogs.EditEventDialog; import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationDataChanged; import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector; +import info.nightscout.androidaps.utils.OKDialog; class EventListAdapter extends RecyclerView.Adapter { - private final List mEventList; - private final FragmentManager mFragmentManager; + private final List eventList; + private final FragmentManager fragmentManager; + private final Activity activity; - EventListAdapter(List events, FragmentManager fragmentManager) { - this.mEventList = events; - this.mFragmentManager = fragmentManager; + EventListAdapter(List events, FragmentManager fragmentManager, Activity activity) { + this.eventList = events; + this.fragmentManager = fragmentManager; + this.activity = activity; } @NonNull @@ -52,7 +56,7 @@ class EventListAdapter extends RecyclerView.Adapter @Override public void onBindViewHolder(@NonNull ViewHolder holder, int position) { - final AutomationEvent event = mEventList.get(position); + final AutomationEvent event = eventList.get(position); holder.eventTitle.setText(event.getTitle()); holder.enabled.setChecked(event.isEnabled()); holder.iconLayout.removeAllViews(); @@ -88,10 +92,12 @@ class EventListAdapter extends RecyclerView.Adapter }); // remove event - holder.iconTrash.setOnClickListener(v -> { - mEventList.remove(event); - RxBus.INSTANCE.send(new EventAutomationDataChanged()); - }); + holder.iconTrash.setOnClickListener(v -> + OKDialog.showConfirmation(activity, MainApp.gs(R.string.removerecord) + " " + event.getTitle(), () -> { + eventList.remove(event); + RxBus.INSTANCE.send(new EventAutomationDataChanged()); + }) + ); // edit event holder.rootLayout.setOnClickListener(v -> { @@ -101,14 +107,14 @@ class EventListAdapter extends RecyclerView.Adapter args.putString("event", event.toJSON()); args.putInt("position", position); dialog.setArguments(args); - if (mFragmentManager != null) - dialog.show(mFragmentManager, "EditEventDialog"); + if (fragmentManager != null) + dialog.show(fragmentManager, "EditEventDialog"); }); } @Override public int getItemCount() { - return mEventList.size(); + return eventList.size(); } static class ViewHolder extends RecyclerView.ViewHolder {