Skip to content

Commit

Permalink
chore: Use Deeplink extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
sirambd committed Dec 27, 2024
1 parent 829ca5d commit e2c32e7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.lifecycleScope
import com.infomaniak.sentry.SentryLog
import com.infomaniak.swisstransfer.ui.utils.AccountUtils
import com.infomaniak.swisstransfer.ui.utils.hasValidTransferDeeplink
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import javax.inject.Inject
Expand Down Expand Up @@ -52,7 +53,7 @@ class LaunchActivity : ComponentActivity() {
}

private suspend fun startTargetActivity() {
if (isValidTransferDeeplink()) {
if (hasValidTransferDeeplink()) {
if (!accountUtils.isUserConnected()) accountUtils.login()
createDeeplink()
} else {
Expand All @@ -65,18 +66,12 @@ class LaunchActivity : ComponentActivity() {
else -> OnboardingActivity::class
}.java

private fun isValidTransferDeeplink(): Boolean {
val deeplink = intent?.data?.toString()
return deeplink?.matches(TRANSFER_DEEPLINK_REGEX) == true
}

private fun createDeeplink() {
val deepLinkIntent = Intent(Intent.ACTION_VIEW, intent.data, /*context*/this, MainActivity::class.java)
startActivity(deepLinkIntent)
}

companion object {
private val TAG = LaunchActivity::class.java.simpleName
private val TRANSFER_DEEPLINK_REGEX = "https://.+/d/.+".toRegex()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.infomaniak.multiplatform_swisstransfer.common.models.Theme
import com.infomaniak.swisstransfer.ui.screen.main.MainScreen
import com.infomaniak.swisstransfer.ui.screen.main.settings.SettingsViewModel
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.hasValidTransferDeeplink
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand All @@ -40,11 +41,11 @@ class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
val isReceivedDeeplink = intent.data != null
val isTransferDeeplink = hasValidTransferDeeplink()
setContent {
val appSettings by settingsViewModel.appSettingsFlow.collectAsStateWithLifecycle(null)
SwissTransferTheme(isDarkTheme = isDarkTheme(getTheme = { appSettings?.theme })) {
MainScreen(isReceivedDeeplink)
MainScreen(isTransferDeeplink)
}
}
}
Expand Down

0 comments on commit e2c32e7

Please sign in to comment.