Experimental Gadgetbridge support

master
M66B 2 weeks ago
parent 9407b6b0d3
commit 0bd70b3712

@ -1313,6 +1313,8 @@ public class EntityRule {
} }
private boolean onActionAutomation(Context context, EntityMessage message, JSONObject jargs, String html) { private boolean onActionAutomation(Context context, EntityMessage message, JSONObject jargs, String html) {
Intent automation;
InternetAddress iaddr = InternetAddress iaddr =
(message.from == null || message.from.length == 0 (message.from == null || message.from.length == 0
? null : ((InternetAddress) message.from[0])); ? null : ((InternetAddress) message.from[0]));
@ -1321,16 +1323,36 @@ public class EntityRule {
DateFormat DTF = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); DateFormat DTF = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
DTF.setTimeZone(java.util.TimeZone.getTimeZone("Zulu")); DTF.setTimeZone(java.util.TimeZone.getTimeZone("Zulu"));
if (html == null && message.content) {
File file = message.getFile(context);
try {
html = Helper.readText(file);
} catch (IOException ex) {
Log.e(ex);
}
}
String text = HtmlHelper.getFullText(context, html); String text = HtmlHelper.getFullText(context, html);
String preview = HtmlHelper.getPreview(text); String preview = HtmlHelper.getPreview(text);
Intent automation = new Intent(ACTION_AUTOMATION); boolean gb = jargs.optBoolean("gadgetbridge");
automation.putExtra(EXTRA_RULE, name); if (gb) {
automation.putExtra(EXTRA_RECEIVED, DTF.format(message.received)); // https://gadgetbridge.org/internals/automations/intents/#send-a-custom-notification
automation.putExtra(EXTRA_SENDER, iaddr == null ? null : iaddr.getAddress()); automation = new Intent("nodomain.freeyourgadget.gadgetbridge.command.DEBUG_SEND_NOTIFICATION");
automation.putExtra(EXTRA_NAME, iaddr == null ? null : iaddr.getPersonal()); automation.putExtra("type", "GENERIC_EMAIL");
automation.putExtra(EXTRA_SUBJECT, message.subject); automation.putExtra("sender", iaddr == null ? null : MessageHelper.formatAddresses(new InternetAddress[]{iaddr}));
automation.putExtra(EXTRA_PREVIEW, preview); automation.putExtra("subject", message.subject);
automation.putExtra("body", TextUtils.isEmpty(preview) ? "-" : preview);
//automation.setPackage("nodomain.freeyourgadget.gadgetbridge");
} else {
automation = new Intent(ACTION_AUTOMATION);
automation.putExtra(EXTRA_RULE, name);
automation.putExtra(EXTRA_RECEIVED, DTF.format(message.received));
automation.putExtra(EXTRA_SENDER, iaddr == null ? null : iaddr.getAddress());
automation.putExtra(EXTRA_NAME, iaddr == null ? null : iaddr.getPersonal());
automation.putExtra(EXTRA_SUBJECT, message.subject);
automation.putExtra(EXTRA_PREVIEW, preview);
}
List<String> extras = Log.getExtras(automation.getExtras()); List<String> extras = Log.getExtras(automation.getExtras());
EntityLog.log(context, EntityLog.Type.Rules, message, EntityLog.log(context, EntityLog.Type.Rules, message,

@ -180,6 +180,8 @@ public class FragmentRule extends FragmentBase {
private TextView tvAutomation; private TextView tvAutomation;
private CheckBox cbGadgetBridge;
private EditText etNotes; private EditText etNotes;
private ViewButtonColor btnColorNotes; private ViewButtonColor btnColorNotes;
@ -394,6 +396,8 @@ public class FragmentRule extends FragmentBase {
tvAutomation = view.findViewById(R.id.tvAutomation); tvAutomation = view.findViewById(R.id.tvAutomation);
cbGadgetBridge = view.findViewById(R.id.cbGadgetBridge);
etNotes = view.findViewById(R.id.etNotes); etNotes = view.findViewById(R.id.etNotes);
btnColorNotes = view.findViewById(R.id.btnColorNotes); btnColorNotes = view.findViewById(R.id.btnColorNotes);
@ -972,6 +976,7 @@ public class FragmentRule extends FragmentBase {
grpTts.setVisibility(View.GONE); grpTts.setVisibility(View.GONE);
grpSound.setVisibility(View.GONE); grpSound.setVisibility(View.GONE);
grpAutomation.setVisibility(View.GONE); grpAutomation.setVisibility(View.GONE);
cbGadgetBridge.setVisibility(View.GONE);
grpDelete.setVisibility(View.GONE); grpDelete.setVisibility(View.GONE);
grpLocalOnly.setVisibility(View.GONE); grpLocalOnly.setVisibility(View.GONE);
grpNotes.setVisibility(View.GONE); grpNotes.setVisibility(View.GONE);
@ -1518,6 +1523,10 @@ public class FragmentRule extends FragmentBase {
etAlarmDuration.setText(duration == 0 ? null : Integer.toString(duration)); etAlarmDuration.setText(duration == 0 ? null : Integer.toString(duration));
break; break;
case EntityRule.TYPE_AUTOMATION:
cbGadgetBridge.setChecked(jaction.optBoolean("gadgetbridge"));
break;
case EntityRule.TYPE_NOTES: case EntityRule.TYPE_NOTES:
etNotes.setText(jaction.getString("notes")); etNotes.setText(jaction.getString("notes"));
btnColorNotes.setColor( btnColorNotes.setColor(
@ -1591,6 +1600,7 @@ public class FragmentRule extends FragmentBase {
grpTts.setVisibility(type == EntityRule.TYPE_TTS ? View.VISIBLE : View.GONE); grpTts.setVisibility(type == EntityRule.TYPE_TTS ? View.VISIBLE : View.GONE);
grpSound.setVisibility(type == EntityRule.TYPE_SOUND ? View.VISIBLE : View.GONE); grpSound.setVisibility(type == EntityRule.TYPE_SOUND ? View.VISIBLE : View.GONE);
grpAutomation.setVisibility(type == EntityRule.TYPE_AUTOMATION ? View.VISIBLE : View.GONE); grpAutomation.setVisibility(type == EntityRule.TYPE_AUTOMATION ? View.VISIBLE : View.GONE);
cbGadgetBridge.setVisibility(type == EntityRule.TYPE_AUTOMATION && BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
grpDelete.setVisibility(type == EntityRule.TYPE_DELETE ? View.VISIBLE : View.GONE); grpDelete.setVisibility(type == EntityRule.TYPE_DELETE ? View.VISIBLE : View.GONE);
grpLocalOnly.setVisibility(type == EntityRule.TYPE_LOCAL_ONLY ? View.VISIBLE : View.GONE); grpLocalOnly.setVisibility(type == EntityRule.TYPE_LOCAL_ONLY ? View.VISIBLE : View.GONE);
grpNotes.setVisibility(type == EntityRule.TYPE_NOTES ? View.VISIBLE : View.GONE); grpNotes.setVisibility(type == EntityRule.TYPE_NOTES ? View.VISIBLE : View.GONE);
@ -1964,6 +1974,10 @@ public class FragmentRule extends FragmentBase {
} }
break; break;
case EntityRule.TYPE_AUTOMATION:
jaction.put("gadgetbridge", cbGadgetBridge.isChecked());
break;
case EntityRule.TYPE_NOTES: case EntityRule.TYPE_NOTES:
jaction.put("notes", etNotes.getText().toString()); jaction.put("notes", etNotes.getText().toString());
int ncolor = btnColorNotes.getColor(); int ncolor = btnColorNotes.getColor();

@ -1373,6 +1373,15 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etAlarmDuration" /> app:layout_constraintTop_toBottomOf="@+id/etAlarmDuration" />
<CheckBox
android:id="@+id/cbGadgetBridge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_rule_automation_gadgetbridge"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAutomation" />
<TextView <TextView
android:id="@+id/tvDelete" android:id="@+id/tvDelete"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -1386,7 +1395,7 @@
android:textStyle="bold" android:textStyle="bold"
app:drawableTint="?attr/colorWarning" app:drawableTint="?attr/colorWarning"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvAutomation" /> app:layout_constraintTop_toBottomOf="@+id/cbGadgetBridge" />
<TextView <TextView
android:id="@+id/tvLocalOnly" android:id="@+id/tvLocalOnly"

@ -2204,6 +2204,7 @@
<string name="title_rule_answer_missing">Template missing</string> <string name="title_rule_answer_missing">Template missing</string>
<string name="title_rule_keyword_missing">Keyword missing</string> <string name="title_rule_keyword_missing">Keyword missing</string>
<string name="title_rule_automation_hint">This will send the intent \'%1$s\' with the extras \'%2$s\'</string> <string name="title_rule_automation_hint">This will send the intent \'%1$s\' with the extras \'%2$s\'</string>
<string name="title_rule_automation_gadgetbridge" translatable="false">GadgetBridge</string>
<string name="title_rule_notes_missing">Local notes missing</string> <string name="title_rule_notes_missing">Local notes missing</string>
<string name="title_rule_url_missing">URL missing or invalid</string> <string name="title_rule_url_missing">URL missing or invalid</string>
<string name="title_rule_delete_hint">Permanent deletion is irreversible, so make sure the rule conditions are correct!</string> <string name="title_rule_delete_hint">Permanent deletion is irreversible, so make sure the rule conditions are correct!</string>

Loading…
Cancel
Save