-
Notifications
You must be signed in to change notification settings - Fork 47
feat: improve Vshare WebView with intent URL support and status bar padding #155
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
962b47b
feat: improve Vshare WebView with intent URL support and status bar p…
graycreate bbc3c04
fix: use explicit paddingTop for WebView status bar spacing
graycreate 2dae224
fix: properly handle status bar padding using WindowInsets
graycreate c222c94
refactor: make VshareWebActivity extend BaseActivity
graycreate 5907220
feat: hide toolbar in VshareWebActivity for fullscreen experience
graycreate a54021b
fix: add fitsSystemWindows to WebView to properly handle status bar
graycreate daec27e
fix: use layout_marginTop instead of WindowInsets for WebView spacing
graycreate e0a7d57
refactor: dynamically set WebView top margin based on status bar height
graycreate 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,21 @@ | ||
| package me.ghui.v2er.module.vshare; | ||
|
|
||
| import android.annotation.SuppressLint; | ||
| import android.content.ActivityNotFoundException; | ||
| import android.content.Context; | ||
| import android.content.Intent; | ||
| import android.graphics.Bitmap; | ||
| import android.net.Uri; | ||
| import android.os.Bundle; | ||
| import android.util.Log; | ||
| import android.view.View; | ||
| import android.webkit.WebChromeClient; | ||
| import android.webkit.WebResourceRequest; | ||
| import android.webkit.WebSettings; | ||
| import android.webkit.WebView; | ||
| import android.webkit.WebViewClient; | ||
| import android.widget.ProgressBar; | ||
| import android.widget.Toast; | ||
|
|
||
| import androidx.appcompat.app.AppCompatActivity; | ||
|
|
||
|
|
@@ -26,6 +30,7 @@ | |
| */ | ||
| public class VshareWebActivity extends AppCompatActivity { | ||
|
|
||
| private static final String TAG = "VshareWebActivity"; | ||
| private static final String VSHARE_BASE_URL = "https://v2er.app/vshare"; | ||
|
|
||
| @BindView(R.id.webview) | ||
|
|
@@ -114,8 +119,12 @@ private void setupWebView() { | |
| mWebView.setWebViewClient(new WebViewClient() { | ||
| @Override | ||
| public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { | ||
| // Let the WebView handle the navigation | ||
| return false; | ||
| return handleUrlLoading(request.getUrl().toString()); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean shouldOverrideUrlLoading(WebView view, String url) { | ||
| return handleUrlLoading(url); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -149,6 +158,88 @@ public void onProgressChanged(WebView view, int newProgress) { | |
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Handle URL loading for WebView | ||
| * Returns true if the URL was handled externally, false if WebView should load it | ||
| */ | ||
| private boolean handleUrlLoading(String url) { | ||
| if (url == null) { | ||
| return false; | ||
| } | ||
|
|
||
| Uri uri = Uri.parse(url); | ||
| String scheme = uri.getScheme(); | ||
|
|
||
| // Handle intent:// URLs (e.g., Google Play Store links) | ||
| if ("intent".equals(scheme)) { | ||
| try { | ||
| Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME); | ||
|
|
||
| // Check if there's an app that can handle this intent | ||
| if (getPackageManager().resolveActivity(intent, 0) != null) { | ||
| startActivity(intent); | ||
| return true; | ||
| } | ||
|
|
||
| // Fallback: Try to open the browser_fallback_url if available | ||
| String fallbackUrl = intent.getStringExtra("browser_fallback_url"); | ||
| if (fallbackUrl != null) { | ||
| mWebView.loadUrl(fallbackUrl); | ||
| return true; | ||
| } | ||
|
|
||
| // Last resort: Try to open in Google Play if it's a Play Store intent | ||
| String packageName = intent.getPackage(); | ||
| if (packageName != null) { | ||
| Intent marketIntent = new Intent(Intent.ACTION_VIEW, | ||
| Uri.parse("market://details?id=" + packageName)); | ||
| marketIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
| if (getPackageManager().resolveActivity(marketIntent, 0) != null) { | ||
|
||
| startActivity(marketIntent); | ||
| return true; | ||
| } | ||
| } | ||
| } catch (Exception e) { | ||
| Log.e(TAG, "Error handling intent URL: " + url, e); | ||
| Toast.makeText(this, "Unable to open app", Toast.LENGTH_SHORT).show(); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| // Handle market:// URLs (Google Play Store) | ||
| if ("market".equals(scheme)) { | ||
| try { | ||
| Intent intent = new Intent(Intent.ACTION_VIEW, uri); | ||
| intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
| startActivity(intent); | ||
| return true; | ||
| } catch (ActivityNotFoundException e) { | ||
| Log.e(TAG, "Google Play Store not found", e); | ||
| // Fallback to web version | ||
| String webUrl = url.replace("market://", "https://play.google.com/store/apps/"); | ||
| mWebView.loadUrl(webUrl); | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| // Handle other app-specific schemes (e.g., mailto:, tel:, etc.) | ||
| if (!"http".equals(scheme) && !"https".equals(scheme)) { | ||
| try { | ||
| Intent intent = new Intent(Intent.ACTION_VIEW, uri); | ||
| intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
| startActivity(intent); | ||
| return true; | ||
| } catch (ActivityNotFoundException e) { | ||
| Log.e(TAG, "No app found to handle scheme: " + scheme, e); | ||
| Toast.makeText(this, "No app found to open this link", Toast.LENGTH_SHORT).show(); | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| // Let WebView handle normal http/https URLs | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public void onBackPressed() { | ||
| // Handle back navigation in WebView | ||
|
|
||
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
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 resolveActivity() call with flags=0 is deprecated in API level 30+. Use PackageManager.ResolveInfo flags or PackageManager.MATCH_DEFAULT_ONLY for better compatibility.