-
Notifications
You must be signed in to change notification settings - Fork 72
[WIP] Add deeplink recipe for single module #97
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
Open
claraf3
wants to merge
4
commits into
android:main
Choose a base branch
from
claraf3:basic-deeplink-new-design
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...rc/main/java/com/example/nav3recipes/deeplink/parseintent/singleModule/CommonResources.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.example.nav3recipes.deeplink.parseintent.singleModule | ||
|
|
||
| /** | ||
| * String resources | ||
| */ | ||
| internal const val STRING_LITERAL_FILTER = "filter" | ||
| internal const val STRING_LITERAL_HOME = "home" | ||
| internal const val STRING_LITERAL_USERS = "users" | ||
| internal const val STRING_LITERAL_SEARCH = "search" | ||
| internal const val STRING_LITERAL_INCLUDE = "include" | ||
| internal const val PATH_BASE = "https://www.nav3recipes.com" | ||
| internal const val PATH_INCLUDE = "$STRING_LITERAL_USERS/$STRING_LITERAL_INCLUDE" | ||
| internal const val PATH_SEARCH = "$STRING_LITERAL_USERS/$STRING_LITERAL_SEARCH" | ||
| internal const val URL_HOME_EXACT = "$PATH_BASE/$STRING_LITERAL_HOME" | ||
|
|
||
| internal const val URL_USERS_WITH_FILTER = "$PATH_BASE/$PATH_INCLUDE/{$STRING_LITERAL_FILTER}" | ||
| internal val URL_SEARCH = "$PATH_BASE/$PATH_SEARCH" + | ||
| "?${SearchKey::ageMin.name}={${SearchKey::ageMin.name}}" + | ||
| "&${SearchKey::ageMax.name}={${SearchKey::ageMax.name}}" + | ||
| "&${SearchKey::firstName.name}={${SearchKey::firstName.name}}" + | ||
| "&${SearchKey::location.name}={${SearchKey::location.name}}" | ||
|
|
||
| /** | ||
| * User data | ||
| */ | ||
| internal const val FIRST_NAME_JOHN = "John" | ||
| internal const val FIRST_NAME_TOM = "Tom" | ||
| internal const val FIRST_NAME_MARY = "Mary" | ||
| internal const val FIRST_NAME_JULIE = "Julie" | ||
| internal const val LOCATION_CA = "CA" | ||
| internal const val LOCATION_BC = "BC" | ||
| internal const val LOCATION_BR = "BR" | ||
| internal const val LOCATION_US = "US" | ||
| internal const val EMPTY = "" | ||
| internal val LIST_USERS = listOf( | ||
| User(FIRST_NAME_JOHN, 15, LOCATION_CA), | ||
| User(FIRST_NAME_JOHN, 22, LOCATION_BC), | ||
| User(FIRST_NAME_TOM, 25, LOCATION_CA), | ||
| User(FIRST_NAME_TOM, 68, LOCATION_BR), | ||
| User(FIRST_NAME_JULIE, 48, LOCATION_BR), | ||
| User(FIRST_NAME_JULIE, 33, LOCATION_US), | ||
| User(FIRST_NAME_JULIE, 9, LOCATION_BR), | ||
| User(FIRST_NAME_MARY, 64, LOCATION_US), | ||
| User(FIRST_NAME_MARY, 5, LOCATION_CA), | ||
| User(FIRST_NAME_MARY, 52, LOCATION_BC), | ||
| User(FIRST_NAME_TOM, 94, LOCATION_BR), | ||
| User(FIRST_NAME_JULIE, 46, LOCATION_CA), | ||
| User(FIRST_NAME_JULIE, 37, LOCATION_BC), | ||
| User(FIRST_NAME_JULIE, 73 ,LOCATION_US), | ||
| User(FIRST_NAME_MARY, 51, LOCATION_US), | ||
| User(FIRST_NAME_MARY, 63, LOCATION_BR), | ||
| ) |
192 changes: 192 additions & 0 deletions
192
app/src/main/java/com/example/nav3recipes/deeplink/parseintent/singleModule/CommonScreens.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| package com.example.nav3recipes.deeplink.parseintent.singleModule | ||
|
|
||
| import android.content.Context | ||
| import android.content.Intent | ||
| import androidx.compose.animation.animateContentSize | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.width | ||
| import androidx.compose.foundation.lazy.LazyColumn | ||
| import androidx.compose.material3.Button | ||
| import androidx.compose.material3.DropdownMenuItem | ||
| import androidx.compose.material3.ExperimentalMaterial3Api | ||
| import androidx.compose.material3.ExposedDropdownMenuAnchorType | ||
| import androidx.compose.material3.ExposedDropdownMenuBox | ||
| import androidx.compose.material3.ExposedDropdownMenuDefaults | ||
| import androidx.compose.material3.OutlinedTextField | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.material3.TextField | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.runtime.setValue | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.text.font.FontWeight | ||
| import androidx.compose.ui.text.style.TextAlign | ||
| import androidx.compose.ui.unit.TextUnit | ||
| import androidx.compose.ui.unit.dp | ||
| import androidx.compose.ui.unit.sp | ||
| import androidx.core.net.toUri | ||
|
|
||
| @Composable | ||
| internal fun EntryScreen(text: String, block: @Composable () -> Unit = { }) { | ||
claraf3 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { | ||
| Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(10.dp)) { | ||
| Text(text, fontWeight = FontWeight.Bold, fontSize = FONT_SIZE_TITLE) | ||
| block() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| internal fun FriendsList(users: List<User>) { | ||
| // display list of matching targets | ||
| if (users.isEmpty()) { | ||
| Text("List is Empty", fontWeight = FontWeight.Bold) | ||
| } else { | ||
| LazyColumn { | ||
| items(users.size) { idx -> | ||
| val user = users[idx] | ||
| TextContent("${user.firstName}(${user.age}), ${user.location}") | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Displays a text input menu, may include several text fields | ||
| */ | ||
| @Composable | ||
| internal fun MenuTextInput( | ||
| menuLabels: List<String>, | ||
| onValueChange: (String, String) -> Unit = { _, _ ->}, | ||
| ) { | ||
| Column { | ||
| menuLabels.forEach { label -> | ||
| var inputText by remember { mutableStateOf("") } | ||
|
|
||
| OutlinedTextField( | ||
| value = inputText, | ||
| onValueChange = { | ||
| inputText = it | ||
| onValueChange(label, it) | ||
| }, | ||
| placeholder = { Text("enter integer") }, | ||
| label = { Text(label) }, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Displays a drop down menu, may include multiple drop downs | ||
| */ | ||
| @Composable | ||
| internal fun MenuDropDown( | ||
| menuOptions: Map<String, List<String>>, | ||
| onSelect: (label: String, selection: String) -> Unit = { _, _ ->}, | ||
| ) { | ||
| Column( | ||
| modifier = Modifier.animateContentSize(), | ||
| horizontalAlignment = Alignment.CenterHorizontally | ||
| ) { | ||
| menuOptions.forEach { entry -> | ||
| val key = entry.key | ||
| ArgumentDropDownMenu(label = key, menuItemOptions = entry.value) { label, selection -> | ||
| onSelect(key, selection) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Display list of selections for one drop down | ||
| @OptIn(ExperimentalMaterial3Api::class) | ||
| @Composable | ||
| private fun ArgumentDropDownMenu( | ||
| label: String, | ||
| menuItemOptions: List<String>, | ||
| onSelect: (label: String, selection: String) -> Unit, | ||
| ) { | ||
| val initValue = menuItemOptions.firstOrNull() ?: "" | ||
| var expanded by remember { mutableStateOf(false) } | ||
| var currSelected by remember { mutableStateOf(initValue) } | ||
| Box( | ||
| modifier = Modifier | ||
| .padding(16.dp) | ||
| ) { | ||
| ExposedDropdownMenuBox( | ||
| expanded = expanded, | ||
| onExpandedChange = { expanded = !expanded } | ||
| ) { | ||
| TextField( | ||
| readOnly = true, | ||
| value = currSelected, | ||
| onValueChange = { }, | ||
| label = { Text(label) }, | ||
| trailingIcon = { | ||
| ExposedDropdownMenuDefaults.TrailingIcon( | ||
| expanded = expanded | ||
| ) | ||
| }, | ||
| modifier = Modifier.menuAnchor(ExposedDropdownMenuAnchorType.PrimaryNotEditable, true) | ||
| ) | ||
| ExposedDropdownMenu( | ||
| expanded = expanded, | ||
| onDismissRequest = { | ||
| expanded = false | ||
| } | ||
| ) { | ||
| menuItemOptions.forEach { text -> | ||
| DropdownMenuItem( | ||
| text = { Text(text) }, | ||
| onClick = { | ||
| expanded = false | ||
| currSelected = text | ||
| onSelect(label, text) | ||
| } | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| internal fun DeepLinkButton( | ||
| context: Context, | ||
| targetActivity: Class<*>, | ||
| deepLinkUrl: String, | ||
| ) { | ||
| Button( | ||
| onClick = { | ||
| val intent = Intent( | ||
| context, | ||
| targetActivity | ||
| ) | ||
| // start activity with the url | ||
| intent.data = deepLinkUrl.toUri() | ||
| context.startActivity(intent) | ||
| } | ||
| ) { | ||
| Text("Deeplink away!") | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| fun TextContent(text: String) { | ||
| Text( | ||
| text = text, | ||
| modifier = Modifier.width(300.dp), | ||
| textAlign = TextAlign.Center, | ||
| fontSize = FONT_SIZE_TEXT, | ||
| ) | ||
| } | ||
|
|
||
| internal val FONT_SIZE_TITLE: TextUnit = 20.sp | ||
| internal val FONT_SIZE_TEXT: TextUnit = 15.sp | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The package name could just be
com.example.nav3recipes.deeplinksand all the library code could be placed in a subpackage saycommonorlibrary. We could make it clear that to add deeplinks to your app you can just copy thelibrarypackage into your own app. WDYT?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is really important for each recipe to stand on its own - the simple example should include only simple code.
Trying to make just a single shared library means that to understand even what the simple recipe is doing you have to understand a library that handles way more than what is needed for that recipe.
I do think we should separate the recipe into the activity code (e.g., the example of how to use it) from the library code (e.g., what we expect developers to use in their own app if they want to 'adopt' that specific recipe).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated with
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can simplify
deeplinkutilto justutilsince it's a subpackage ofdeeplink.basic