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

feat: Deeplink even unauthenticated #291

Merged
merged 7 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
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
13 changes: 5 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,13 @@
<activity
android:name=".ui.LaunchActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/Theme.AppStarting">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".ui.OnboardingActivity" />

<activity
android:name=".ui.MainActivity"
android:exported="true"
android:launchMode="singleTop">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

Expand All @@ -89,6 +82,10 @@
</intent-filter>
</activity>

<activity android:name=".ui.OnboardingActivity" />

<activity android:name=".ui.MainActivity" />

<activity android:name=".ui.NewTransferActivity" />
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
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

@AndroidEntryPoint
Expand All @@ -38,16 +42,36 @@ class LaunchActivity : ComponentActivity() {

super.onCreate(savedInstanceState)

startTargetActivity()
finish()
lifecycleScope.launch {
runCatching {
startTargetActivity()
}.onFailure { exception ->
SentryLog.e(TAG, "Failure for startTargetActivity", exception)
}
finish()
}
}

private fun startTargetActivity() {
startActivity(Intent(this, chooseTargetActivity()))
private suspend fun startTargetActivity() {
if (hasValidTransferDeeplink()) {
if (!accountUtils.isUserConnected()) accountUtils.login()
createDeeplink()
} else {
startActivity(Intent(this@LaunchActivity, chooseTargetActivity()))
}
}

private fun chooseTargetActivity(): Class<out ComponentActivity> = when {
accountUtils.isUserConnected() -> MainActivity::class
else -> OnboardingActivity::class
}.java

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
}
}
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,10 +41,11 @@ class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
val isTransferDeeplink = hasValidTransferDeeplink()
setContent {
val appSettings by settingsViewModel.appSettingsFlow.collectAsStateWithLifecycle(null)
SwissTransferTheme(isDarkTheme = isDarkTheme(getTheme = { appSettings?.theme })) {
MainScreen()
MainScreen(isTransferDeeplink)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ import com.infomaniak.swisstransfer.ui.screen.main.transfers.TransfersScreenWrap
fun MainNavHost(
navController: NavHostController,
currentDestination: MainNavigation,
isTransferDeeplink: Boolean,
) {
NavHost(
navController = navController,
startDestination = MainNavigation.startDestination,
startDestination = if (isTransferDeeplink) ReceivedDestination() else MainNavigation.startDestination,
enterTransition = { if (currentDestination.enableTransition) fadeIn() else EnterTransition.None },
exitTransition = { if (currentDestination.enableTransition) fadeOut() else ExitTransition.None },
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows

@Composable
fun MainScreen() {
fun MainScreen(isTransferDeeplink: Boolean = false) {
val navController = rememberNavController()

val navBackStackEntry by navController.currentBackStackEntryAsState()
Expand All @@ -44,7 +44,7 @@ fun MainScreen() {
navController = navController,
currentDestination = currentDestination,
largeWindowTopAppBar = { BrandTopAppBar() },
content = { MainNavHost(navController, currentDestination) },
content = { MainNavHost(navController, currentDestination, isTransferDeeplink) },
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Infomaniak SwissTransfer - Android
* Copyright (C) 2024 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.infomaniak.swisstransfer.ui.utils

import androidx.activity.ComponentActivity


private val TRANSFER_DEEPLINK_REGEX = "https://.+/d/.+".toRegex()

fun ComponentActivity.hasValidTransferDeeplink(): Boolean {
val deeplink = intent?.data?.toString()
return deeplink?.matches(TRANSFER_DEEPLINK_REGEX) == true
}
Loading