1- package com.example.nav3recipes.deeplink.parseintent.singleModule
1+ package com.example.nav3recipes.deeplink.basic
22
33import android.os.Bundle
44import androidx.activity.ComponentActivity
@@ -9,9 +9,47 @@ import androidx.compose.runtime.mutableStateMapOf
99import androidx.compose.runtime.mutableStateOf
1010import androidx.compose.runtime.remember
1111import androidx.compose.runtime.setValue
12+ import com.example.nav3recipes.deeplink.basic.ui.DeepLinkButton
13+ import com.example.nav3recipes.deeplink.basic.ui.EMPTY
14+ import com.example.nav3recipes.deeplink.basic.ui.EntryScreen
15+ import com.example.nav3recipes.deeplink.basic.ui.FIRST_NAME_JOHN
16+ import com.example.nav3recipes.deeplink.basic.ui.FIRST_NAME_JULIE
17+ import com.example.nav3recipes.deeplink.basic.ui.FIRST_NAME_MARY
18+ import com.example.nav3recipes.deeplink.basic.ui.FIRST_NAME_TOM
19+ import com.example.nav3recipes.deeplink.basic.ui.LOCATION_BC
20+ import com.example.nav3recipes.deeplink.basic.ui.LOCATION_BR
21+ import com.example.nav3recipes.deeplink.basic.ui.LOCATION_CA
22+ import com.example.nav3recipes.deeplink.basic.ui.LOCATION_US
23+ import com.example.nav3recipes.deeplink.basic.ui.MenuDropDown
24+ import com.example.nav3recipes.deeplink.basic.ui.MenuTextInput
25+ import com.example.nav3recipes.deeplink.basic.ui.PATH_BASE
26+ import com.example.nav3recipes.deeplink.basic.ui.PATH_INCLUDE
27+ import com.example.nav3recipes.deeplink.basic.ui.PATH_SEARCH
28+ import com.example.nav3recipes.deeplink.basic.ui.STRING_LITERAL_HOME
29+ import com.example.nav3recipes.deeplink.basic.ui.SearchKey
30+ import com.example.nav3recipes.deeplink.basic.ui.TextContent
31+ import com.example.nav3recipes.deeplink.basic.ui.HomeKey
32+ import com.example.nav3recipes.deeplink.basic.ui.UsersKey
1233
1334/* *
14- * This activity allows the user to create a deep link and make a request with it
35+ * This activity allows the user to create a deep link and make a request with it.
36+ *
37+ * **HOW THIS RECIPE WORKS** it consists of two activities - [CreateDeepLinkActivity] to construct
38+ * and trigger the deeplink request, and the [MainActivity] to show how an app can handle
39+ * that request.
40+ *
41+ * **DEMONSTRATED FORMS OF DEEPLINK** The [MainActivity] has a several backStack keys to
42+ * demonstrate different types of supported deeplinks:
43+ * 1. [HomeKey] - deeplink with an exact url (no deeplink arguments)
44+ * 2. [UsersKey] - deeplink with path arguments
45+ * 3. [SearchKey] - deeplink with query arguments
46+ * See [MainActivity.deepLinkPatterns] for the actual url pattern of each.
47+ *
48+ * **RECIPE STRUCTURE** This recipe consists of three main packages:
49+ * 1. basic.deeplink - Contains the two activities
50+ * 2. basic.deeplink.ui - Contains the activity UI code, i.e. Screens, global string variables etc
51+ * 3. basic.deeplink.deeplinkutil - Contains the classes and helper methods to parse and match
52+ * the deeplinks
1553 *
1654 * See [MainActivity] for how the requested deeplink is handled.
1755 */
@@ -24,7 +62,7 @@ class CreateDeepLinkActivity : ComponentActivity() {
2462 * UI for deeplink sandbox
2563 */
2664 EntryScreen (" Sandbox - Build Your Deeplink" ) {
27- TextContent (" Base url:\n $PATH_BASE /" )
65+ TextContent (" Base url:\n ${ PATH_BASE } /" )
2866 var showFilterOptions by remember { mutableStateOf(false ) }
2967 val selectedPath = remember { mutableStateOf(MENU_OPTIONS_PATH [KEY_PATH ]?.first()) }
3068
@@ -42,10 +80,12 @@ class CreateDeepLinkActivity : ComponentActivity() {
4280 showQueryOptions = true
4381 showFilterOptions = false
4482 }
83+
4584 PATH_INCLUDE -> {
4685 showQueryOptions = false
4786 showFilterOptions = true
4887 }
88+
4989 else -> {
5090 showQueryOptions = false
5191 showFilterOptions = false
@@ -64,7 +104,7 @@ class CreateDeepLinkActivity : ComponentActivity() {
64104 if (showFilterOptions) {
65105 MenuDropDown (
66106 menuOptions = MENU_OPTIONS_FILTER ,
67- ) { _, selected ->
107+ ) { _, selected ->
68108 selectedFilter = selected
69109 }
70110 }
@@ -104,9 +144,10 @@ class CreateDeepLinkActivity : ComponentActivity() {
104144 }
105145 }
106146 }
147+
107148 else -> " "
108149 }
109- val finalUrl = " $PATH_BASE /${selectedPath.value}$arguments "
150+ val finalUrl = " ${ PATH_BASE } /${selectedPath.value}$arguments "
110151 TextContent (" Final url:\n $finalUrl " )
111152 // deeplink to target
112153 DeepLinkButton (
@@ -133,7 +174,13 @@ private val MENU_OPTIONS_FILTER = mapOf(
133174)
134175
135176private val MENU_OPTIONS_SEARCH = mapOf (
136- SearchKey ::firstName.name to listOf (EMPTY , FIRST_NAME_JOHN , FIRST_NAME_TOM , FIRST_NAME_MARY , FIRST_NAME_JULIE ),
177+ SearchKey ::firstName.name to listOf (
178+ EMPTY ,
179+ FIRST_NAME_JOHN ,
180+ FIRST_NAME_TOM ,
181+ FIRST_NAME_MARY ,
182+ FIRST_NAME_JULIE
183+ ),
137184 SearchKey ::location.name to listOf (EMPTY , LOCATION_CA , LOCATION_BC , LOCATION_BR , LOCATION_US )
138185)
139186
0 commit comments