fix in DateTimeTrigger management and executions when service already stopped

This commit is contained in:
jens 2022-04-03 14:46:28 +02:00
parent 7ed04c7ae2
commit 152b0c3c49
5 changed files with 57 additions and 18 deletions

View File

@ -256,8 +256,10 @@ public class ActivityManageRule extends Activity
switch(selectedTrigger.getTriggerType())
{
case timeFrame:
ActivityManageTriggerTimeFrame.editedTimeFrameTrigger = selectedTrigger;
// ActivityManageTriggerTimeFrame.editedTimeFrameTrigger = selectedTrigger;
Intent timeFrameEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerTimeFrame.class);
timeFrameEditor.putExtra(intentNameTriggerParameter1, selectedTrigger.getTriggerParameter());
timeFrameEditor.putExtra(intentNameTriggerParameter2, selectedTrigger.getTriggerParameter2());
startActivityForResult(timeFrameEditor, requestCodeTriggerTimeframeEdit);
break;
case bluetoothConnection:
@ -1232,9 +1234,15 @@ public class ActivityManageRule extends Activity
else if(requestCode == requestCodeTriggerTimeframeEdit)
{
//edit TimeFrame
if(resultCode == RESULT_OK && ActivityManageTriggerTimeFrame.editedTimeFrameTrigger != null)
if(resultCode == RESULT_OK && data.hasExtra(intentNameTriggerParameter2))
{
ActivityManageTriggerTimeFrame.editedTimeFrameTrigger.setParentRule(ruleToEdit);
Trigger responseTimeFrame = new Trigger();
responseTimeFrame.setTriggerType(Trigger_Enum.timeFrame);
responseTimeFrame.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
responseTimeFrame.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
responseTimeFrame.setTimeFrame(new TimeFrame(data.getStringExtra(intentNameTriggerParameter2)));
responseTimeFrame.setParentRule(ruleToEdit);
ruleToEdit.getTriggerSet().set(editIndex, responseTimeFrame);
this.refreshTriggerList();
}
else

View File

@ -1,6 +1,7 @@
package com.jens.automation2;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
@ -27,7 +28,7 @@ public class ActivityManageTriggerTimeFrame extends Activity
RadioButton radioTimeFrameEntering, radioTimeFrameLeaving;
EditText etRepeatEvery;
public static Trigger editedTimeFrameTrigger = null;
static Trigger editedTimeFrameTrigger = null;
@Override
protected void onCreate(Bundle savedInstanceState)
@ -152,8 +153,13 @@ public class ActivityManageTriggerTimeFrame extends Activity
}
editedTimeFrameTrigger.setTriggerParameter(radioTimeFrameEntering.isChecked());
editedTimeFrameTrigger.setTriggerParameter2(editedTimeFrameTrigger.getTimeFrame().toTriggerParameter2String());
setResult(RESULT_OK);
Intent response = new Intent();
response.putExtra(ActivityManageRule.intentNameTriggerParameter1, editedTimeFrameTrigger.getTriggerParameter());
response.putExtra(ActivityManageRule.intentNameTriggerParameter2, editedTimeFrameTrigger.getTriggerParameter2());
setResult(RESULT_OK, response);
finish();
}
});
@ -167,9 +173,15 @@ public class ActivityManageTriggerTimeFrame extends Activity
}
});
if(editedTimeFrameTrigger.getTimeFrame() != null)
if(getIntent().hasExtra(ActivityManageRule.intentNameTriggerParameter2))
{
editedTimeFrameTrigger = new Trigger();
editedTimeFrameTrigger.setTriggerParameter(getIntent().getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, true));
editedTimeFrameTrigger.setTriggerParameter2(getIntent().getStringExtra(ActivityManageRule.intentNameTriggerParameter2));
editedTimeFrameTrigger.setTimeFrame(new TimeFrame(editedTimeFrameTrigger.getTriggerParameter2()));
loadVariableIntoGui();
}
}
private void loadVariableIntoGui()
{
@ -219,5 +231,4 @@ public class ActivityManageTriggerTimeFrame extends Activity
etRepeatEvery.setText(String.valueOf(editedTimeFrameTrigger.getTimeFrame().getRepetition()));
}
}
}

View File

@ -80,6 +80,29 @@ public class TimeFrame
this.setRepetition(Long.parseLong(dateArray[3]));
}
public String toTriggerParameter2String()
{
StringBuilder response = new StringBuilder();
response.append(this.getTriggerTimeStart().getHours() + ":" + this.getTriggerTimeStart().getMinutes() + ":0");
response.append(separator);
response.append(this.getTriggerTimeStop().getHours() + ":" + this.getTriggerTimeStop().getMinutes() + ":0");
response.append(separator);
StringBuilder days = new StringBuilder();
for(int day : dayList)
days.append(String.valueOf(day));
response.append(days.toString());
if(this.repetition > 0)
{
response.append(separator + this.getRepetition());
}
return response.toString();
}
@Override
public String toString()
{

View File

@ -254,8 +254,6 @@ public class XmlFileInterface
else
serializer.text("null");
}
else if(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getTriggerType() == Trigger_Enum.timeFrame)
serializer.text(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getTimeFrame().toString());
else if(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getTriggerType() == Trigger_Enum.speed)
serializer.text(String.valueOf(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getSpeed()));
else if(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getTriggerType() == Trigger_Enum.noiseLevel)
@ -838,7 +836,6 @@ public class XmlFileInterface
private static Trigger readTrigger(XmlPullParser parser) throws IOException, XmlPullParserException
{
/* FILE EXAMPE:
* *****************
* <Automation>

View File

@ -29,8 +29,8 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
private static AlarmManager centralAlarmManagerInstance;
private static boolean alarmListenerActive=false;
private static ArrayList<ScheduleElement> alarmCandidates = new ArrayList<>();
private static ArrayList<Integer> requestCodeList = new ArrayList<Integer>();
static PendingIntent alarmPendingIntent = null;
public static void startAlarmListener(final AutomationService automationServiceRef)
{
@ -246,7 +246,7 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
}
Intent alarmIntent = new Intent(automationServiceRef, DateTimeListener.class);
PendingIntent alarmPendingIntent = PendingIntent.getBroadcast(automationServiceRef, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmPendingIntent = PendingIntent.getBroadcast(automationServiceRef, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
centralAlarmManagerInstance.set(AlarmManager.RTC_WAKEUP, scheduleCandidate.time.getTimeInMillis(), alarmPendingIntent);
SimpleDateFormat sdf = new SimpleDateFormat("E dd.MM.yyyy HH:mm");
@ -261,10 +261,10 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
for(int requestCode : requestCodeList)
{
Intent alarmIntent = new Intent(automationServiceRef, DateTimeListener.class);
PendingIntent alarmPendingIntent = PendingIntent.getBroadcast(automationServiceRef, requestCode, alarmIntent, 0);
if(alarmPendingIntent == null)
alarmPendingIntent = PendingIntent.getBroadcast(automationServiceRef, requestCode, alarmIntent, 0);
// Miscellaneous.logEvent("i", "AlarmManager", "Clearing alarm with request code: " + String.valueOf(requestCode));
centralAlarmManagerInstance.cancel(alarmPendingIntent);
centralAlarmManagerInstance.
}
requestCodeList.clear();
}
@ -298,7 +298,7 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
{
Miscellaneous.logEvent("i", "AlarmListener", "Stopping alarm listener.", 4);
clearAlarms();
// centralAlarmManagerInstance.cancel(alarmPendingIntent);
centralAlarmManagerInstance.cancel(alarmPendingIntent);
alarmListenerActive = false;
}
else