diff --git a/app/src/main/java/com/jens/automation2/Action.java b/app/src/main/java/com/jens/automation2/Action.java index 718b8d97..b152f18d 100644 --- a/app/src/main/java/com/jens/automation2/Action.java +++ b/app/src/main/java/com/jens/automation2/Action.java @@ -144,7 +144,7 @@ public class Action case takeScreenshot: return context.getResources().getString(R.string.takeScreenshot); case setLocationService: - return context.getResources().getString(R.string.setLocationService); + return context.getResources().getString(R.string.setLocationServiceCapital); default: return "Unknown"; } diff --git a/app/src/main/java/com/jens/automation2/ActivityManageRule.java b/app/src/main/java/com/jens/automation2/ActivityManageRule.java index 73d8ec16..6111896f 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageRule.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageRule.java @@ -644,6 +644,8 @@ public class ActivityManageRule extends Activity items.add(new Item(typesLong[i].toString(), R.drawable.router)); else if(types[i].toString().equals(Trigger_Enum.subSystemState.toString())) items.add(new Item(typesLong[i].toString(), R.drawable.subsystemstate)); + else if(types[i].toString().equals(Trigger_Enum.checkVariable.toString())) + items.add(new Item(typesLong[i].toString(), R.drawable.variable)); else if(types[i].toString().equals(Trigger_Enum.calendarEvent.toString())) items.add(new Item(typesLong[i].toString(), R.drawable.calendar)); else @@ -2203,6 +2205,8 @@ public class ActivityManageRule extends Activity items.add(new Item(typesLong[i].toString(), R.drawable.clipboard)); else if(types[i].toString().equals(Action_Enum.takeScreenshot.toString())) items.add(new Item(typesLong[i].toString(), R.drawable.copier)); + else if(types[i].toString().equals(Action_Enum.setVariable.toString())) + items.add(new Item(typesLong[i].toString(), R.drawable.variable)); else if(types[i].toString().equals(Action_Enum.setLocationService.toString())) items.add(new Item(typesLong[i].toString(), R.drawable.compass_small)); else diff --git a/app/src/main/java/com/jens/automation2/ActivityManageTriggerCalendar.java b/app/src/main/java/com/jens/automation2/ActivityManageTriggerCalendar.java index f270d87c..e171bf35 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageTriggerCalendar.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageTriggerCalendar.java @@ -12,6 +12,7 @@ import android.widget.CompoundButton; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.Spinner; +import android.widget.TextView; import androidx.annotation.Nullable; @@ -30,6 +31,7 @@ public class ActivityManageTriggerCalendar extends Activity Button bSaveTriggerCalendar; List checkboxesCalendars = new ArrayList<>(); final static String separator = ","; + TextView tvMissingCalendarHint; private static String[] directions; ArrayAdapter directionSpinnerAdapter; @@ -51,6 +53,8 @@ public class ActivityManageTriggerCalendar extends Activity chkCalendarAvailabilityOutOfOffice = (CheckBox)findViewById(R.id.chkCalendarAvailabilityOutOfOffice); chkCalendarAvailabilityWorkingElsewhere = (CheckBox)findViewById(R.id.chkCalendarAvailabilityWorkingElsewhere); + tvMissingCalendarHint = (TextView) findViewById(R.id.tvMissingCalendarHint); + llCalendarSelection = (LinearLayout)findViewById(R.id.llCalendarSelection); etCalendarTitle = (EditText)findViewById(R.id.etCalendarTitle); @@ -207,6 +211,8 @@ public class ActivityManageTriggerCalendar extends Activity chkCalendarAvailabilityWorkingElsewhere.setChecked(true); } + List usedCalendarIDs = new ArrayList<>(); + List unusedCalendarIDs = new ArrayList<>(); for(CheckBox checkbox : checkboxesCalendars) { int id = ((CalendarReceiver.AndroidCalendar)checkbox.getTag()).calendarId; @@ -214,11 +220,27 @@ public class ActivityManageTriggerCalendar extends Activity { if(calId.equals(String.valueOf(id))) { + usedCalendarIDs.add(String.valueOf(id)); checkbox.setChecked(true); break; } } } + for(String calId : calendars) + { + if(!Miscellaneous.arraySearch((ArrayList) usedCalendarIDs, calId, false, true)) + unusedCalendarIDs.add(calId); + } + if(unusedCalendarIDs.size() > 0) + { + /* + A calendar has been configured that has been deleted since. We cannot resolve it. + It will be removed with the next save, but we should inform this user + of these circumstances. + */ + + tvMissingCalendarHint.setText(String.format(getResources().getString(R.string.calendarsMissingHint), Miscellaneous.explode(", ", (ArrayList) unusedCalendarIDs))); + } } } } \ No newline at end of file diff --git a/app/src/main/java/com/jens/automation2/Trigger.java b/app/src/main/java/com/jens/automation2/Trigger.java index 4489bd78..4b47da7f 100644 --- a/app/src/main/java/com/jens/automation2/Trigger.java +++ b/app/src/main/java/com/jens/automation2/Trigger.java @@ -622,7 +622,7 @@ public class Trigger try { String[] conditions = this.getTriggerParameter2().split(Trigger.triggerParameter2Split); - List calendarEvents = CalendarReceiver.readCalendarEvents(AutomationService.getInstance(), true); + List calendarEvents = CalendarReceiver.readCalendarEvents(AutomationService.getInstance(), false); /* 0 = titleDirection @@ -1917,6 +1917,40 @@ public class Trigger returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.eventIsCurrentlyHappening)); else returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.eventIsCurrentlyNotHappening)); + + String[] conditions = triggerParameter2.split(triggerParameter2Split, -1); + + if( + !StringUtils.isEmpty(conditions[1]) + || + !StringUtils.isEmpty(conditions[3]) + || + !StringUtils.isEmpty(conditions[5]) + || + !StringUtils.isEmpty(conditions[6]) + || + !StringUtils.isEmpty(conditions[7])) + { + returnString.append(" ("); + + if (!StringUtils.isEmpty(conditions[1])) + returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.title) + " " + conditions[0] + " " + conditions[1] + ", "); + if (!StringUtils.isEmpty(conditions[3])) + returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.location) + " " + conditions[2] + " " + conditions[3] + ", "); + if (!StringUtils.isEmpty(conditions[5])) + returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.calendarDescription) + " " + conditions[4] + " " + conditions[5] + ", "); + + if (!StringUtils.isEmpty(conditions[6])) + returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.availabilities) + " " + conditions[6] + ", "); + + if (!StringUtils.isEmpty(conditions[7])) + returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.calendars) + " " + conditions[7]); + + if (returnString.toString().endsWith(", ")) + returnString.delete(returnString.length() - 2, returnString.length()); + + returnString.append(")"); + } break; default: returnString.append("error"); diff --git a/app/src/main/res/drawable-hdpi/variable.png b/app/src/main/res/drawable-hdpi/variable.png new file mode 100644 index 00000000..31b83bb9 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/variable.png differ diff --git a/app/src/main/res/layout/activity_manage_trigger_calendar.xml b/app/src/main/res/layout/activity_manage_trigger_calendar.xml index bc8c344f..4890bfd5 100644 --- a/app/src/main/res/layout/activity_manage_trigger_calendar.xml +++ b/app/src/main/res/layout/activity_manage_trigger_calendar.xml @@ -275,6 +275,13 @@ + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5eec0154..33e89f1b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -899,6 +899,7 @@ Required for certain actions. If you fail to grant one the following permission and a system message like \"Restricted permission\" you need to go to Android settings first, then applications, choose Automation. Now there should be 3 dots in the upper right corner. Click \"Allow restricted settings\". After that the necessary permission should be grantable. This should only apply to the APK version of the app, not the ones from F-Droid or Play Store. set location service + Set location service Unfortunately the permission WRITE_SECURE_SETTINGS cannot be given directly on your Android device. Instead you need to connect your device to a computer and grant the permission via ADB. Click here to find out how to grant it: https://server47.de/automation/adb_hack.php Location service SENSOR_ONLY @@ -920,4 +921,7 @@ Select no item if any will do. Calendars It may be that only the first 3 types are actually working becaue the other types are not part of Google Calendar. + any calender + availabilities + In this trigger calendars with IDs %1$s have been previously configured, but have been deleted since. With the next save those will be removed from this trigger. Until then this trigger/condition will never be met. \ No newline at end of file