Improve EditEventDialog
This commit is contained in:
parent
87cf62e8f6
commit
6dc87db73e
|
@ -51,6 +51,11 @@ public class AutomationFragment extends SubscriberFragment {
|
|||
mEventListView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
mEventListView.setAdapter(mEventListAdapter);
|
||||
|
||||
EditEventDialog.setOnClickListener(event -> {
|
||||
plugin.getAutomationEvents().add(event);
|
||||
mEventListAdapter.notifyDataSetChanged();
|
||||
});
|
||||
|
||||
updateGUI();
|
||||
|
||||
return view;
|
||||
|
|
|
@ -10,6 +10,7 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
@ -22,8 +23,17 @@ import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin;
|
|||
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector;
|
||||
|
||||
public class EditEventDialog extends DialogFragment {
|
||||
public interface OnClickListener {
|
||||
void onClick(AutomationEvent event);
|
||||
}
|
||||
|
||||
private static OnClickListener mClickListener = null;
|
||||
private static AutomationEvent mEvent;
|
||||
|
||||
public static void setOnClickListener(OnClickListener clickListener) {
|
||||
mClickListener = clickListener;
|
||||
}
|
||||
|
||||
@BindView(R.id.inputEventTitle)
|
||||
TextInputEditText mEditEventTitle;
|
||||
|
||||
|
@ -105,14 +115,28 @@ public class EditEventDialog extends DialogFragment {
|
|||
|
||||
@OnClick(R.id.ok)
|
||||
public void onButtonOk(View view) {
|
||||
// check for title
|
||||
String title = mEditEventTitle.getText().toString();
|
||||
if (title.isEmpty()) return;
|
||||
|
||||
if (title.isEmpty()) {
|
||||
Toast.makeText(getContext(), R.string.automation_missing_task_name, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
mEvent.setTitle(title);
|
||||
|
||||
final AutomationPlugin plugin = AutomationPlugin.getPlugin();
|
||||
plugin.getAutomationEvents().add(mEvent);
|
||||
// check for at least one trigger
|
||||
TriggerConnector con = (TriggerConnector) mEvent.getTrigger();
|
||||
if (con.size() == 0) {
|
||||
Toast.makeText(getContext(), R.string.automation_missing_trigger, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
// check for at least one action
|
||||
if (mEvent.getActions().isEmpty()) {
|
||||
Toast.makeText(getContext(), R.string.automation_missing_action, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (mClickListener != null) mClickListener.onClick(mEvent);
|
||||
dismiss();
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
android:id="@+id/inputEventTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Event Name" />
|
||||
android:hint="Task Name" />
|
||||
|
||||
<View
|
||||
android:layout_width="fill_parent"
|
||||
|
|
|
@ -1292,6 +1292,9 @@
|
|||
<string name="automation">Automation</string>
|
||||
<string name="automation_short">Auto</string>
|
||||
<string name="automation_description">User defined automation tasks</string>
|
||||
<string name="automation_missing_task_name">Please enter a task name.</string>
|
||||
<string name="automation_missing_trigger">Please specify at least one trigger.</string>
|
||||
<string name="automation_missing_action">Please specify at least one action.</string>
|
||||
<string name="alreadyenabled">Already enabled</string>
|
||||
<string name="alreadydisabled">Already disabled</string>
|
||||
<string name="alreadysuspended">Already suspended</string>
|
||||
|
|
Loading…
Reference in a new issue