Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handling deeplinks not working everytime #3412

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions app/src/main/kotlin/com/wire/android/ui/WireActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -561,6 +571,15 @@ 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) {
Expand Down Expand Up @@ -598,6 +617,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"
}
}
Expand Down
Loading