fix some threading issues related to third party intent checking

This commit is contained in:
tibbi
2018-11-18 17:37:23 +01:00
parent f2ba190af4
commit ad4c1dbd99

View File

@@ -91,15 +91,13 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
refreshCalDAVCalendars(false) refreshCalDAVCalendars(false)
} }
if (!checkViewIntents()) {
return
}
if (!checkOpenIntents()) {
updateViewPager()
}
checkAppOnSDCard() checkAppOnSDCard()
checkIsViewIntent {
if (!checkIsOpenIntent()) {
updateViewPager()
}
}
} }
override fun onResume() { override fun onResume() {
@@ -205,8 +203,8 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
override fun onNewIntent(intent: Intent?) { override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent) super.onNewIntent(intent)
setIntent(intent) setIntent(intent)
checkOpenIntents() checkIsOpenIntent()
checkViewIntents() checkIsViewIntent()
} }
private fun storeStateVariables() { private fun storeStateVariables() {
@@ -261,7 +259,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
mSearchMenuItem?.collapseActionView() mSearchMenuItem?.collapseActionView()
} }
private fun checkOpenIntents(): Boolean { private fun checkIsOpenIntent(): Boolean {
val dayCodeToOpen = intent.getStringExtra(DAY_CODE) ?: "" val dayCodeToOpen = intent.getStringExtra(DAY_CODE) ?: ""
val viewToOpen = intent.getIntExtra(VIEW_TO_OPEN, DAILY_VIEW) val viewToOpen = intent.getIntExtra(VIEW_TO_OPEN, DAILY_VIEW)
intent.removeExtra(VIEW_TO_OPEN) intent.removeExtra(VIEW_TO_OPEN)
@@ -290,35 +288,38 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
return false return false
} }
private fun checkViewIntents(): Boolean { private fun checkIsViewIntent(callback: (() -> Unit)? = null) {
if (intent?.action == Intent.ACTION_VIEW && intent.data != null) { if (intent?.action == Intent.ACTION_VIEW && intent.data != null) {
val uri = intent.data val uri = intent.data
if (uri.authority == "com.android.calendar") { if (uri.authority == "com.android.calendar") {
if (uri.path.startsWith("/events")) { if (uri.path.startsWith("/events")) {
// intents like content://com.android.calendar/events/1756 Thread {
val eventId = uri.lastPathSegment // intents like content://com.android.calendar/events/1756
val id = eventsDB.getEventIdWithLastImportId("%-$eventId") val eventId = uri.lastPathSegment
if (id != null) { val id = eventsDB.getEventIdWithLastImportId("%-$eventId")
Intent(this, EventActivity::class.java).apply { if (id != null) {
putExtra(EVENT_ID, id) Intent(this, EventActivity::class.java).apply {
startActivity(this) putExtra(EVENT_ID, id)
startActivity(this)
}
return@Thread
} else {
toast(R.string.unknown_error_occurred)
} }
} else { }.start()
toast(R.string.unknown_error_occurred)
}
} else if (intent?.extras?.getBoolean("DETAIL_VIEW", false) == true) { } else if (intent?.extras?.getBoolean("DETAIL_VIEW", false) == true) {
// clicking date on a third party widget: content://com.android.calendar/time/1507309245683 // clicking date on a third party widget: content://com.android.calendar/time/1507309245683
val timestamp = uri.pathSegments.last() val timestamp = uri.pathSegments.last()
if (timestamp.areDigitsOnly()) { if (timestamp.areDigitsOnly()) {
openDayAt(timestamp.toLong()) openDayAt(timestamp.toLong())
return false return
} }
} }
} else { } else {
tryImportEventsFromFile(uri) tryImportEventsFromFile(uri)
} }
} }
return true callback?.invoke()
} }
private fun showViewDialog() { private fun showViewDialog() {