Add EditTriggerDialog
This commit is contained in:
parent
75d0bd9761
commit
49b0e3ab71
|
@ -7,7 +7,7 @@ import android.support.v4.app.DialogFragment;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
@ -25,13 +25,16 @@ public class EditEventDialog extends DialogFragment {
|
|||
@BindView(R.id.inputEventTitle)
|
||||
TextInputEditText mEditEventTitle;
|
||||
|
||||
@BindView(R.id.layoutTrigger)
|
||||
LinearLayout mLayoutTrigger;
|
||||
@BindView(R.id.editTrigger)
|
||||
TextView mEditTrigger;
|
||||
|
||||
@BindView(R.id.triggerDescription)
|
||||
TextView mTriggerDescription;
|
||||
|
||||
private Unbinder mUnbinder;
|
||||
|
||||
public static EditEventDialog newInstance(AutomationEvent event) {
|
||||
mEvent = event;
|
||||
mEvent = event; // FIXME
|
||||
|
||||
Bundle args = new Bundle();
|
||||
EditEventDialog fragment = new EditEventDialog();
|
||||
|
@ -54,14 +57,22 @@ public class EditEventDialog extends DialogFragment {
|
|||
}
|
||||
|
||||
// display root trigger
|
||||
mLayoutTrigger.addView(mEvent.getTrigger().createView(getContext(), getFragmentManager()));
|
||||
mTriggerDescription.setText(mEvent.getTrigger().friendlyDescription());
|
||||
|
||||
mEditTrigger.setOnClickListener(v -> {
|
||||
EditTriggerDialog dialog = EditTriggerDialog.newInstance(mEvent.getTrigger());
|
||||
dialog.show(getFragmentManager(), "EditTriggerDialog");
|
||||
dialog.setOnClickListener(trigger -> {
|
||||
mEvent.setTrigger(trigger);
|
||||
mTriggerDescription.setText(mEvent.getTrigger().friendlyDescription());
|
||||
});
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
//mTriggerListAdapter.destroy();
|
||||
mUnbinder.unbind();
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
package info.nightscout.androidaps.plugins.general.automation.dialogs;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import butterknife.Unbinder;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger;
|
||||
|
||||
public class EditTriggerDialog extends DialogFragment {
|
||||
|
||||
public interface OnClickListener {
|
||||
void onClick(Trigger newTriggerObject);
|
||||
}
|
||||
|
||||
@BindView(R.id.layoutTrigger)
|
||||
LinearLayout mLayoutTrigger;
|
||||
|
||||
private Trigger mTrigger;
|
||||
private Unbinder mUnbinder;
|
||||
private OnClickListener mClickListener = null;
|
||||
|
||||
public static EditTriggerDialog newInstance(Trigger trigger) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString("trigger", trigger.toJSON());
|
||||
EditTriggerDialog fragment = new EditTriggerDialog();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.automation_dialog_edit_trigger, container, false);
|
||||
mUnbinder = ButterKnife.bind(this, view);
|
||||
|
||||
// load data from bundle
|
||||
Bundle bundle = savedInstanceState != null ? savedInstanceState : getArguments();
|
||||
if (bundle != null) {
|
||||
String triggerData = bundle.getString("trigger");
|
||||
if (triggerData != null) mTrigger = Trigger.instantiate(triggerData);
|
||||
}
|
||||
|
||||
// display root trigger
|
||||
mLayoutTrigger.addView(mTrigger.createView(getContext(), getFragmentManager()));
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
public void setOnClickListener(OnClickListener clickListener) {
|
||||
mClickListener = clickListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
mUnbinder.unbind();
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@OnClick(R.id.ok)
|
||||
public void onButtonOk(View view) {
|
||||
if (mClickListener != null)
|
||||
mClickListener.onClick(mTrigger);
|
||||
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@OnClick(R.id.cancel)
|
||||
public void onButtonCancel(View view) {
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle bundle) {
|
||||
bundle.putString("trigger", mTrigger.toJSON());
|
||||
}
|
||||
}
|
33
app/src/main/res/layout/automation_dialog_edit_trigger.xml
Normal file
33
app/src/main/res/layout/automation_dialog_edit_trigger.xml
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="info.nightscout.androidaps.plugins.general.automation.dialogs.EditEventDialog">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:focusableInTouchMode="true"
|
||||
android:orientation="vertical"
|
||||
android:padding="10dp">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/layoutTrigger"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:orientation="vertical" />
|
||||
|
||||
<include layout="@layout/mdtp_done_button" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</FrameLayout>
|
|
@ -29,16 +29,31 @@
|
|||
android:layout_marginTop="5dp"
|
||||
android:background="@color/listdelimiter" />
|
||||
|
||||
<TextView
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Triggers:"/>
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/layoutTrigger"
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="if:"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/editTrigger"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:text="Edit" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/triggerDescription"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginVertical="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:orientation="vertical" />
|
||||
|
||||
<View
|
||||
|
@ -51,7 +66,7 @@
|
|||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Actions:"/>
|
||||
android:text="then:"/>
|
||||
|
||||
<include layout="@layout/mdtp_done_button" />
|
||||
|
||||
|
|
Loading…
Reference in a new issue