add some Calendar open intent handling

This commit is contained in:
tibbi 2017-10-06 20:09:17 +02:00
parent c64b1d10cf
commit 6781860a92
2 changed files with 32 additions and 1 deletions

View File

@ -38,6 +38,15 @@
<data android:mimeType="text/x-vcalendar"/> <data android:mimeType="text/x-vcalendar"/>
<data android:mimeType="text/calendar"/> <data android:mimeType="text/calendar"/>
</intent-filter> </intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="time/epoch"/>
<data android:host="com.android.calendar"/>
<data android:scheme="content"/>
</intent-filter>
</activity> </activity>
<activity <activity

View File

@ -81,12 +81,26 @@ class MainActivity : SimpleActivity(), NavigationListener {
calendar_fab.setOnClickListener { launchNewEventIntent() } calendar_fab.setOnClickListener { launchNewEventIntent() }
checkWhatsNewDialog() checkWhatsNewDialog()
storeStoragePaths() storeStoragePaths()
if (resources.getBoolean(R.bool.portrait_only)) if (resources.getBoolean(R.bool.portrait_only))
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
if (intent?.action == Intent.ACTION_VIEW && intent.data != null) { if (intent?.action == Intent.ACTION_VIEW && intent.data != null) {
tryImportEventsFromFile(intent.data) val uri = intent.data
if (uri.authority == "com.android.calendar") {
// clicking date on a 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())
return
}
}
} else {
tryImportEventsFromFile(uri)
}
} }
storeStateVariables() storeStateVariables()
updateViewPager() updateViewPager()
@ -578,6 +592,14 @@ class MainActivity : SimpleActivity(), NavigationListener {
mIsMonthSelected = true mIsMonthSelected = true
} }
private fun openDayAt(timestamp: Long) {
val dayCode = Formatter.getDayCodeFromTS((timestamp / 1000).toInt())
Intent(this, DayActivity::class.java).apply {
putExtra(DAY_CODE, dayCode)
startActivity(this)
}
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) { override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults) super.onRequestPermissionsResult(requestCode, permissions, grantResults)