Confirmation on automation task delete
This commit is contained in:
parent
b0e180ef8a
commit
7cd66a6a43
|
@ -29,7 +29,7 @@ class AutomationFragment : Fragment() {
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
eventListAdapter = EventListAdapter(AutomationPlugin.automationEvents, fragmentManager)
|
eventListAdapter = EventListAdapter(AutomationPlugin.automationEvents, fragmentManager, activity)
|
||||||
automation_eventListView.layoutManager = LinearLayoutManager(context)
|
automation_eventListView.layoutManager = LinearLayoutManager(context)
|
||||||
automation_eventListView.adapter = eventListAdapter
|
automation_eventListView.adapter = eventListAdapter
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package info.nightscout.androidaps.plugins.general.automation;
|
package info.nightscout.androidaps.plugins.general.automation;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
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.dialogs.EditEventDialog;
|
||||||
import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationDataChanged;
|
import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationDataChanged;
|
||||||
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector;
|
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector;
|
||||||
|
import info.nightscout.androidaps.utils.OKDialog;
|
||||||
|
|
||||||
class EventListAdapter extends RecyclerView.Adapter<EventListAdapter.ViewHolder> {
|
class EventListAdapter extends RecyclerView.Adapter<EventListAdapter.ViewHolder> {
|
||||||
private final List<AutomationEvent> mEventList;
|
private final List<AutomationEvent> eventList;
|
||||||
private final FragmentManager mFragmentManager;
|
private final FragmentManager fragmentManager;
|
||||||
|
private final Activity activity;
|
||||||
|
|
||||||
EventListAdapter(List<AutomationEvent> events, FragmentManager fragmentManager) {
|
EventListAdapter(List<AutomationEvent> events, FragmentManager fragmentManager, Activity activity) {
|
||||||
this.mEventList = events;
|
this.eventList = events;
|
||||||
this.mFragmentManager = fragmentManager;
|
this.fragmentManager = fragmentManager;
|
||||||
|
this.activity = activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@ -52,7 +56,7 @@ class EventListAdapter extends RecyclerView.Adapter<EventListAdapter.ViewHolder>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
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.eventTitle.setText(event.getTitle());
|
||||||
holder.enabled.setChecked(event.isEnabled());
|
holder.enabled.setChecked(event.isEnabled());
|
||||||
holder.iconLayout.removeAllViews();
|
holder.iconLayout.removeAllViews();
|
||||||
|
@ -88,10 +92,12 @@ class EventListAdapter extends RecyclerView.Adapter<EventListAdapter.ViewHolder>
|
||||||
});
|
});
|
||||||
|
|
||||||
// remove event
|
// remove event
|
||||||
holder.iconTrash.setOnClickListener(v -> {
|
holder.iconTrash.setOnClickListener(v ->
|
||||||
mEventList.remove(event);
|
OKDialog.showConfirmation(activity, MainApp.gs(R.string.removerecord) + " " + event.getTitle(), () -> {
|
||||||
|
eventList.remove(event);
|
||||||
RxBus.INSTANCE.send(new EventAutomationDataChanged());
|
RxBus.INSTANCE.send(new EventAutomationDataChanged());
|
||||||
});
|
})
|
||||||
|
);
|
||||||
|
|
||||||
// edit event
|
// edit event
|
||||||
holder.rootLayout.setOnClickListener(v -> {
|
holder.rootLayout.setOnClickListener(v -> {
|
||||||
|
@ -101,14 +107,14 @@ class EventListAdapter extends RecyclerView.Adapter<EventListAdapter.ViewHolder>
|
||||||
args.putString("event", event.toJSON());
|
args.putString("event", event.toJSON());
|
||||||
args.putInt("position", position);
|
args.putInt("position", position);
|
||||||
dialog.setArguments(args);
|
dialog.setArguments(args);
|
||||||
if (mFragmentManager != null)
|
if (fragmentManager != null)
|
||||||
dialog.show(mFragmentManager, "EditEventDialog");
|
dialog.show(fragmentManager, "EditEventDialog");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return mEventList.size();
|
return eventList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
Loading…
Reference in a new issue