Skip to content

Commit 4486d0e

Browse files
Merge pull request #16 from saasquatch/dev
Use loadDataWithBaseURL for WebVIew
2 parents 4335718 + b2172f9 commit 4486d0e

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
## [Unreleased]
44

5+
## [0.1.1] - 2025-06-12
6+
7+
### Changed
8+
9+
- Added base URL for WebView.
10+
- Internal dependency version bumps.
11+
512
## [0.1.0] - 2024-11-22
613

714
### Changed
@@ -67,7 +74,9 @@
6774

6875
## [0.0.1] - 2021-02-17
6976

70-
[Unreleased]: https://github.com/saasquatch/squatch-android/compare/0.1.0...HEAD
77+
[Unreleased]: https://github.com/saasquatch/squatch-android/compare/0.1.1...HEAD
78+
79+
[0.1.1]: https://github.com/saasquatch/squatch-android/compare/0.1.0...0.1.1
7180

7281
[0.1.0]: https://github.com/saasquatch/squatch-android/compare/0.0.9...0.1.0
7382

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Add the dependency:
2424

2525
```gradle
2626
dependencies {
27-
implementation 'com.github.saasquatch:squatch-android:0.1.0'
27+
implementation 'com.github.saasquatch:squatch-android:0.1.1'
2828
}
2929
```
3030

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ dependencies {
2727
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
2828
api 'com.github.saasquatch:saasquatch-java-sdk:0.2.0'
2929
api 'org.reactivestreams:reactive-streams:1.0.4'
30-
implementation 'io.reactivex.rxjava3:rxjava:3.1.9'
30+
implementation 'io.reactivex.rxjava3:rxjava:3.1.10'
3131
implementation 'io.reactivex.rxjava3:rxandroid:3.0.2'
3232
implementation 'com.google.code.findbugs:jsr305:3.0.2'
3333
}

app/src/main/java/com/saasquatch/android/SquatchAndroidImpl.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.saasquatch.android;
22

3-
import static java.nio.charset.StandardCharsets.UTF_8;
4-
53
import android.annotation.SuppressLint;
6-
import android.util.Base64;
74
import android.webkit.WebSettings;
85
import android.webkit.WebView;
96
import com.saasquatch.android.input.AndroidRenderWidgetOptions;
@@ -125,8 +122,8 @@ private void loadHtmlToWebView(@Nonnull AndroidRenderWidgetOptions androidRender
125122
webSettings.setJavaScriptEnabled(true);
126123
webSettings.setDomStorageEnabled(true);
127124
SquatchJavascriptInterface.applyToWebView(webView);
128-
final String htmlBase64 = Base64.encodeToString(htmlString.getBytes(UTF_8), Base64.DEFAULT);
129-
webView.loadData(htmlBase64, "text/html; charset=utf-8", "base64");
125+
webView.loadDataWithBaseURL(androidRenderWidgetOptions.getWebViewBaseUrl(), htmlString,
126+
"text/html; charset=utf-8", null, null);
130127
}
131128

132129
private void loadErrorHtmlToWebView(

app/src/main/java/com/saasquatch/android/input/AndroidRenderWidgetOptions.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,21 @@
77
public final class AndroidRenderWidgetOptions {
88

99
private final WebView webView;
10+
private final String webViewBaseUrl;
1011

11-
private AndroidRenderWidgetOptions(WebView webView) {
12+
private AndroidRenderWidgetOptions(WebView webView, String webViewBaseUrl) {
1213
this.webView = webView;
14+
this.webViewBaseUrl = webViewBaseUrl;
1315
}
1416

1517
public WebView getWebView() {
1618
return webView;
1719
}
1820

21+
public String getWebViewBaseUrl() {
22+
return webViewBaseUrl;
23+
}
24+
1925
public static Builder newBuilder() {
2026
return new Builder();
2127
}
@@ -27,6 +33,7 @@ public static AndroidRenderWidgetOptions ofWebView(@Nonnull WebView webView) {
2733
public static final class Builder {
2834

2935
private WebView webView;
36+
private String webViewBaseUrl = "https://fast.ssqt.io/";
3037

3138
private Builder() {}
3239

@@ -35,8 +42,14 @@ public Builder setWebView(@Nonnull WebView webView) {
3542
return this;
3643
}
3744

45+
public Builder setWebViewBaseUrl(String webViewBaseUrl) {
46+
this.webViewBaseUrl = webViewBaseUrl;
47+
return this;
48+
}
49+
3850
public AndroidRenderWidgetOptions build() {
39-
return new AndroidRenderWidgetOptions(Objects.requireNonNull(webView, "webView"));
51+
return new AndroidRenderWidgetOptions(Objects.requireNonNull(webView, "webView"),
52+
webViewBaseUrl);
4053
}
4154

4255
}

0 commit comments

Comments
 (0)