2023-12-23 13:55:02 +01:00
|
|
|
package com.jens.automation2;
|
|
|
|
|
2023-12-29 19:43:50 +01:00
|
|
|
import android.Manifest;
|
2023-12-23 13:55:02 +01:00
|
|
|
import android.app.Activity;
|
2023-12-29 19:43:50 +01:00
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.content.DialogInterface;
|
2023-12-25 11:57:55 +01:00
|
|
|
import android.content.Intent;
|
2023-12-29 19:43:50 +01:00
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.os.Build;
|
2023-12-23 13:55:02 +01:00
|
|
|
import android.os.Bundle;
|
2023-12-27 13:33:09 +01:00
|
|
|
import android.provider.CalendarContract;
|
2024-01-02 16:36:10 +01:00
|
|
|
import android.util.Log;
|
2023-12-25 11:57:55 +01:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.Button;
|
2023-12-23 13:55:02 +01:00
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.CompoundButton;
|
2023-12-25 11:57:55 +01:00
|
|
|
import android.widget.EditText;
|
2023-12-27 13:33:09 +01:00
|
|
|
import android.widget.LinearLayout;
|
2023-12-25 11:57:55 +01:00
|
|
|
import android.widget.Spinner;
|
2023-12-28 00:25:55 +01:00
|
|
|
import android.widget.TextView;
|
2024-01-02 16:36:10 +01:00
|
|
|
import android.widget.Toast;
|
2023-12-23 13:55:02 +01:00
|
|
|
|
2023-12-29 19:43:50 +01:00
|
|
|
import androidx.annotation.NonNull;
|
2023-12-23 13:55:02 +01:00
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
2023-12-27 13:33:09 +01:00
|
|
|
import com.jens.automation2.receivers.CalendarReceiver;
|
|
|
|
|
2023-12-28 17:17:08 +01:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
2023-12-27 13:33:09 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2023-12-23 13:55:02 +01:00
|
|
|
public class ActivityManageTriggerCalendar extends Activity
|
|
|
|
{
|
2024-01-02 16:36:10 +01:00
|
|
|
CheckBox chkCalendarEventActive, chkCalendarAvailabilityBusy, chkCalendarAvailabilityFree, chkCalendarAvailabilityTentative, chkCalendarAvailabilityOutOfOffice, chkCalendarAvailabilityWorkingElsewhere, chkCalendarAllDayEvent, calendarEvaluateAllDayEvent;
|
2023-12-27 13:33:09 +01:00
|
|
|
Spinner spinnerCalendarTitleDirection, spinnerCalendarLocationDirection, spinnerCalendarDescriptionDirection;
|
2023-12-25 11:57:55 +01:00
|
|
|
EditText etCalendarTitle, etCalendarLocation, etCalendarDescription;
|
2023-12-27 13:33:09 +01:00
|
|
|
LinearLayout llCalendarSelection;
|
2023-12-25 11:57:55 +01:00
|
|
|
Button bSaveTriggerCalendar;
|
2023-12-27 13:33:09 +01:00
|
|
|
List<CheckBox> checkboxesCalendars = new ArrayList<>();
|
2023-12-27 14:48:27 +01:00
|
|
|
final static String separator = ",";
|
2023-12-28 00:25:55 +01:00
|
|
|
TextView tvMissingCalendarHint;
|
2023-12-25 11:57:55 +01:00
|
|
|
|
|
|
|
private static String[] directions;
|
|
|
|
ArrayAdapter<String> directionSpinnerAdapter;
|
2023-12-29 19:43:50 +01:00
|
|
|
public static int requestCodePermissionReadCalendar = 815;
|
2023-12-25 11:57:55 +01:00
|
|
|
|
2023-12-23 13:55:02 +01:00
|
|
|
@Override
|
|
|
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
|
|
|
{
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
Miscellaneous.setDisplayLanguage(this);
|
|
|
|
setContentView(R.layout.activity_manage_trigger_calendar);
|
|
|
|
|
2023-12-27 14:48:27 +01:00
|
|
|
chkCalendarEventActive = (CheckBox) findViewById(R.id.chkCalendarEventActive);
|
2023-12-25 11:57:55 +01:00
|
|
|
spinnerCalendarTitleDirection = (Spinner)findViewById(R.id.spinnerCalendarTitleDirection);
|
|
|
|
spinnerCalendarLocationDirection = (Spinner)findViewById(R.id.spinnerCalendarLocationDirection);
|
|
|
|
spinnerCalendarDescriptionDirection = (Spinner)findViewById(R.id.spinnerCalendarDescriptionDirection);
|
2023-12-28 17:17:08 +01:00
|
|
|
chkCalendarAllDayEvent = (CheckBox)findViewById(R.id.chkCalendarAllDayEvent);
|
2023-12-27 13:33:09 +01:00
|
|
|
chkCalendarAvailabilityBusy = (CheckBox)findViewById(R.id.chkCalendarAvailabilityBusy);
|
|
|
|
chkCalendarAvailabilityFree = (CheckBox)findViewById(R.id.chkCalendarAvailabilityFree);
|
|
|
|
chkCalendarAvailabilityTentative = (CheckBox)findViewById(R.id.chkCalendarAvailabilityTentative);
|
|
|
|
chkCalendarAvailabilityOutOfOffice = (CheckBox)findViewById(R.id.chkCalendarAvailabilityOutOfOffice);
|
|
|
|
chkCalendarAvailabilityWorkingElsewhere = (CheckBox)findViewById(R.id.chkCalendarAvailabilityWorkingElsewhere);
|
2024-01-02 16:36:10 +01:00
|
|
|
calendarEvaluateAllDayEvent = (CheckBox)findViewById(R.id.calendarEvaluateAllDayEvent);
|
2023-12-27 13:33:09 +01:00
|
|
|
|
2023-12-28 00:25:55 +01:00
|
|
|
tvMissingCalendarHint = (TextView) findViewById(R.id.tvMissingCalendarHint);
|
|
|
|
|
2023-12-27 13:33:09 +01:00
|
|
|
llCalendarSelection = (LinearLayout)findViewById(R.id.llCalendarSelection);
|
2023-12-25 11:57:55 +01:00
|
|
|
|
|
|
|
etCalendarTitle = (EditText)findViewById(R.id.etCalendarTitle);
|
|
|
|
etCalendarLocation = (EditText)findViewById(R.id.etCalendarLocation);
|
|
|
|
etCalendarDescription = (EditText)findViewById(R.id.etCalendarDescription);
|
|
|
|
|
|
|
|
bSaveTriggerCalendar = (Button)findViewById(R.id.bSaveTriggerCalendar);
|
|
|
|
|
|
|
|
directions = new String[] {
|
|
|
|
getResources().getString(R.string.directionStringEquals),
|
|
|
|
getResources().getString(R.string.directionStringContains),
|
|
|
|
getResources().getString(R.string.directionStringDoesNotContain),
|
|
|
|
getResources().getString(R.string.directionStringStartsWith),
|
|
|
|
getResources().getString(R.string.directionStringEndsWith),
|
|
|
|
getResources().getString(R.string.directionStringNotEquals)
|
|
|
|
};
|
2024-01-02 16:36:10 +01:00
|
|
|
directionSpinnerAdapter = new ArrayAdapter<>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ActivityManageTriggerCalendar.directions);
|
2023-12-25 11:57:55 +01:00
|
|
|
spinnerCalendarTitleDirection.setAdapter(directionSpinnerAdapter);
|
|
|
|
spinnerCalendarLocationDirection.setAdapter(directionSpinnerAdapter);
|
|
|
|
spinnerCalendarDescriptionDirection.setAdapter(directionSpinnerAdapter);
|
|
|
|
directionSpinnerAdapter.notifyDataSetChanged();
|
|
|
|
|
2024-01-02 16:36:10 +01:00
|
|
|
calendarEvaluateAllDayEvent.setChecked(false);
|
|
|
|
chkCalendarAllDayEvent.setEnabled(false);
|
|
|
|
calendarEvaluateAllDayEvent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked)
|
|
|
|
{
|
|
|
|
chkCalendarAllDayEvent.setEnabled(checked);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-12-29 19:43:50 +01:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
2023-12-27 13:33:09 +01:00
|
|
|
{
|
2023-12-29 19:43:50 +01:00
|
|
|
if(ActivityPermissions.havePermission(Manifest.permission.READ_CALENDAR, ActivityManageTriggerCalendar.this) || ActivityPermissions.havePermission(Manifest.permission.WRITE_CALENDAR, ActivityManageTriggerCalendar.this))
|
|
|
|
populateCalenderCheckboxes();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(ActivityManageTriggerCalendar.this);
|
|
|
|
builder.setTitle(getResources().getString(R.string.info));
|
|
|
|
builder.setMessage(getResources().getString(R.string.permissionCalendarRequired));
|
|
|
|
builder.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i)
|
|
|
|
{
|
|
|
|
ActivityManageTriggerCalendar.this.finish();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i)
|
|
|
|
{
|
|
|
|
requestPermissions(new String[]{ Manifest.permission.READ_CALENDAR } , requestCodePermissionReadCalendar);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.show();
|
|
|
|
}
|
2023-12-27 13:33:09 +01:00
|
|
|
}
|
2023-12-29 19:43:50 +01:00
|
|
|
else
|
|
|
|
populateCalenderCheckboxes();
|
2023-12-23 13:55:02 +01:00
|
|
|
|
2023-12-27 14:48:27 +01:00
|
|
|
chkCalendarEventActive.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
2023-12-23 13:55:02 +01:00
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked)
|
|
|
|
{
|
|
|
|
if(checked)
|
2023-12-27 14:48:27 +01:00
|
|
|
chkCalendarEventActive.setText(R.string.eventIsCurrentlyHappening);
|
2023-12-23 13:55:02 +01:00
|
|
|
else
|
2023-12-27 14:48:27 +01:00
|
|
|
chkCalendarEventActive.setText(R.string.eventIsCurrentlyNotHappening);
|
2023-12-23 13:55:02 +01:00
|
|
|
}
|
|
|
|
});
|
2023-12-25 11:57:55 +01:00
|
|
|
|
2023-12-28 17:17:08 +01:00
|
|
|
chkCalendarAllDayEvent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked)
|
|
|
|
{
|
|
|
|
if(checked)
|
|
|
|
chkCalendarAllDayEvent.setText(getResources().getString(R.string.allDayEventTrue));
|
|
|
|
else
|
|
|
|
chkCalendarAllDayEvent.setText(getResources().getString(R.string.allDayEventFalse));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-12-25 11:57:55 +01:00
|
|
|
bSaveTriggerCalendar.setOnClickListener(new View.OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(View view)
|
|
|
|
{
|
|
|
|
String titleDir = Trigger.getMatchCode(spinnerCalendarTitleDirection.getSelectedItem().toString());
|
|
|
|
String title = etCalendarTitle.getText().toString();
|
|
|
|
String descriptionDir = Trigger.getMatchCode(spinnerCalendarDescriptionDirection.getSelectedItem().toString());
|
|
|
|
String description = etCalendarDescription.getText().toString();
|
|
|
|
String locationDir = Trigger.getMatchCode(spinnerCalendarLocationDirection.getSelectedItem().toString());
|
|
|
|
String location = etCalendarLocation.getText().toString();
|
2023-12-27 13:33:09 +01:00
|
|
|
|
|
|
|
List<String> availabilityList = new ArrayList<>();
|
|
|
|
if(chkCalendarAvailabilityBusy.isChecked())
|
|
|
|
availabilityList.add(String.valueOf(CalendarContract.Events.AVAILABILITY_BUSY));
|
|
|
|
|
|
|
|
if(chkCalendarAvailabilityFree.isChecked())
|
|
|
|
availabilityList.add(String.valueOf(CalendarContract.Events.AVAILABILITY_FREE));
|
|
|
|
|
|
|
|
if(chkCalendarAvailabilityTentative.isChecked())
|
|
|
|
availabilityList.add(String.valueOf(CalendarContract.Events.AVAILABILITY_TENTATIVE));
|
|
|
|
|
|
|
|
if(chkCalendarAvailabilityOutOfOffice.isChecked())
|
|
|
|
availabilityList.add(String.valueOf(CalendarReceiver.AVAILABILITY_OUT_OF_OFFICE));
|
|
|
|
|
|
|
|
if(chkCalendarAvailabilityWorkingElsewhere.isChecked())
|
|
|
|
availabilityList.add(String.valueOf(CalendarReceiver.AVAILABILITY_WORKING_ELSEWHERE));
|
|
|
|
|
|
|
|
List<CalendarReceiver.AndroidCalendar> selectedCalendarsList = new ArrayList<>();
|
|
|
|
for(CheckBox calCheckbox : checkboxesCalendars)
|
|
|
|
{
|
|
|
|
if(calCheckbox.isChecked())
|
|
|
|
selectedCalendarsList.add((CalendarReceiver.AndroidCalendar) calCheckbox.getTag());
|
|
|
|
}
|
2023-12-27 14:48:27 +01:00
|
|
|
List<String> selectedCalendarsIdArray = new ArrayList<>();
|
|
|
|
for(CalendarReceiver.AndroidCalendar cal : selectedCalendarsList)
|
|
|
|
selectedCalendarsIdArray.add(String.valueOf(cal.calendarId));
|
2023-12-25 11:57:55 +01:00
|
|
|
|
|
|
|
String returnString =
|
|
|
|
titleDir + Trigger.triggerParameter2Split + title + Trigger.triggerParameter2Split +
|
|
|
|
descriptionDir + Trigger.triggerParameter2Split + description + Trigger.triggerParameter2Split +
|
|
|
|
locationDir + Trigger.triggerParameter2Split + location + Trigger.triggerParameter2Split +
|
2024-01-02 16:36:10 +01:00
|
|
|
String.valueOf(calendarEvaluateAllDayEvent.isChecked()) + Trigger.triggerParameter2Split +
|
2023-12-28 17:17:08 +01:00
|
|
|
String.valueOf(chkCalendarAllDayEvent.isChecked()) + Trigger.triggerParameter2Split +
|
2023-12-27 14:48:27 +01:00
|
|
|
Miscellaneous.explode(separator, availabilityList.toArray(new String[availabilityList.size()])) + Trigger.triggerParameter2Split +
|
|
|
|
Miscellaneous.explode(separator, selectedCalendarsIdArray.toArray(new String[selectedCalendarsIdArray.size()]));
|
2023-12-25 11:57:55 +01:00
|
|
|
|
|
|
|
Intent data = new Intent();
|
2023-12-27 14:48:27 +01:00
|
|
|
data.putExtra(ActivityManageRule.intentNameTriggerParameter1, chkCalendarEventActive.isChecked());
|
2023-12-25 11:57:55 +01:00
|
|
|
data.putExtra(ActivityManageRule.intentNameTriggerParameter2, returnString);
|
|
|
|
ActivityManageTriggerCalendar.this.setResult(RESULT_OK, data);
|
|
|
|
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Intent inputIntent = getIntent();
|
|
|
|
if(inputIntent.hasExtra(ActivityManageRule.intentNameTriggerParameter1))
|
|
|
|
loadValuesIntoGui(inputIntent);
|
|
|
|
}
|
|
|
|
|
2023-12-29 19:43:50 +01:00
|
|
|
private void populateCalenderCheckboxes()
|
|
|
|
{
|
|
|
|
List<CalendarReceiver.AndroidCalendar> calList = CalendarReceiver.readCalendars(ActivityManageTriggerCalendar.this);
|
|
|
|
|
|
|
|
if(calList != null)
|
|
|
|
{
|
|
|
|
if(calList.size() > 0)
|
|
|
|
{
|
|
|
|
for (CalendarReceiver.AndroidCalendar cal : calList)
|
|
|
|
{
|
|
|
|
CheckBox oneCalCheckbox = new CheckBox(ActivityManageTriggerCalendar.this);
|
|
|
|
oneCalCheckbox.setText(cal.toString());
|
|
|
|
oneCalCheckbox.setTag(cal);
|
|
|
|
llCalendarSelection.addView(oneCalCheckbox);
|
|
|
|
checkboxesCalendars.add(oneCalCheckbox);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Miscellaneous.messageBox(getResources().getString(R.string.warning), getResources().getString(R.string.noCalendarsOnYourDevice), ActivityManageTriggerCalendar.this).show();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Miscellaneous.messageBox(getResources().getString(R.string.warning), getResources().getString(R.string.errorReadingCalendars), ActivityManageTriggerCalendar.this).show();
|
|
|
|
}
|
|
|
|
|
2023-12-25 11:57:55 +01:00
|
|
|
void loadValuesIntoGui(Intent data)
|
|
|
|
{
|
2024-01-02 16:36:10 +01:00
|
|
|
try
|
2023-12-25 11:57:55 +01:00
|
|
|
{
|
2024-01-02 16:36:10 +01:00
|
|
|
if (data.hasExtra(ActivityManageRule.intentNameTriggerParameter1))
|
|
|
|
chkCalendarEventActive.setChecked(data.getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, true));
|
|
|
|
|
|
|
|
if (data.hasExtra(ActivityManageRule.intentNameTriggerParameter2))
|
|
|
|
{
|
|
|
|
String input[] = data.getStringExtra(ActivityManageRule.intentNameTriggerParameter2).split(Trigger.triggerParameter2Split, -1);
|
2023-12-25 11:57:55 +01:00
|
|
|
/*
|
|
|
|
0 = titleDir
|
|
|
|
1 = title
|
|
|
|
2 = descriptionDir
|
|
|
|
3 = description
|
|
|
|
4 = locationDir
|
|
|
|
5 = location
|
2024-01-02 16:36:10 +01:00
|
|
|
6 = evaluate all day event
|
|
|
|
7 = all day event
|
|
|
|
8 = availability list
|
|
|
|
9 = calendars list
|
2023-12-25 11:57:55 +01:00
|
|
|
*/
|
|
|
|
|
2024-01-02 16:36:10 +01:00
|
|
|
for (int i = 0; i < directions.length; i++)
|
|
|
|
{
|
|
|
|
if (Trigger.getMatchCode(directions[i]).equalsIgnoreCase(input[0]))
|
|
|
|
spinnerCalendarTitleDirection.setSelection(i);
|
2023-12-25 11:57:55 +01:00
|
|
|
|
2024-01-02 16:36:10 +01:00
|
|
|
if (Trigger.getMatchCode(directions[i]).equalsIgnoreCase(input[2]))
|
|
|
|
spinnerCalendarDescriptionDirection.setSelection(i);
|
2023-12-25 11:57:55 +01:00
|
|
|
|
2024-01-02 16:36:10 +01:00
|
|
|
if (Trigger.getMatchCode(directions[i]).equalsIgnoreCase(input[4]))
|
|
|
|
spinnerCalendarLocationDirection.setSelection(i);
|
|
|
|
}
|
2023-12-25 11:57:55 +01:00
|
|
|
|
2024-01-02 16:36:10 +01:00
|
|
|
etCalendarTitle.setText(input[1]);
|
|
|
|
etCalendarDescription.setText(input[3]);
|
|
|
|
etCalendarLocation.setText(input[5]);
|
2023-12-27 14:48:27 +01:00
|
|
|
|
2024-01-02 16:36:10 +01:00
|
|
|
calendarEvaluateAllDayEvent.setChecked(Boolean.parseBoolean(input[6]));
|
|
|
|
chkCalendarAllDayEvent.setChecked(Boolean.parseBoolean(input[7]));
|
2023-12-28 17:17:08 +01:00
|
|
|
|
2024-01-02 16:36:10 +01:00
|
|
|
String[] availabilities = null;
|
|
|
|
if (!StringUtils.isEmpty(input[8]))
|
|
|
|
availabilities = input[8].split(separator);
|
2023-12-27 14:48:27 +01:00
|
|
|
|
2024-01-02 16:36:10 +01:00
|
|
|
if (availabilities != null)
|
2023-12-28 17:17:08 +01:00
|
|
|
{
|
2024-01-02 16:36:10 +01:00
|
|
|
for (String avail : availabilities)
|
|
|
|
{
|
|
|
|
if (Integer.parseInt(avail) == CalendarContract.Events.AVAILABILITY_BUSY)
|
|
|
|
chkCalendarAvailabilityBusy.setChecked(true);
|
|
|
|
else if (Integer.parseInt(avail) == CalendarContract.Events.AVAILABILITY_FREE)
|
|
|
|
chkCalendarAvailabilityFree.setChecked(true);
|
|
|
|
else if (Integer.parseInt(avail) == CalendarContract.Events.AVAILABILITY_TENTATIVE)
|
|
|
|
chkCalendarAvailabilityTentative.setChecked(true);
|
|
|
|
else if (Integer.parseInt(avail) == CalendarReceiver.AVAILABILITY_OUT_OF_OFFICE)
|
|
|
|
chkCalendarAvailabilityOutOfOffice.setChecked(true);
|
|
|
|
else if (Integer.parseInt(avail) == CalendarReceiver.AVAILABILITY_WORKING_ELSEWHERE)
|
|
|
|
chkCalendarAvailabilityWorkingElsewhere.setChecked(true);
|
|
|
|
}
|
2023-12-28 17:17:08 +01:00
|
|
|
}
|
2023-12-27 14:48:27 +01:00
|
|
|
|
2024-01-02 16:36:10 +01:00
|
|
|
String[] calendars = null;
|
|
|
|
if (!StringUtils.isEmpty(input[9]))
|
|
|
|
calendars = input[9].split(separator);
|
2023-12-29 19:43:50 +01:00
|
|
|
|
2024-01-02 16:36:10 +01:00
|
|
|
if (calendars != null)
|
2023-12-27 14:48:27 +01:00
|
|
|
{
|
2024-01-02 16:36:10 +01:00
|
|
|
List<String> usedCalendarIDs = new ArrayList<>();
|
|
|
|
List<String> unusedCalendarIDs = new ArrayList<>();
|
|
|
|
for (CheckBox checkbox : checkboxesCalendars)
|
2023-12-27 14:48:27 +01:00
|
|
|
{
|
2024-01-02 16:36:10 +01:00
|
|
|
int id = ((CalendarReceiver.AndroidCalendar) checkbox.getTag()).calendarId;
|
|
|
|
for (String calId : calendars)
|
2023-12-28 17:17:08 +01:00
|
|
|
{
|
2024-01-02 16:36:10 +01:00
|
|
|
if (calId.equals(String.valueOf(id)))
|
|
|
|
{
|
|
|
|
usedCalendarIDs.add(String.valueOf(id));
|
|
|
|
checkbox.setChecked(true);
|
|
|
|
break;
|
|
|
|
}
|
2023-12-28 17:17:08 +01:00
|
|
|
}
|
2023-12-27 14:48:27 +01:00
|
|
|
}
|
2024-01-02 16:36:10 +01:00
|
|
|
for (String calId : calendars)
|
|
|
|
{
|
|
|
|
if (!Miscellaneous.arraySearch((ArrayList<String>) usedCalendarIDs, calId, false, true))
|
|
|
|
unusedCalendarIDs.add(calId);
|
|
|
|
}
|
|
|
|
if (unusedCalendarIDs.size() > 0)
|
|
|
|
{
|
2023-12-28 00:25:55 +01:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2024-01-02 16:36:10 +01:00
|
|
|
tvMissingCalendarHint.setText(String.format(getResources().getString(R.string.calendarsMissingHint), Miscellaneous.explode(", ", (ArrayList<String>) unusedCalendarIDs)));
|
|
|
|
}
|
2023-12-28 17:17:08 +01:00
|
|
|
}
|
2023-12-28 00:25:55 +01:00
|
|
|
}
|
2023-12-25 11:57:55 +01:00
|
|
|
}
|
2024-01-02 16:36:10 +01:00
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Miscellaneous.logEvent("e", "ActivityManagerTriggerCalender", "Error loading values into GUI: " + Log.getStackTraceString(e), 1);
|
|
|
|
Toast.makeText(ActivityManageTriggerCalendar.this, getResources().getString(R.string.errorLoadingValues), Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
2023-12-23 13:55:02 +01:00
|
|
|
}
|
2023-12-29 19:43:50 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
|
|
|
|
{
|
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
|
|
|
|
|
if(requestCode == requestCodePermissionReadCalendar)
|
|
|
|
{
|
|
|
|
if(
|
|
|
|
permissions[0].equals(Manifest.permission.READ_CALENDAR)
|
|
|
|
||
|
|
|
|
permissions[0].equals(Manifest.permission.WRITE_CALENDAR)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if(grantResults[0] == PackageManager.PERMISSION_GRANTED)
|
|
|
|
populateCalenderCheckboxes();
|
|
|
|
else
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-12-27 14:48:27 +01:00
|
|
|
}
|