Skip to content

Commit

Permalink
fix: handling deeplinks not working everytime (#3412)
Browse files Browse the repository at this point in the history
  • Loading branch information
yamilmedina authored Sep 5, 2024
1 parent 7d0b263 commit 68e946f
Showing 1 changed file with 22 additions and 2 deletions.
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

0 comments on commit 68e946f

Please sign in to comment.