fix(#464): an Open link button for reminders whose location is a web link
This commit is contained in:
1 parent
328c874670
commit
e5a5c10dea
6 files changed
+67
-1
No files matched your search
@@ -56,6 +56,17 @@
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent>
|
||||
<!-- A reminder's "Open link" button only shows when something can open the link (#464). -->
|
||||
<intent>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="https" />
|
||||
</intent>
|
||||
<intent>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="http" />
|
||||
</intent>
|
||||
</queries>
|
||||
|
||||
<application
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.core.net.toUri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
@@ -19,6 +20,7 @@ import de.jeanlucmakiola.calendula.data.prefs.CalendarPrefs
|
||||
import de.jeanlucmakiola.calendula.data.prefs.SettingsPrefs
|
||||
import de.jeanlucmakiola.calendula.data.prefs.is24Hour
|
||||
import de.jeanlucmakiola.calendula.data.prefs.resolveFirstDay
|
||||
import de.jeanlucmakiola.calendula.domain.reminders.reminderLink
|
||||
import de.jeanlucmakiola.calendula.domain.reminders.reminderMapQuery
|
||||
import de.jeanlucmakiola.floret.android.hasPermission
|
||||
import de.jeanlucmakiola.floret.android.resolvableMapsSearchIntent
|
||||
@@ -114,7 +116,10 @@ class ReminderNotifier @Inject constructor(
|
||||
actionIntent(alert, ReminderActionReceiver.ACTION_DISMISS),
|
||||
)
|
||||
.apply {
|
||||
mapIntent(alert)?.let {
|
||||
// Room for one more button: a meeting link beats the place, being the likelier next step.
|
||||
linkIntent(alert)?.let {
|
||||
addAction(R.drawable.ic_notification_link, context.getString(R.string.reminder_action_open_link), it)
|
||||
} ?: mapIntent(alert)?.let {
|
||||
addAction(R.drawable.ic_notification_map, context.getString(R.string.event_detail_open_in_maps), it)
|
||||
}
|
||||
}
|
||||
@@ -189,6 +194,24 @@ class ReminderNotifier @Inject constructor(
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
|
||||
)
|
||||
|
||||
/**
|
||||
* Opens the first web link in [alert]'s location, e.g. a meeting, started
|
||||
* directly like [mapIntent]. Null without a link or an app to open it.
|
||||
*/
|
||||
private fun linkIntent(alert: ReminderAlert): PendingIntent? {
|
||||
val link = reminderLink(alert.location) ?: return null
|
||||
val intent = Intent(Intent.ACTION_VIEW, link.toUri())
|
||||
.addCategory(Intent.CATEGORY_BROWSABLE)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
if (intent.resolveActivity(context.packageManager) == null) return null
|
||||
return PendingIntent.getActivity(
|
||||
context,
|
||||
/* requestCode = */ 0,
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens [alert]'s location in maps like the detail screen does, started
|
||||
* directly (no receiver trampoline). Leaves the notification up for a later
|
||||
|
||||
@@ -12,3 +12,7 @@ fun reminderMapQuery(location: String?): String? {
|
||||
val trimmed = location?.trim()?.takeIf { it.isNotEmpty() } ?: return null
|
||||
return trimmed.takeIf { webLinkRegex.replace(it, "").any(Char::isLetterOrDigit) }
|
||||
}
|
||||
|
||||
/** The first web (meeting) link in [location], for the reminder's "Open link" button; null without one. */
|
||||
fun reminderLink(location: String?): String? =
|
||||
location?.let { webLinkRegex.find(it)?.value?.trimEnd('.', ',', ';', ')', '>') }
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Monochrome notification-action mark: Material "link" glyph. -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M3.9,12c0,-1.71 1.39,-3.1 3.1,-3.1h4V7H7c-2.76,0 -5,2.24 -5,5s2.24,5 5,5h4v-1.9H7c-1.71,0 -3.1,-1.39 -3.1,-3.1zM8,13h8v-2H8v2zM17,7h-4v1.9h4c1.71,0 3.1,1.39 3.1,3.1s-1.39,3.1 -3.1,3.1h-4V17h4c2.76,0 5,-2.24 5,-5s-2.24,-5 -5,-5z" />
|
||||
</vector>
|
||||
@@ -231,6 +231,8 @@
|
||||
<string name="event_detail_title">Title</string>
|
||||
<string name="event_detail_location">Location</string>
|
||||
<string name="event_detail_open_in_maps">Open in maps</string>
|
||||
<!-- Reminder notification action opening the web (meeting) link in the event's location (#464) -->
|
||||
<string name="reminder_action_open_link">Open link</string>
|
||||
<string name="link_open_failed">No app can open this link</string>
|
||||
<string name="event_detail_description">Description</string>
|
||||
<string name="event_detail_attendees">Attendees</string>
|
||||
|
||||
+14
@@ -34,4 +34,18 @@ class ReminderMapQueryTest {
|
||||
fun `a place with a link beside it is still looked up`() {
|
||||
assertThat(reminderMapQuery("Room 4, https://example.com/map")).isEqualTo("Room 4, https://example.com/map")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the first web link is the reminder's link`() {
|
||||
assertThat(reminderLink("https://meet.google.com/abc-defg-hij")).isEqualTo("https://meet.google.com/abc-defg-hij")
|
||||
assertThat(reminderLink("<https://teams.microsoft.com/l/meetup-join/x>")).isEqualTo("https://teams.microsoft.com/l/meetup-join/x")
|
||||
assertThat(reminderLink("Room 4, https://example.com/map.")).isEqualTo("https://example.com/map")
|
||||
assertThat(reminderLink("https://a.example\nhttps://b.example")).isEqualTo("https://a.example")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `no link without one`() {
|
||||
assertThat(reminderLink(null)).isNull()
|
||||
assertThat(reminderLink("Hauptstr. 12/3, Wien")).isNull()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user