Skip to content

Commit

Permalink
Merge branch 'develop' into start-call-activity-in-a-new-task
Browse files Browse the repository at this point in the history
  • Loading branch information
ohassine authored May 2, 2024
2 parents 6864053 + d099c02 commit 4c01401
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 24 deletions.
27 changes: 25 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 @@ -23,6 +23,7 @@ import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.WindowManager
import android.widget.Toast
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
Expand Down Expand Up @@ -51,6 +52,7 @@ import androidx.navigation.NavController
import androidx.navigation.NavHostController
import com.ramcosta.composedestinations.spec.Route
import com.wire.android.BuildConfig
import com.wire.android.R
import com.wire.android.appLogger
import com.wire.android.config.CustomUiConfigurationProvider
import com.wire.android.config.LocalCustomUiConfigurationProvider
Expand Down Expand Up @@ -507,8 +509,29 @@ class WireActivity : AppCompatActivity() {
viewModel.handleDeepLink(
intent = intent,
onResult = ::handleDeepLinkResult,
onOpenConversation = { navigate(NavigationCommand(ConversationScreenDestination(it), BackStackMode.CLEAR_TILL_START)) },
onIsSharingIntent = { navigate(NavigationCommand(ImportMediaScreenDestination, BackStackMode.UPDATE_EXISTED)) }
onOpenConversation = {
navigate(
NavigationCommand(
ConversationScreenDestination(it),
BackStackMode.CLEAR_TILL_START
)
)
},
onIsSharingIntent = {
navigate(
NavigationCommand(
ImportMediaScreenDestination,
BackStackMode.UPDATE_EXISTED
)
)
},
onCannotLoginDuringACall = {
Toast.makeText(
this,
resources.getString(R.string.cant_switch_account_in_call),
Toast.LENGTH_SHORT
).show()
}
)
intent.putExtra(HANDLED_DEEPLINK_FLAG, true)
}
Expand Down
23 changes: 20 additions & 3 deletions app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import com.wire.kalium.logic.data.logout.LogoutReason
import com.wire.kalium.logic.data.sync.SyncState
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.feature.appVersioning.ObserveIfAppUpdateRequiredUseCase
import com.wire.kalium.logic.feature.call.usecase.ObserveEstablishedCallsUseCase
import com.wire.kalium.logic.feature.client.ClearNewClientsForUserUseCase
import com.wire.kalium.logic.feature.client.NewClientResult
import com.wire.kalium.logic.feature.client.ObserveNewClientsUseCase
Expand Down Expand Up @@ -117,6 +118,7 @@ class WireActivityViewModel @Inject constructor(
private val globalDataStore: GlobalDataStore,
private val observeIfE2EIRequiredDuringLoginUseCaseProviderFactory: ObserveIfE2EIRequiredDuringLoginUseCaseProvider.Factory,
private val workManager: WorkManager,
private val observeEstablishedCalls: ObserveEstablishedCallsUseCase
) : ViewModel() {

var globalAppState: GlobalAppState by mutableStateOf(GlobalAppState())
Expand Down Expand Up @@ -255,12 +257,15 @@ class WireActivityViewModel @Inject constructor(
return intent?.action == Intent.ACTION_SEND || intent?.action == Intent.ACTION_SEND_MULTIPLE
}

private suspend fun canLoginThroughDeepLinks() = observeEstablishedCalls().first().isEmpty()

@Suppress("ComplexMethod")
fun handleDeepLink(
intent: Intent?,
onIsSharingIntent: () -> Unit,
onOpenConversation: (ConversationId) -> Unit,
onResult: (DeepLinkResult) -> Unit
onResult: (DeepLinkResult) -> Unit,
onCannotLoginDuringACall: () -> Unit
) {
if (shouldMigrate()) {
// means User is Logged in, but didn't finish the migration yet.
Expand All @@ -270,9 +275,21 @@ class WireActivityViewModel @Inject constructor(
viewModelScope.launch {
val result = intent?.data?.let { deepLinkProcessor(it) }
when {
result is DeepLinkResult.SSOLogin -> onResult(result)
result is DeepLinkResult.SSOLogin -> {
if (canLoginThroughDeepLinks()) {
onResult(result)
} else {
onCannotLoginDuringACall()
}
}
result is DeepLinkResult.MigrationLogin -> onResult(result)
result is DeepLinkResult.CustomServerConfig -> onCustomServerConfig(result)
result is DeepLinkResult.CustomServerConfig -> {
if (canLoginThroughDeepLinks()) {
onCustomServerConfig(result)
} else {
onCannotLoginDuringACall()
}
}
isSharingIntent(intent) -> onIsSharingIntent()
shouldLogIn() -> {
// to handle the deepLinks above user needs to be Logged in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import javax.inject.Inject
import javax.inject.Singleton

sealed class DeepLinkResult {
object Unknown : DeepLinkResult()
data object Unknown : DeepLinkResult()
data class CustomServerConfig(val url: String) : DeepLinkResult()

@Serializable
Expand Down
Loading

0 comments on commit 4c01401

Please sign in to comment.