mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
properly handle File Open intent if the app is just backgrounded
This commit is contained in:
@ -83,32 +83,8 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||||
}
|
}
|
||||||
|
|
||||||
if (intent?.action == Intent.ACTION_VIEW && intent.data != null) {
|
if (!checkViewIntents()) {
|
||||||
val uri = intent.data
|
return
|
||||||
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
|
|
||||||
val timestamp = uri.pathSegments.last()
|
|
||||||
if (timestamp.areDigitsOnly()) {
|
|
||||||
openDayAt(timestamp.toLong())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
tryImportEventsFromFile(uri)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!checkOpenIntents()) {
|
if (!checkOpenIntents()) {
|
||||||
@ -213,6 +189,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
super.onNewIntent(intent)
|
super.onNewIntent(intent)
|
||||||
setIntent(intent)
|
setIntent(intent)
|
||||||
checkOpenIntents()
|
checkOpenIntents()
|
||||||
|
checkViewIntents()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun storeStateVariables() {
|
private fun storeStateVariables() {
|
||||||
@ -293,6 +270,37 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun checkViewIntents(): Boolean {
|
||||||
|
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
|
||||||
|
val timestamp = uri.pathSegments.last()
|
||||||
|
if (timestamp.areDigitsOnly()) {
|
||||||
|
openDayAt(timestamp.toLong())
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tryImportEventsFromFile(uri)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
private fun showViewDialog() {
|
private fun showViewDialog() {
|
||||||
val items = arrayListOf(
|
val items = arrayListOf(
|
||||||
RadioItem(DAILY_VIEW, getString(R.string.daily_view)),
|
RadioItem(DAILY_VIEW, getString(R.string.daily_view)),
|
||||||
|
Reference in New Issue
Block a user