-
Notifications
You must be signed in to change notification settings - Fork 72
Open url via navigation menu #3780
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
FikriMilano
wants to merge
1
commit into
main
Choose a base branch
from
3779-open-url-via-navigation-menu
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 all commits
Commits
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:width="24dp" | ||
| android:height="24dp" | ||
| android:viewportWidth="960" | ||
| android:viewportHeight="960" | ||
| android:tint="?attr/colorControlNormal"> | ||
| <path | ||
| android:fillColor="@android:color/white" | ||
| android:pathData="M480,600Q497,600 508.5,588.5Q520,577 520,560Q520,543 508.5,531.5Q497,520 480,520Q463,520 451.5,531.5Q440,543 440,560Q440,577 451.5,588.5Q463,600 480,600ZM440,440L520,440L520,200L440,200L440,440ZM80,880L80,160Q80,127 103.5,103.5Q127,80 160,80L800,80Q833,80 856.5,103.5Q880,127 880,160L880,640Q880,673 856.5,696.5Q833,720 800,720L240,720L80,880ZM206,640L800,640Q800,640 800,640Q800,640 800,640L800,160Q800,160 800,160Q800,160 800,160L160,160Q160,160 160,160Q160,160 160,160L160,685L206,640ZM160,640L160,640L160,160Q160,160 160,160Q160,160 160,160L160,160Q160,160 160,160Q160,160 160,160L160,640Q160,640 160,640Q160,640 160,640Z"/> | ||
| </vector> |
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,6 +26,7 @@ import android.widget.Toast | |||||||||||||||||||||||||||||||||||||
| import androidx.appcompat.app.AppCompatActivity | ||||||||||||||||||||||||||||||||||||||
| import androidx.compose.runtime.snapshots.SnapshotStateMap | ||||||||||||||||||||||||||||||||||||||
| import androidx.core.content.ContextCompat | ||||||||||||||||||||||||||||||||||||||
| import androidx.core.net.toUri | ||||||||||||||||||||||||||||||||||||||
| import androidx.core.os.bundleOf | ||||||||||||||||||||||||||||||||||||||
| import androidx.navigation.NavController | ||||||||||||||||||||||||||||||||||||||
| import androidx.navigation.NavOptions | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -245,6 +246,18 @@ fun ActionConfig.handleClickEvent( | |||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
| navController.navigate(MainNavigationScreen.AlertDialogFragment.route, args) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| ApplicationWorkflow.OPEN_URL -> { | ||||||||||||||||||||||||||||||||||||||
| val url = interpolatedParams.find { it.key == "url" }?.value | ||||||||||||||||||||||||||||||||||||||
| if (!url.isNullOrBlank()) { | ||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||
| val intent = Intent(Intent.ACTION_VIEW, url.toUri()) | ||||||||||||||||||||||||||||||||||||||
| intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||||||||||||||||||||||||||||||||||||||
| ContextCompat.startActivity(navController.context, intent, null) | ||||||||||||||||||||||||||||||||||||||
| } catch (e: Exception) { | ||||||||||||||||||||||||||||||||||||||
| context?.showToast("Unable to open url ${e.message}", Toast.LENGTH_SHORT) | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+252
to
+257
|
||||||||||||||||||||||||||||||||||||||
| try { | |
| val intent = Intent(Intent.ACTION_VIEW, url.toUri()) | |
| intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | |
| ContextCompat.startActivity(navController.context, intent, null) | |
| } catch (e: Exception) { | |
| context?.showToast("Unable to open url ${e.message}", Toast.LENGTH_SHORT) | |
| val uri = Uri.parse(url) | |
| val scheme = uri.scheme?.lowercase() | |
| if (scheme == "http" || scheme == "https") { | |
| try { | |
| val intent = Intent(Intent.ACTION_VIEW, uri) | |
| intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | |
| ContextCompat.startActivity(navController.context, intent, null) | |
| } catch (e: Exception) { | |
| context?.showToast("Unable to open url ${e.message}", Toast.LENGTH_SHORT) | |
| } | |
| } else { | |
| context?.showToast("Invalid or unsupported URL scheme", Toast.LENGTH_SHORT) |
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 error message exposes the raw exception message to users, which may contain technical details that are confusing. Consider using a more user-friendly message like 'Unable to open the URL. Please check the link and try again.'