From 270af47f4e1226bcdb2d52e8ae47eae13fa6f1fb Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Mon, 2 Sep 2024 18:15:31 +0200 Subject: [PATCH 1/2] fix: handling deeplinks not working everytime --- .../com/wire/android/ui/WireActivity.kt | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/wire/android/ui/WireActivity.kt b/app/src/main/kotlin/com/wire/android/ui/WireActivity.kt index 8da1c7d7227..35b8d44e594 100644 --- a/app/src/main/kotlin/com/wire/android/ui/WireActivity.kt +++ b/app/src/main/kotlin/com/wire/android/ui/WireActivity.kt @@ -21,6 +21,7 @@ package com.wire.android.ui import android.app.Activity import android.content.Intent import android.net.Uri +import android.os.Build import android.os.Bundle import android.view.WindowManager import android.widget.Toast @@ -65,8 +66,8 @@ import com.wire.android.navigation.NavigationGraph import com.wire.android.navigation.navigateToItem import com.wire.android.navigation.rememberNavigator import com.wire.android.ui.calling.getIncomingCallIntent -import com.wire.android.ui.calling.ongoing.getOngoingCallIntent import com.wire.android.ui.calling.getOutgoingCallIntent +import com.wire.android.ui.calling.ongoing.getOngoingCallIntent import com.wire.android.ui.common.snackbar.LocalSnackbarHostState import com.wire.android.ui.common.topappbar.CommonTopAppBar import com.wire.android.ui.common.topappbar.CommonTopAppBarViewModel @@ -514,17 +515,26 @@ class WireActivity : AppCompatActivity() { override fun onSaveInstanceState(outState: Bundle) { outState.putBoolean(HANDLED_DEEPLINK_FLAG, true) + outState.putParcelable(ORIGINAL_SAVED_INTENT_FLAG, intent) super.onSaveInstanceState(outState) } + override fun onRestoreInstanceState(savedInstanceState: Bundle) { + super.onRestoreInstanceState(savedInstanceState) + savedInstanceState.getOriginalIntent()?.let { + this.intent = it + } + } + @Suppress("ComplexCondition") private fun handleDeepLink( intent: Intent?, savedInstanceState: Bundle? = null ) { + val originalIntent = savedInstanceState.getOriginalIntent() if (intent == null || intent.flags and Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY != 0 - || savedInstanceState?.getBoolean(HANDLED_DEEPLINK_FLAG, false) == true + || originalIntent == intent // This is the case when the activity is recreated and already handled || intent.getBooleanExtra(HANDLED_DEEPLINK_FLAG, false) ) { return @@ -561,6 +571,14 @@ class WireActivity : AppCompatActivity() { } } + private fun Bundle?.getOriginalIntent(): Intent? { + return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { + @Suppress("DEPRECATION")// API 33 + this?.getParcelable(ORIGINAL_SAVED_INTENT_FLAG) + } else + this?.getParcelable(ORIGINAL_SAVED_INTENT_FLAG, Intent::class.java) + } + private fun handleDeepLinkResult(result: DeepLinkResult) { val navigate: (NavigationCommand) -> Unit = { lifecycleScope.launch { navigationCommands.emit(it) } } when (result) { @@ -598,6 +616,7 @@ class WireActivity : AppCompatActivity() { companion object { private const val HANDLED_DEEPLINK_FLAG = "deeplink_handled_flag_key" + private const val ORIGINAL_SAVED_INTENT_FLAG = "original_saved_intent" private const val TAG = "WireActivity" } } From 87247a06bcb5ffdd3b07557339e4e3799cdf072b Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Mon, 2 Sep 2024 20:45:33 +0200 Subject: [PATCH 2/2] feat: fix detekt --- app/src/main/kotlin/com/wire/android/ui/WireActivity.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/wire/android/ui/WireActivity.kt b/app/src/main/kotlin/com/wire/android/ui/WireActivity.kt index 35b8d44e594..0fcf8944426 100644 --- a/app/src/main/kotlin/com/wire/android/ui/WireActivity.kt +++ b/app/src/main/kotlin/com/wire/android/ui/WireActivity.kt @@ -573,10 +573,11 @@ class WireActivity : AppCompatActivity() { private fun Bundle?.getOriginalIntent(): Intent? { return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { - @Suppress("DEPRECATION")// API 33 + @Suppress("DEPRECATION") // API 33 this?.getParcelable(ORIGINAL_SAVED_INTENT_FLAG) - } else + } else { this?.getParcelable(ORIGINAL_SAVED_INTENT_FLAG, Intent::class.java) + } } private fun handleDeepLinkResult(result: DeepLinkResult) {