From a88a2fdca12bcbdcc87b03330383adeba0686b8f Mon Sep 17 00:00:00 2001 From: davinci9196 Date: Thu, 12 Sep 2024 09:53:42 +0800 Subject: [PATCH] Open via browser --- .../src/main/AndroidManifest.xml | 2 +- .../ui/GoogleHelpRedirectActivity.kt | 44 ++++--------------- 2 files changed, 9 insertions(+), 37 deletions(-) diff --git a/play-services-core/src/main/AndroidManifest.xml b/play-services-core/src/main/AndroidManifest.xml index 8cf03d3ac..2fb58134c 100644 --- a/play-services-core/src/main/AndroidManifest.xml +++ b/play-services-core/src/main/AndroidManifest.xml @@ -777,7 +777,7 @@ diff --git a/play-services-core/src/main/kotlin/org/microg/gms/googlehelp/ui/GoogleHelpRedirectActivity.kt b/play-services-core/src/main/kotlin/org/microg/gms/googlehelp/ui/GoogleHelpRedirectActivity.kt index 1a0ee324a..e7e79d265 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/googlehelp/ui/GoogleHelpRedirectActivity.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/googlehelp/ui/GoogleHelpRedirectActivity.kt @@ -6,6 +6,7 @@ package org.microg.gms.googlehelp.ui import android.content.Intent +import android.net.Uri import android.os.Bundle import android.os.Parcel import android.os.Parcelable.Creator @@ -42,8 +43,6 @@ private const val HELP_URL = "https://www.google.com/tools/feedback/mobile/help- class GoogleHelpRedirectActivity : AppCompatActivity() { - private lateinit var webView: WebView - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) Log.d(TAG, "onCreate begin") @@ -59,43 +58,16 @@ class GoogleHelpRedirectActivity : AppCompatActivity() { if (googleHelp == null) { inProductHelp = getParcelableFromIntent(intent, PRODUCT_HELP_KEY, InProductHelp.CREATOR) } - Log.d(TAG, "onCreate: googleHelp: ${googleHelp ?: inProductHelp?.googleHelp}") - - val layout = RelativeLayout(this) - layout.addView(ProgressBar(this).apply { - layoutParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT).apply { - addRule(RelativeLayout.CENTER_HORIZONTAL) - addRule(RelativeLayout.CENTER_VERTICAL) - } - isIndeterminate = true - }) - webView = WebView(this).apply { - layoutParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT) - visibility = View.INVISIBLE - } - layout.addView(webView) - setContentView(layout) lifecycleScope.launchWhenCreated { - val account = googleHelp?.account ?: inProductHelp?.googleHelp?.account + Log.d(TAG, "onCreate: googleHelp: ${googleHelp ?: inProductHelp?.googleHelp}") val searchId = googleHelp?.appContext ?: inProductHelp?.googleHelp?.appContext - Log.d(TAG, "loadHelpUrl: searchId: $searchId") - val answerUrl = requestHelpLink(callingPackage, searchId).content?.info?.answerUrl - Log.d(TAG, "answerUrl: $answerUrl") - val url = googleHelp?.uri?.toString() ?: inProductHelp?.googleHelp?.uri?.toString() ?: answerUrl - Log.d(TAG, "loadUrl: $url") - if (answerUrl != null) { - WebViewHelper(this@GoogleHelpRedirectActivity, webView).openWebView(url, account?.name) - setResult(RESULT_OK) - } else finish() - } - } - - override fun onBackPressed() { - if (this::webView.isInitialized && webView.canGoBack()) { - webView.goBack() - } else { - super.onBackPressed() + val answerUrl = runCatching { requestHelpLink(callingPackage, searchId).content?.info?.answerUrl }.getOrNull() + Log.d(TAG, "requestHelpLink answerUrl: $answerUrl") + val url = answerUrl ?: googleHelp?.uri?.toString() ?: inProductHelp?.googleHelp?.uri?.toString() ?: return@launchWhenCreated finish() + Log.d(TAG, "Open $url for $callingPackage in Browser") + startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url))) + finish() } }