Skip to content

Commit

Permalink
Adds an option to ignore calendar visibility
Browse files Browse the repository at this point in the history
Fixes #508 with a workaround
  • Loading branch information
hufman committed Jan 20, 2022
1 parent 3dc753e commit a2f197f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface AppSettings {
ENABLED_CALENDAR("Enabled_Calendar", "false", "Show Calendar in the car"),
CALENDAR_DETAILED_EVENTS("Calendar_Detailed_Events", "false", "Only show detailed appointments"),
CALENDAR_AUTOMATIC_NAVIGATION("Calendar_Automatic_Navigation", "false", "Automatically navigate to upcoming appointments"),
CALENDAR_IGNORE_VISIBILITY("Calendar_Ignore_Visibility", "false", "Ignore calendar visibility for events"),
ENABLED_GMAPS("Enabled_GMaps", "false", "Show Google Maps in the car"),
MAP_WIDESCREEN("Map_Widescreen", "false", "Show Map in widescreen"),
MAP_INVERT_SCROLL("Map_Invert_Scroll", "false", "Invert zoom direction"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,16 @@ class CalendarProvider(val context: Context, val appSettings: AppSettings) {
}

val cursor = try {
// manually querying Instances table, ignoring VISIBLE flag
val builder = CalendarContract.Instances.CONTENT_URI.buildUpon()
ContentUris.appendId(builder, queryStart.timeInMillis)
ContentUris.appendId(builder, queryEnd.timeInMillis)
context.contentResolver.query(builder.build(), PROJECTION,
null,null, "begin ASC")
if (appSettings[AppSettings.KEYS.CALENDAR_IGNORE_VISIBILITY].toBoolean()) {
// manually query Instances table, ignoring VISIBLE flag
val builder = CalendarContract.Instances.CONTENT_URI.buildUpon()
ContentUris.appendId(builder, queryStart.timeInMillis)
ContentUris.appendId(builder, queryEnd.timeInMillis)
context.contentResolver.query(builder.build(), PROJECTION,
null, null, "begin ASC")
} else {
CalendarContract.Instances.query(context.contentResolver, PROJECTION, queryStart.timeInMillis, queryEnd.timeInMillis)
}
} catch (e: SecurityException) { null }
if (cursor != null) {
cursor.moveToFirst()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class CalendarEventsFragment: Fragment() {
val eventsAdapter by lazy {
DataBoundArrayAdapter(requireContext(), R.layout.calendarevent_listitem, calendarEventsModel.upcomingEvents, null)
}
val calendarDetailedEventsSettings by lazy {BooleanLiveSetting(requireContext().applicationContext, AppSettings.KEYS.CALENDAR_DETAILED_EVENTS)}
val calendarDetailedEventsSetting by lazy {BooleanLiveSetting(requireContext().applicationContext, AppSettings.KEYS.CALENDAR_DETAILED_EVENTS)}
val calendarIgnoreVisibilitySetting by lazy {BooleanLiveSetting(requireContext().applicationContext, AppSettings.KEYS.CALENDAR_IGNORE_VISIBILITY)}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_calendar_events, container, false)
Expand All @@ -34,7 +35,10 @@ class CalendarEventsFragment: Fragment() {
emptyView = view.findViewById<TextView>(R.id.txtEmptyCalendarEvents)
adapter = eventsAdapter
}
calendarDetailedEventsSettings.observe(viewLifecycleOwner) {
calendarDetailedEventsSetting.observe(viewLifecycleOwner) {
redraw()
}
calendarIgnoreVisibilitySetting.observe(viewLifecycleOwner) {
redraw()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ class CalendarSettingsModel(appContext: Context, carInformation: CarInformation,
}
}

val advancedSettings = BooleanLiveSetting(appContext, AppSettings.KEYS.SHOW_ADVANCED_SETTINGS)
val calendarEnabled = BooleanLiveSetting(appContext, AppSettings.KEYS.ENABLED_CALENDAR)
val detailedEvents = BooleanLiveSetting(appContext, AppSettings.KEYS.CALENDAR_DETAILED_EVENTS)
val ignoreVisibility = BooleanLiveSetting(appContext, AppSettings.KEYS.CALENDAR_IGNORE_VISIBILITY)
val autonav = BooleanLiveSetting(appContext, AppSettings.KEYS.CALENDAR_AUTOMATIC_NAVIGATION)
val isNaviNotSupported = FunctionalLiveData {
carInformation.capabilities["navi"]?.lowercase(Locale.ROOT) == "false"
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout/fragment_calendar_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,15 @@
android:visibility="@{settings.isNaviNotSupported()}"
android:text="@string/txt_capabilities_navi_no" />
</LinearLayout>

<androidx.appcompat.widget.SwitchCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:paddingBottom="@dimen/settings_vertical_margin"
android:text="@string/lbl_calendar_ignore_visibility"
android:visibility="@{settings.advancedSettings}"
android:checked="@={settings.ignoreVisibility}"/>

</LinearLayout>
</layout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<string name="lbl_calendar_xiaomi_installed">Events in Mi Calendar may not be visible in the car</string>
<string name="lbl_calendar_detailed_events">Hide events without details or locations</string>
<string name="lbl_calendar_automatic_navigation">Automatically navigate to upcoming appointments</string>
<string name="lbl_calendar_ignore_visibility">Include events from hidden calendars</string>
<string name="lbl_calendar_calendars">Calendars:</string>
<string name="lbl_calendar_calendars_empty">No calendars found</string>
<string name="lbl_calendar_upcoming_events">Upcoming events:</string>
Expand Down

0 comments on commit a2f197f

Please sign in to comment.