Calendar trigger

This commit is contained in:
2023-12-28 00:25:55 +01:00
parent d2606b72cd
commit 2ba25a9e65
7 changed files with 73 additions and 2 deletions

View File

@ -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";
}

View File

@ -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

View File

@ -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<CheckBox> checkboxesCalendars = new ArrayList<>();
final static String separator = ",";
TextView tvMissingCalendarHint;
private static String[] directions;
ArrayAdapter<String> 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<String> usedCalendarIDs = new ArrayList<>();
List<String> 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<String>) 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<String>) unusedCalendarIDs)));
}
}
}
}

View File

@ -622,7 +622,7 @@ public class Trigger
try
{
String[] conditions = this.getTriggerParameter2().split(Trigger.triggerParameter2Split);
List<CalendarReceiver.CalendarEvent> calendarEvents = CalendarReceiver.readCalendarEvents(AutomationService.getInstance(), true);
List<CalendarReceiver.CalendarEvent> 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");