From b314acf30c6ef276cea27e2b48d1f702e556db3e Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 9 Dec 2018 20:57:02 +0100 Subject: [PATCH] fix #241, check all third party intents at onNewIntent too --- .../notes/pro/activities/MainActivity.kt | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt index 48dd90b9..915ba50e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt @@ -60,27 +60,7 @@ class MainActivity : SimpleActivity() { pager_title_strip.setTextSize(TypedValue.COMPLEX_UNIT_PX, getTextSize()) pager_title_strip.layoutParams.height = (pager_title_strip.height + resources.getDimension(R.dimen.activity_margin) * 2).toInt() checkWhatsNewDialog() - - intent.apply { - if (action == Intent.ACTION_SEND && type == MIME_TEXT_PLAIN) { - getStringExtra(Intent.EXTRA_TEXT)?.let { - handleTextIntent(it) - intent.removeExtra(Intent.EXTRA_TEXT) - } - } - - if (action == Intent.ACTION_VIEW) { - val realPath = intent.getStringExtra(REAL_FILE_PATH) - if (realPath != null) { - val file = File(realPath) - handleUri(Uri.fromFile(file)) - } else { - handleUri(data) - } - intent.removeCategory(Intent.CATEGORY_DEFAULT) - intent.action = null - } - } + checkIntents(intent) storeStateVariables() if (config.showNotePicker && savedInstanceState == null) { @@ -207,6 +187,30 @@ class MainActivity : SimpleActivity() { super.onNewIntent(intent) val wantedNoteId = intent.getLongExtra(OPEN_NOTE_ID, -1L) view_pager.currentItem = getWantedNoteIndex(wantedNoteId) + checkIntents(intent) + } + + private fun checkIntents(intent: Intent) { + intent.apply { + if (action == Intent.ACTION_SEND && type == MIME_TEXT_PLAIN) { + getStringExtra(Intent.EXTRA_TEXT)?.let { + handleTextIntent(it) + intent.removeExtra(Intent.EXTRA_TEXT) + } + } + + if (action == Intent.ACTION_VIEW) { + val realPath = intent.getStringExtra(REAL_FILE_PATH) + if (realPath != null) { + val file = File(realPath) + handleUri(Uri.fromFile(file)) + } else { + handleUri(data) + } + intent.removeCategory(Intent.CATEGORY_DEFAULT) + intent.action = null + } + } } private fun storeStateVariables() {