First implementation
This commit is contained in:
parent
e2ddb48498
commit
8b3b1e67ea
8 changed files with 45 additions and 75 deletions
|
@ -64,6 +64,6 @@ public interface PumpInterface {
|
||||||
|
|
||||||
List<CustomAction> getCustomActions();
|
List<CustomAction> getCustomActions();
|
||||||
|
|
||||||
PumpEnactResult executeCustomAction(CustomActionType customActionType);
|
void executeCustomAction(CustomActionType customActionType);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.Actions;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
|
@ -68,6 +69,9 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
|
||||||
SingleClickButton tddStats;
|
SingleClickButton tddStats;
|
||||||
SingleClickButton history;
|
SingleClickButton history;
|
||||||
|
|
||||||
|
private Map<String,CustomAction> pumpCustomActions = new HashMap<>();
|
||||||
|
private List<SingleClickButton> pumpCustomButtons = new ArrayList<>();
|
||||||
|
|
||||||
public ActionsFragment() {
|
public ActionsFragment() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
@ -203,119 +207,84 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
|
||||||
else
|
else
|
||||||
tempTarget.setVisibility(View.VISIBLE);
|
tempTarget.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
if (!ConfigBuilderPlugin.getActivePump().getPumpDescription().supportsTDDs) tddStats.setVisibility(View.GONE);
|
if (!pump.getPumpDescription().supportsTDDs)
|
||||||
else tddStats.setVisibility(View.VISIBLE);
|
tddStats.setVisibility(View.GONE);
|
||||||
|
else
|
||||||
|
tddStats.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
checkCustomActions();
|
checkPumpCustomActions();
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String activePumpName;
|
View.OnClickListener pumpCustomActionsListener = v -> {
|
||||||
private Map<String,CustomAction> currentCustomActions = new HashMap<>();
|
|
||||||
private List<SingleClickButton> customButtons = new ArrayList<>();
|
|
||||||
|
|
||||||
View.OnClickListener customActionsListener = v -> {
|
|
||||||
|
|
||||||
SingleClickButton btn = (SingleClickButton)v;
|
SingleClickButton btn = (SingleClickButton)v;
|
||||||
|
|
||||||
CustomAction customAction = this.currentCustomActions.get(btn.getText().toString());
|
CustomAction customAction = this.pumpCustomActions.get(btn.getText().toString());
|
||||||
|
|
||||||
ConfigBuilderPlugin.getActivePump().executeCustomAction(customAction.getCustomActionType());
|
ConfigBuilderPlugin.getActivePump().executeCustomAction(customAction.getCustomActionType());
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
private void checkPumpCustomActions() {
|
||||||
|
|
||||||
private void checkCustomActions() {
|
PumpInterface activePump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
||||||
|
|
||||||
PumpInterface activePump = ConfigBuilderPlugin.getActivePump();
|
removePumpCustomActions();
|
||||||
|
|
||||||
if (activePump==null) {
|
if (activePump == null) {
|
||||||
removeCustomActions();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String newPump = activePump.getClass().getSimpleName();
|
|
||||||
|
|
||||||
if (newPump.equals(activePumpName))
|
|
||||||
return;
|
|
||||||
|
|
||||||
removeCustomActions();
|
|
||||||
|
|
||||||
// add new actions
|
|
||||||
List<CustomAction> customActions = activePump.getCustomActions();
|
List<CustomAction> customActions = activePump.getCustomActions();
|
||||||
|
|
||||||
if (customActions!=null)
|
if (customActions != null && customActions.size()>0) {
|
||||||
{
|
|
||||||
|
|
||||||
LinearLayout ll = (LinearLayout)actionsFragmentView.findViewById(R.id.action_buttons_layout);
|
LinearLayout ll = actionsFragmentView.findViewById(R.id.action_buttons_layout);
|
||||||
|
|
||||||
for (CustomAction customAction : customActions) {
|
for (CustomAction customAction : customActions) {
|
||||||
|
|
||||||
SingleClickButton btn = new SingleClickButton(MainApp.instance().getApplicationContext());
|
SingleClickButton btn = new SingleClickButton(getContext(), null, android.R.attr.buttonStyle);
|
||||||
btn.setText(MainApp.gs(customAction.getName()));
|
btn.setText(MainApp.gs(customAction.getName()));
|
||||||
|
|
||||||
// TODO style and drawableTop
|
|
||||||
//btn.setTextAppearance(R.style.buttonStyle);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
|
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
|
||||||
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0.5f);
|
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0.5f);
|
||||||
layoutParams.setMargins(10, 3, 10, 3);
|
layoutParams.setMargins(20, 8, 20, 8); // 10,3,10,3
|
||||||
|
|
||||||
btn.setLayoutParams(layoutParams);
|
btn.setLayoutParams(layoutParams);
|
||||||
btn.setOnClickListener(customActionsListener);
|
btn.setOnClickListener(pumpCustomActionsListener);
|
||||||
|
|
||||||
|
Drawable top = getResources().getDrawable(R.drawable.icon_actions_profileswitch);
|
||||||
|
btn.setCompoundDrawablesWithIntrinsicBounds(null, top, null, null);
|
||||||
|
|
||||||
ll.addView(btn);
|
ll.addView(btn);
|
||||||
|
|
||||||
this.currentCustomActions.put(MainApp.gs(customAction.getName()), customAction);
|
this.pumpCustomActions.put(MainApp.gs(customAction.getName()), customAction);
|
||||||
this.customButtons.add(btn);
|
this.pumpCustomButtons.add(btn);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// <info.nightscout.utils.SingleClickButton
|
|
||||||
// android:id="@+id/actions_profileswitch"
|
|
||||||
// style="?android:attr/buttonStyle"
|
|
||||||
|
|
||||||
// android:layout_width="fill_parent"
|
|
||||||
// android:layout_height="wrap_content"
|
|
||||||
// android:layout_marginBottom="3dp"
|
|
||||||
// android:layout_marginLeft="10dp"
|
|
||||||
// android:layout_marginRight="10dp"
|
|
||||||
// android:layout_marginTop="3dp"
|
|
||||||
// android:layout_weight="0.5"
|
|
||||||
// android:drawableTop="@drawable/icon_actions_profileswitch"
|
|
||||||
// android:text="@string/careportal_profileswitch" />
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
activePumpName = newPump;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeCustomActions() {
|
|
||||||
|
|
||||||
if (currentCustomActions.size()==0)
|
private void removePumpCustomActions() {
|
||||||
|
|
||||||
|
if (pumpCustomActions.size()==0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LinearLayout ll = (LinearLayout)actionsFragmentView.findViewById(R.id.action_buttons_layout);
|
LinearLayout ll = actionsFragmentView.findViewById(R.id.action_buttons_layout);
|
||||||
|
|
||||||
for (SingleClickButton customButton : customButtons) {
|
for (SingleClickButton customButton : pumpCustomButtons) {
|
||||||
ll.removeView(customButton);
|
ll.removeView(customButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
customButtons.clear();
|
pumpCustomButtons.clear();
|
||||||
currentCustomActions.clear();
|
pumpCustomActions.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1383,8 +1383,8 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult executeCustomAction(CustomActionType customActionType) {
|
public void executeCustomAction(CustomActionType customActionType) {
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -476,9 +476,10 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult executeCustomAction(CustomActionType customActionType) {
|
public void executeCustomAction(CustomActionType customActionType) {
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -816,8 +816,8 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult executeCustomAction(CustomActionType customActionType) {
|
public void executeCustomAction(CustomActionType customActionType) {
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -940,8 +940,8 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult executeCustomAction(CustomActionType customActionType) {
|
public void executeCustomAction(CustomActionType customActionType) {
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,8 +249,8 @@ public class MDIPlugin extends PluginBase implements PumpInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult executeCustomAction(CustomActionType customActionType) {
|
public void executeCustomAction(CustomActionType customActionType) {
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,8 +150,8 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult executeCustomAction(CustomActionType customActionType) {
|
public void executeCustomAction(CustomActionType customActionType) {
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue