Skip to content

Commit

Permalink
[WIP] Playing. DeepLink to be done
Browse files Browse the repository at this point in the history
  • Loading branch information
rfc2822 committed Aug 4, 2024
1 parent a3463e2 commit 09b10a7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
<activity android:name="net.openid.appauth.RedirectUriReceiverActivity"
tools:node="remove" tools:selector="net.openid.appauth"/>

<activity android:name=".ui.intro.IntroActivity" />
<activity
android:name=".ui.MainActivity"
android:exported="true">
Expand All @@ -74,6 +73,7 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".ui.intro.IntroActivity" />

<activity
android:name=".ui.AboutActivity"
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/kotlin/at/bitfire/davdroid/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import android.content.Intent
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.rememberNavController
import at.bitfire.davdroid.ui.account.accountDestination
Expand All @@ -17,18 +19,24 @@ import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class MainActivity: AppCompatActivity() {

companion object {
const val START_DESTINATION = "startDestination"
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

// handle "Sync all" intent from launcher shortcut
val syncAccounts = intent.action == Intent.ACTION_SYNC

val startDestination = intent.getSerializableExtra(START_DESTINATION) ?: AccountsDestination

setContent {
// set up Navigation
val navController = rememberNavController()
NavHost(
navController = navController,
startDestination = AccountsDestination
startDestination = startDestination
) {
accountsDestination(
initialSyncAccounts = syncAccounts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
package at.bitfire.davdroid.ui.account

import android.accounts.Account
import android.content.Intent
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import at.bitfire.davdroid.ui.MainActivity
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Deprecated("Use Compose Navigation instead")
class AccountActivity : AppCompatActivity() {

companion object {
Expand All @@ -23,9 +25,11 @@ class AccountActivity : AppCompatActivity() {
val account = intent.getParcelableExtra(EXTRA_ACCOUNT) as? Account
?: throw IllegalArgumentException("AccountActivity requires EXTRA_ACCOUNT")

setContent {
// noop
}
// TODO remove this activity and use Compose Navigation
startActivity(Intent(this, MainActivity::class.java).apply {
data = accountDeepLink(account.name)
addFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP)
})
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,34 @@ import android.accounts.Account
import android.content.Intent
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.core.net.toUri
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navDeepLink
import androidx.navigation.toRoute
import at.bitfire.davdroid.BuildConfig
import at.bitfire.davdroid.R
import kotlinx.serialization.Serializable

@Serializable
private data class AccountDestination(
data class AccountDestination(
val accountName: String
)

fun accountDeepLink(accountName: String) = "${BuildConfig.APPLICATION_ID}://account/$accountName".toUri()

fun NavController.navigateToAccount(accountName: String) {
navigate(AccountDestination(accountName))
}

fun NavGraphBuilder.accountDestination() {
composable<AccountDestination> { backStackEntry ->
composable<AccountDestination>(
deepLinks = listOf(
navDeepLink { uriPattern = "${BuildConfig.APPLICATION_ID}://account/{accountName}" }
)
) { backStackEntry ->
val destination: AccountDestination = backStackEntry.toRoute()
val account = Account(destination.accountName, stringResource(R.string.account_type))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.TaskStackBuilder
import androidx.navigation.compose.rememberNavController
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand Down

0 comments on commit 09b10a7

Please sign in to comment.