mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-02-18 14:55:18 -05:00
Update android webview
This commit is contained in:
@@ -23,6 +23,13 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter android:autoVerify="true">
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="com.compassmeet" android:host="auth" />
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
<provider
|
||||
|
||||
@@ -2,20 +2,14 @@ package com.compass.app;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.webkit.JavascriptInterface;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import com.getcapacitor.BridgeActivity;
|
||||
import com.getcapacitor.BridgeWebViewClient;
|
||||
import com.getcapacitor.Plugin;
|
||||
import com.getcapacitor.PluginHandle;
|
||||
|
||||
import ee.forgr.capacitor.social.login.GoogleProvider;
|
||||
import ee.forgr.capacitor.social.login.ModifiedMainActivityForSocialLoginPlugin;
|
||||
import ee.forgr.capacitor.social.login.SocialLoginPlugin;
|
||||
|
||||
public class MainActivity extends BridgeActivity implements ModifiedMainActivityForSocialLoginPlugin {
|
||||
public class MainActivity extends BridgeActivity {
|
||||
public class NativeBridge {
|
||||
@JavascriptInterface
|
||||
public boolean isNativeApp() {
|
||||
@@ -23,18 +17,28 @@ public class MainActivity extends BridgeActivity implements ModifiedMainActivity
|
||||
}
|
||||
}
|
||||
|
||||
private static final String LOCAL_URL = "file:///android_asset/public/server/pages";
|
||||
private static final String REMOTE_URL = "https://www.compassmeet.com";
|
||||
// private static final String LOCAL_URL = "file:///android_asset/public/server/pages";
|
||||
// private static final String REMOTE_URL = "https://www.compassmeet.com";
|
||||
|
||||
// Optional helper for future use
|
||||
public void loadLocalContent() {
|
||||
Log.i("CompassApp", "Loading local assets...");
|
||||
this.bridge.getWebView().loadUrl(LOCAL_URL);
|
||||
}
|
||||
// public void loadLocalContent() {
|
||||
// Log.i("CompassApp", "Loading local assets...");
|
||||
// this.bridge.getWebView().loadUrl(LOCAL_URL);
|
||||
// }
|
||||
//
|
||||
// public void loadRemoteContent() {
|
||||
// Log.i("CompassApp", "Loading remote content...");
|
||||
// this.bridge.getWebView().loadUrl(REMOTE_URL);
|
||||
// }
|
||||
|
||||
public void loadRemoteContent() {
|
||||
Log.i("CompassApp", "Loading remote content...");
|
||||
this.bridge.getWebView().loadUrl(REMOTE_URL);
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
|
||||
String data = intent.getDataString();
|
||||
if (data != null && data.startsWith("com.compassmeet:/auth")) {
|
||||
bridge.triggerWindowJSEvent("oauthRedirect", data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,11 +51,10 @@ public class MainActivity extends BridgeActivity implements ModifiedMainActivity
|
||||
WebView.setWebContentsDebuggingEnabled(true);
|
||||
|
||||
// Set a recognizable User-Agent (always reliable)
|
||||
webView.getSettings().setUserAgentString(
|
||||
webView.getSettings().getUserAgentString() + " CompassAppWebView"
|
||||
);
|
||||
WebSettings settings = webView.getSettings();
|
||||
settings.setUserAgentString(settings.getUserAgentString() + " CompassAppWebView");
|
||||
|
||||
webView.getSettings().setJavaScriptEnabled(true);
|
||||
settings.setJavaScriptEnabled(true);
|
||||
webView.addJavascriptInterface(new NativeBridge(), "AndroidBridge");
|
||||
|
||||
// Allow remote URLs to still have access to Capacitor bridge
|
||||
@@ -70,31 +73,31 @@ public class MainActivity extends BridgeActivity implements ModifiedMainActivity
|
||||
// this.bridge.getWebView().loadUrl("https://www.compassmeet.com");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
Log.i("Google Activity Result", "onActivityResult called with requestCode: " + requestCode + data);
|
||||
|
||||
if (requestCode >= GoogleProvider.REQUEST_AUTHORIZE_GOOGLE_MIN && requestCode < GoogleProvider.REQUEST_AUTHORIZE_GOOGLE_MAX) {
|
||||
PluginHandle pluginHandle = getBridge().getPlugin("SocialLogin");
|
||||
if (pluginHandle == null) {
|
||||
Log.i("Google Activity Result", "SocialLogin login handle is null");
|
||||
return;
|
||||
}
|
||||
Plugin plugin = pluginHandle.getInstance();
|
||||
if (!(plugin instanceof SocialLoginPlugin)) {
|
||||
Log.i("Google Activity Result", "SocialLogin plugin instance is not SocialLoginPlugin");
|
||||
return;
|
||||
}
|
||||
Log.i("Google Activity Result", "Handling Google login intent");
|
||||
((SocialLoginPlugin) plugin).handleGoogleLoginIntent(requestCode, data);
|
||||
}
|
||||
}
|
||||
// @Override
|
||||
// public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
// super.onActivityResult(requestCode, resultCode, data);
|
||||
//
|
||||
// Log.i("Google Activity Result", "onActivityResult called with requestCode: " + requestCode + data);
|
||||
//
|
||||
// if (requestCode >= GoogleProvider.REQUEST_AUTHORIZE_GOOGLE_MIN && requestCode < GoogleProvider.REQUEST_AUTHORIZE_GOOGLE_MAX) {
|
||||
// PluginHandle pluginHandle = getBridge().getPlugin("SocialLogin");
|
||||
// if (pluginHandle == null) {
|
||||
// Log.i("Google Activity Result", "SocialLogin login handle is null");
|
||||
// return;
|
||||
// }
|
||||
// Plugin plugin = pluginHandle.getInstance();
|
||||
// if (!(plugin instanceof SocialLoginPlugin)) {
|
||||
// Log.i("Google Activity Result", "SocialLogin plugin instance is not SocialLoginPlugin");
|
||||
// return;
|
||||
// }
|
||||
// Log.i("Google Activity Result", "Handling Google login intent");
|
||||
// ((SocialLoginPlugin) plugin).handleGoogleLoginIntent(requestCode, data);
|
||||
// }
|
||||
// }
|
||||
|
||||
// This function will never be called, leave it empty
|
||||
@Override
|
||||
public void IHaveModifiedTheMainActivityForTheUseWithSocialLoginPlugin() {
|
||||
}
|
||||
// @Override
|
||||
// public void IHaveModifiedTheMainActivityForTheUseWithSocialLoginPlugin() {
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user