tbr capability in ComboFragment

This commit is contained in:
AdrianLxM 2017-07-26 22:16:35 +02:00
parent 76c0b999ff
commit 13173e48c1
3 changed files with 94 additions and 17 deletions

View file

@ -33,7 +33,7 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
}
private Button refresh;
private Button testButton;
private TextView updateCapabilities;
private TextView statusText;
@ -46,13 +46,15 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
private TextView lastCmdTimeText;
private TextView lastCmdResultText;
private TextView tbrCapabilityText;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.combopump_fragment, container, false);
refresh = (Button) view.findViewById(R.id.combo_refresh);
testButton = (Button) view.findViewById(R.id.combo_testaction);
updateCapabilities = (TextView) view.findViewById(R.id.combo_update_capabilities);
statusText = (TextView) view.findViewById(R.id.combo_status);
@ -64,9 +66,10 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
lastCmdText = (TextView) view.findViewById(R.id.combo_last_command);
lastCmdTimeText = (TextView) view.findViewById(R.id.combo_last_command_time);
lastCmdResultText = (TextView) view.findViewById(R.id.combo_last_command_result);
tbrCapabilityText = (TextView) view.findViewById(R.id.combo_tbr_capability);
refresh.setOnClickListener(this);
testButton.setOnClickListener(this);
updateCapabilities.setOnClickListener(this);
updateGUI();
return view;
@ -102,11 +105,29 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
});
thread.start();
break;
case R.id.combo_testaction:
case R.id.combo_update_capabilities:
(new Thread(new Runnable() {
@Override
public void run() {
getPlugin().doTestAction();
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
updateCapabilities.setText("{fa-bluetooth}");
}
});
getPlugin().updateCapabilities();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
updateCapabilities.setText("{fa-bluetooth-b}");
}
});
}
})).start();
break;
@ -151,7 +172,9 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
} else {
lastCmdResultText.setText("");
}
}
tbrCapabilityText.setText(getPlugin().getPumpDescription().maxTempPercent + "%");
}
});
}

View file

@ -621,19 +621,23 @@ public class ComboPlugin implements PluginBase, PumpInterface {
}
public void doTestAction() {
ToastUtils.showToastInUiThread(MainApp.instance(), "TestAction called");
public void updateCapabilities() {
// if Android is sluggish this might get called before ruffy is bound
if (ruffyScripter == null) {
log.warn("Rejecting call to RefreshDataFromPump: ruffy service not bound (yet)");
ToastUtils.showToastInUiThread(MainApp.instance(), "Rejecting call to RefreshDataFromPump: ruffy service not bound (yet)");
ToastUtils.showToastInUiThread(MainApp.instance(), "Ruffy not initialized.");
return;
}
if (isBusy()){
ToastUtils.showToastInUiThread(MainApp.instance(), "Pump busy!");
return;
}
CommandResult result = runCommand(new DetermineCapabilitiesCommand());
if (result.success){
ToastUtils.showToastInUiThread(MainApp.instance(), "max%: " + result.capabilities.maxTempPercent);
//TODO: write to settings result.capabilities.maxTempPercent
pumpDescription.maxTempPercent = (int) result.capabilities.maxTempPercent;
MainApp.bus().post(new EventComboPumpUpdateGUI());
} else {
ToastUtils.showToastInUiThread(MainApp.instance(), "No success with test Command.");
}

View file

@ -20,13 +20,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Refresh" />
<Button
android:id="@+id/combo_testaction"
style="?android:attr/buttonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test Action" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -151,6 +144,7 @@
android:textColor="@android:color/white"
android:textSize="14sp" />
</LinearLayout>
<View
@ -379,6 +373,62 @@
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:background="@color/listdelimiter" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:paddingRight="5dp"
android:text="TBR Capability"
android:textSize="14sp" />
<TextView
android:layout_width="5dp"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_horizontal"
android:paddingEnd="2dp"
android:paddingStart="2dp"
android:text=":"
android:textSize="14sp" />
<TextView
android:id="@+id/combo_tbr_capability"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="start"
android:paddingLeft="5dp"
android:textColor="@android:color/white"
android:textSize="14sp" />
<com.joanzapata.iconify.widget.IconTextView
android:id="@+id/combo_update_capabilities"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textSize="20sp"
android:gravity="center_horizontal"
android:text="{fa-bluetooth-b}" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"