From 2ba25a9e65177962061fb48a4dc4b6bef795dc0b Mon Sep 17 00:00:00 2001 From: Jens Date: Thu, 28 Dec 2023 00:25:55 +0100 Subject: [PATCH] Calendar trigger --- .../java/com/jens/automation2/Action.java | 2 +- .../jens/automation2/ActivityManageRule.java | 4 ++ .../ActivityManageTriggerCalendar.java | 22 +++++++++++ .../java/com/jens/automation2/Trigger.java | 36 +++++++++++++++++- app/src/main/res/drawable-hdpi/variable.png | Bin 0 -> 2405 bytes .../activity_manage_trigger_calendar.xml | 7 ++++ app/src/main/res/values/strings.xml | 4 ++ 7 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/variable.png diff --git a/app/src/main/java/com/jens/automation2/Action.java b/app/src/main/java/com/jens/automation2/Action.java index 718b8d9..b152f18 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 73d8ec1..6111896 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 f270d87..e171bf3 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 4489bd7..4b47da7 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 0000000000000000000000000000000000000000..31b83bb9bb780e4a4a80220cb94dfd9a270a8c96 GIT binary patch literal 2405 zcmV-r37YnaP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D2>MAxK~!i%&02d* zROuDJ12gy*QLMZ~L=Z)h2z5fT#<-FkX@{#933H^iK zMLmMZFSu^qx<9f(0mR0}UdF)B4GRm?-MMqenGG`GBt}`da^*_$y?gfpNcQmX=u@dw zg=|m&fq{X)pEz+M%dcO*4#y%Tvmz5iGBM4~&6yn?9W49$`u_LQrAsE~5 zCL3fxw#Phu`ZN_)K|?aCQ6DC$j13CH)z$TDJey^BjZ0Nk)k;=mK-R>ZI(15eiAm_{ z>S7%g;(sSkp8O9h3IgGDeeBq=wIsiN`&MdbXpo&}WKGQ7yLY47+uMVMDg^}v>F|Pm zLRAd;`T1?gGv5hS!a_x5XJ^X_Cs`Bo`0-!|wr z`Z!h`gsh1{dHj%EmoRPGw9e_%r&qFK0ZW!Fi3c101mb}iGiH38nwlDDundgZvuBS0 zqum8DYs{E2pMW1NH(1PpN%_{r#f81~<;#~+V`JkYHaG}}CnhT^YeH{t?*~Ga`uh5+ za&mI&g=&WG?(W3S&dvger=C1{Qi$C2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z}R_9B7HniyF)ckY~9|M0+3ky?_zhZao+U1HWWfo2dQ(rurDiFU1s+3inf`5n6;*r#8s3p) zY-0WV{JIgUe`Do+qN}S*4NgORfmaMPycVuKhK&jUVdeu5A=<#thkS_*G9lYzsIyk9 z)y1d+tb?ccg1{xRq5#Uv%i|wCdc+S$C`$_#EKuyl^YrxO7xeY@)n{a6L>Mf?hn+ijCejaU5cMe0 zdNAD~`*Wh~P%;9{^a~{760G2L5Wj0JEiJ>o5e;6`jS#+u^89af)1Q@;lyH|WACmNc XNZM + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5eec015..33e89f1 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