Skip to content

Commit 94fb604

Browse files
graycreateclaude
andcommitted
refactor: address Copilot review feedback for VShare analytics
Address code review feedback from Copilot: 1. Use Uri.Builder for safer URL construction - Replace manual string concatenation with Uri.Builder - Properly encode query parameters - Handle existing parameters correctly 2. Replace PackageManager with BuildConfig.VERSION_NAME - Use BuildConfig.VERSION_NAME directly (no try/catch needed) - Avoid deprecated PackageManager.getPackageInfo() call - Simpler and more reliable implementation Changes: - VshareWebActivity.java:106-114: Use Uri.Builder for URL construction - VshareWebActivity.java:286-288: Simplify getAppVersion() with BuildConfig - Add BuildConfig import Note: Test coverage suggestions noted but deferred for future enhancement. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent e3d37d1 commit 94fb604

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

app/src/main/java/me/ghui/v2er/module/vshare/VshareWebActivity.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import androidx.annotation.Nullable;
2323

2424
import butterknife.BindView;
25+
import me.ghui.v2er.BuildConfig;
2526
import me.ghui.v2er.R;
2627
import me.ghui.v2er.module.base.BaseActivity;
2728
import me.ghui.v2er.module.base.BaseContract;
@@ -104,9 +105,13 @@ protected void init() {
104105
setupWebView();
105106

106107
// Compute URL with theme and source parameters for analytics tracking
107-
String url = VSHARE_BASE_URL;
108108
String themeParam = DarkModelUtils.isDarkMode() ? "dark" : "light";
109-
url += "?theme=" + themeParam + "&source=v2er-android";
109+
String url = Uri.parse(VSHARE_BASE_URL)
110+
.buildUpon()
111+
.appendQueryParameter("theme", themeParam)
112+
.appendQueryParameter("source", "v2er-android")
113+
.build()
114+
.toString();
110115
mWebView.loadUrl(url);
111116
}
112117

@@ -280,12 +285,7 @@ private int getStatusBarHeight() {
280285
* Get app version name for User-Agent tracking
281286
*/
282287
private String getAppVersion() {
283-
try {
284-
return getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
285-
} catch (Exception e) {
286-
Log.e(TAG, "Failed to get app version", e);
287-
return "unknown";
288-
}
288+
return BuildConfig.VERSION_NAME != null ? BuildConfig.VERSION_NAME : "unknown";
289289
}
290290

291291
/**

0 commit comments

Comments
 (0)