fix #357, handle com.android.calendar/events intent

This commit is contained in:
tibbi 2018-03-26 16:34:09 +02:00
parent ceab435410
commit aa14d3022d
3 changed files with 32 additions and 2 deletions

View File

@ -61,6 +61,12 @@
<data android:host="com.android.calendar"/>
<data android:scheme="content"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="vnd.android.cursor.item/event"/>
</intent-filter>
</activity>
<activity

View File

@ -83,8 +83,20 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
if (intent?.action == Intent.ACTION_VIEW && intent.data != null) {
val uri = intent.data
if (uri.authority == "com.android.calendar") {
if (uri.path.startsWith("/events")) {
// intents like content://com.android.calendar/events/1756
val eventId = uri.lastPathSegment
val id = dbHelper.getEventIdWithLastImportId(eventId)
if (id != 0) {
Intent(this, EventActivity::class.java).apply {
putExtra(EVENT_ID, id)
startActivity(this)
}
} else {
toast(R.string.unknown_error_occurred)
}
} else if (intent?.extras?.getBoolean("DETAIL_VIEW", false) == true) {
// clicking date on a third party widget: content://com.android.calendar/time/1507309245683
if (intent?.extras?.getBoolean("DETAIL_VIEW", false) == true) {
val timestamp = uri.pathSegments.last()
if (timestamp.areDigitsOnly()) {
openDayAt(timestamp.toLong())

View File

@ -605,6 +605,18 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
}
}
fun getEventIdWithLastImportId(id: String): Int {
val selection = "$MAIN_TABLE_NAME.$COL_IMPORT_ID LIKE ?"
val selectionArgs = arrayOf("%-$id")
val cursor = getEventsCursor(selection, selectionArgs)
val events = fillEvents(cursor)
return if (events.isNotEmpty()) {
events.minBy { it.id }?.id ?: 0
} else {
0
}
}
fun getEventsWithSearchQuery(text: String, callback: (searchedText: String, events: List<Event>) -> Unit) {
Thread {
val searchQuery = "%$text%"