updated deps and code to a more recent state

This commit is contained in:
2017-01-31 16:02:23 +01:00
parent 5872be4fe7
commit 23035084e8
15 changed files with 336 additions and 437 deletions

View File

@@ -205,20 +205,17 @@ public class AddStripeDialog extends DialogFragment implements DialogInterface.O
}
});
ImageButton.OnClickListener imgListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.imgbuttn_togglechannel_r:
testChannel(channelR, (ImageButton) v);
break;
case R.id.imgbuttn_togglechannel_g:
testChannel(channelG, (ImageButton) v);
break;
case R.id.imgbuttn_togglechannel_b:
testChannel(channelB, (ImageButton) v);
break;
}
ImageButton.OnClickListener imgListener = v -> {
switch (v.getId()) {
case R.id.imgbuttn_togglechannel_r:
testChannel(channelR, (ImageButton) v);
break;
case R.id.imgbuttn_togglechannel_g:
testChannel(channelG, (ImageButton) v);
break;
case R.id.imgbuttn_togglechannel_b:
testChannel(channelB, (ImageButton) v);
break;
}
};
@@ -226,71 +223,53 @@ public class AddStripeDialog extends DialogFragment implements DialogInterface.O
channelGBttn.setOnClickListener(imgListener);
channelBBttn.setOnClickListener(imgListener);
alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(v -> alertDialog.dismiss());
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> {
if (!mDaemonSelected) {
Toast.makeText(getActivity(), "Please select Daemon and Controller", Toast.LENGTH_LONG).show();
return;
}
});
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!mDaemonSelected) {
Toast.makeText(getActivity(), "Please select Daemon and Controller", Toast.LENGTH_LONG).show();
return;
}
if (stripeNameText.getText().toString().isEmpty()) {
stripeNameLay.setError("Please set the Stripe name");
return;
}
if (stripeNameText.getText().toString().isEmpty()) {
stripeNameLay.setError("Please set the Stripe name");
return;
}
if (channelR.getText().toString().isEmpty() || channelG.getText().toString().isEmpty() || channelB.getText().toString().isEmpty()) {
Toast.makeText(getActivity(), "Please add mapping for all channels", Toast.LENGTH_LONG).show();
return;
}
if (channelR.getText().toString().isEmpty() || channelG.getText().toString().isEmpty() || channelB.getText().toString().isEmpty()) {
Toast.makeText(getActivity(), "Please add mapping for all channels", Toast.LENGTH_LONG).show();
return;
}
LedStripe stripe = new LedStripe(Integer.parseInt(channelR.getText().toString()), Integer.parseInt(channelG.getText().toString()),
Integer.parseInt(channelB.getText().toString()), stripeNameText.getText().toString());
stripe.setLedDDaemon((LedDDaemon) daemonSpinner.getSelectedItem());
stripe.setController((Controller) controllerSpinner.getSelectedItem());
LedStripe stripe = new LedStripe(Integer.parseInt(channelR.getText().toString()), Integer.parseInt(channelG.getText().toString()),
Integer.parseInt(channelB.getText().toString()), stripeNameText.getText().toString());
stripe.setLedDDaemon((LedDDaemon) daemonSpinner.getSelectedItem());
stripe.setController((Controller) controllerSpinner.getSelectedItem());
LedDHelper helper = ColorApplication.getInstance().getHelperForDaemon((LedDDaemon) daemonSpinner.getSelectedItem());
LedDHelper helper = ColorApplication.getInstance().getHelperForDaemon((LedDDaemon) daemonSpinner.getSelectedItem());
if (helper != null) {
helper.addStripe(stripe, new AddStripeCallback() {
@Override
public void onAddSuccessfully(final LedStripe stripe) {
ColorActivity activity = ((ColorActivity) getActivity());
activity.refreshStripes();
if (helper != null) {
helper.addStripe(stripe, new AddStripeCallback() {
@Override
public void onAddSuccessfully(final LedStripe stripe) {
ColorActivity activity = ((ColorActivity) getActivity());
activity.refreshStripes();
getActivity().runOnUiThread(() -> Snackbar.make(((ViewGroup) getActivity().getWindow().getDecorView().findViewById(android.R.id.content)).getChildAt(0), String.format(getActivity().getString(R.string.snackbar_added_stripe_id), stripe.getId()), Snackbar.LENGTH_LONG).show());
dismiss();
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Snackbar.make(((ViewGroup) getActivity().getWindow().getDecorView().findViewById(android.R.id.content)).getChildAt(0), String.format(getActivity().getString(R.string.snackbar_added_stripe_id), stripe.getId()), Snackbar.LENGTH_LONG).show();
}
});
dismiss();
}
@Override
public void onAddFailed(int code, String msg) {
@Override
public void onAddFailed(int code, String msg) {
}
}
@Override
public void onConnectionFailed(final String message) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Snackbar.make(((ViewGroup) getActivity().getWindow().getDecorView().findViewById(android.R.id.content)).getChildAt(0), getActivity().getString(R.string.snackbar_failed_add_stripe) + message, Snackbar.LENGTH_LONG).show();
}
});
dismiss();
}
});
}
@Override
public void onConnectionFailed(final String message) {
getActivity().runOnUiThread(() -> Snackbar.make(((ViewGroup) getActivity().getWindow().getDecorView().findViewById(android.R.id.content)).getChildAt(0), getActivity().getString(R.string.snackbar_failed_add_stripe) + message, Snackbar.LENGTH_LONG).show());
dismiss();
}
});
}
});
@@ -359,17 +338,14 @@ public class AddStripeDialog extends DialogFragment implements DialogInterface.O
super.onResume();
ColorApplication.getInstance().onResume();
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
if (daemonArrayAdapter != null) {
daemonArrayAdapter.clear();
daemonArrayAdapter.addAll(ColorApplication.getInstance().getDaemons());
}
getActivity().runOnUiThread(() -> {
if (daemonArrayAdapter != null) {
daemonArrayAdapter.clear();
daemonArrayAdapter.addAll(ColorApplication.getInstance().getDaemons());
}
if (controllerArrayAdapter != null && mDaemonSelected) {
refreshController((LedDDaemon) daemonSpinner.getSelectedItem());
}
if (controllerArrayAdapter != null && mDaemonSelected) {
refreshController((LedDDaemon) daemonSpinner.getSelectedItem());
}
});
}
@@ -409,12 +385,9 @@ public class AddStripeDialog extends DialogFragment implements DialogInterface.O
helper.getStripes(new StripesCallback() {
@Override
public void onSuccess(List<LedStripe> stripes) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
controllerArrayAdapter.addAll(ledDDaemon.getControllers());
toggleAll(stripeMapping, true);
}
getActivity().runOnUiThread(() -> {
controllerArrayAdapter.addAll(ledDDaemon.getControllers());
toggleAll(stripeMapping, true);
});
}