Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Oct 16, 2024
1 parent 04802ed commit ac11baf
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,14 +427,23 @@ public void openWebView(PluginCall call) {
);

try {
Options.ButtonNearDone buttonNearDone = Options.ButtonNearDone.generateFromPluginCall(call, getActivity().getAssets());
Options.ButtonNearDone buttonNearDone =
Options.ButtonNearDone.generateFromPluginCall(
call,
getActivity().getAssets()
);
options.setButtonNearDone(buttonNearDone);
} catch (IllegalArgumentException illegalArgumentException) {
call.reject(String.format("ButtonNearDone rejected: %s", illegalArgumentException.getMessage()));
call.reject(
String.format(
"ButtonNearDone rejected: %s",
illegalArgumentException.getMessage()
)
);
} catch (RuntimeException e) {
Log.e(
"WebViewDialog",
String.format("ButtonNearDone runtime error: %s", e)
"WebViewDialog",
String.format("ButtonNearDone runtime error: %s", e)
);
call.reject(String.format("ButtonNearDone RuntimeException: %s", e));
}
Expand Down
35 changes: 23 additions & 12 deletions android/src/main/java/ee/forgr/capacitor_inappbrowser/Options.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
package ee.forgr.capacitor_inappbrowser;

import android.content.res.AssetManager;

import androidx.annotation.Nullable;

import com.getcapacitor.JSObject;
import com.getcapacitor.PluginCall;

import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;

public class Options {

public static class ButtonNearDone {

public enum AllIconTypes {
ASSET
ASSET,
}

private AllIconTypes iconType;
private String icon;
private int height;
private int width;

private ButtonNearDone(AllIconTypes iconType, String icon, int height, int width) {
private ButtonNearDone(
AllIconTypes iconType,
String icon,
int height,
int width
) {
this.iconType = iconType;
this.icon = icon;
this.height = height;
this.width = width;
}

@Nullable
public static ButtonNearDone generateFromPluginCall(PluginCall call, AssetManager assetManager) throws IllegalArgumentException, RuntimeException {
public static ButtonNearDone generateFromPluginCall(
PluginCall call,
AssetManager assetManager
) throws IllegalArgumentException, RuntimeException {
JSObject buttonNearDone = call.getObject("buttonNearDone");
if (buttonNearDone == null) {
// Return null when "buttonNearDone" isn't configured, else throw an error
Expand All @@ -45,12 +51,16 @@ public static ButtonNearDone generateFromPluginCall(PluginCall call, AssetManage

String iconType = android.getString("iconType", "asset");
if (!Objects.equals(iconType, "asset")) {
throw new IllegalArgumentException("buttonNearDone.android.iconType is not equal to \"asset\"");
throw new IllegalArgumentException(
"buttonNearDone.android.iconType is not equal to \"asset\""
);
}

String icon = android.getString("icon");
if (icon == null) {
throw new IllegalArgumentException("buttonNearDone.android.icon is null");
throw new IllegalArgumentException(
"buttonNearDone.android.icon is null"
);
}

InputStream fileInputString = null;
Expand All @@ -60,7 +70,9 @@ public static ButtonNearDone generateFromPluginCall(PluginCall call, AssetManage
fileInputString = assetManager.open(icon);
// do nothing
} catch (IOException e) {
throw new IllegalArgumentException("buttonNearDone.android.icon cannot be found in the assetManager");
throw new IllegalArgumentException(
"buttonNearDone.android.icon cannot be found in the assetManager"
);
} finally {
// Close the input stream if it was opened
if (fileInputString != null) {
Expand All @@ -70,11 +82,10 @@ public static ButtonNearDone generateFromPluginCall(PluginCall call, AssetManage
throw new RuntimeException(e);
}
}
};

}
Integer width = android.getInteger("width", 48);
Integer height = android.getInteger("height", 48);

Integer height = android.getInteger("height", 48);
return new ButtonNearDone(AllIconTypes.ASSET, icon, height, width);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Picture;
import android.app.AlertDialog;
import android.view.ViewGroup.LayoutParams;
import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
Expand All @@ -13,14 +11,15 @@
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Picture;
import android.graphics.drawable.PictureDrawable;
import android.net.Uri;
import android.net.http.SslError;
import android.text.TextUtils;
import android.util.Log;
import com.caverock.androidsvg.SVG;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.HttpAuthHandler;
Expand All @@ -37,12 +36,10 @@
import android.widget.TextView;
import android.widget.Toast;
import android.widget.Toolbar;

import androidx.annotation.Nullable;

import com.caverock.androidsvg.SVG;
import com.caverock.androidsvg.SVGParseException;
import com.getcapacitor.JSObject;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
Expand Down Expand Up @@ -511,11 +508,15 @@ public void onClick(View view) {
if (TextUtils.equals(_options.getToolbarType(), "activity")) {
_toolbar.findViewById(R.id.forwardButton).setVisibility(View.GONE);
_toolbar.findViewById(R.id.backButton).setVisibility(View.GONE);
ImageButton buttonNearDoneView = _toolbar.findViewById(R.id.buttonNearDone);
ImageButton buttonNearDoneView = _toolbar.findViewById(
R.id.buttonNearDone
);
buttonNearDoneView.setVisibility(View.GONE);
//TODO: Add share button functionality
} else if (TextUtils.equals(_options.getToolbarType(), "navigation")) {
ImageButton buttonNearDoneView = _toolbar.findViewById(R.id.buttonNearDone);
ImageButton buttonNearDoneView = _toolbar.findViewById(
R.id.buttonNearDone
);
buttonNearDoneView.setVisibility(View.GONE);
//TODO: Remove share button when implemented
} else if (TextUtils.equals(_options.getToolbarType(), "blank")) {
Expand All @@ -531,18 +532,23 @@ public void onClick(View view) {
// Open the SVG file from assets
InputStream inputStream = null;
try {
ImageButton buttonNearDoneView = _toolbar.findViewById(R.id.buttonNearDone);
ImageButton buttonNearDoneView = _toolbar.findViewById(
R.id.buttonNearDone
);
buttonNearDoneView.setVisibility(View.VISIBLE);

inputStream = assetManager.open(buttonNearDone.getIcon());
inputStream = assetManager.open(buttonNearDone.getIcon());

SVG svg = SVG.getFromInputStream(inputStream);
Picture picture = svg.renderToPicture(buttonNearDone.getWidth(), buttonNearDone.getHeight());
Picture picture = svg.renderToPicture(
buttonNearDone.getWidth(),
buttonNearDone.getHeight()
);
PictureDrawable pictureDrawable = new PictureDrawable(picture);

buttonNearDoneView.setImageDrawable(pictureDrawable);
buttonNearDoneView.setOnClickListener(
view -> _options.getCallbacks().buttonNearDoneClicked()
buttonNearDoneView.setOnClickListener(view ->
_options.getCallbacks().buttonNearDoneClicked()
);
} catch (IOException | SVGParseException e) {
throw new RuntimeException(e);
Expand All @@ -556,7 +562,9 @@ public void onClick(View view) {
}
}
} else {
ImageButton buttonNearDoneView = _toolbar.findViewById(R.id.buttonNearDone);
ImageButton buttonNearDoneView = _toolbar.findViewById(
R.id.buttonNearDone
);
buttonNearDoneView.setVisibility(View.GONE);
}
}
Expand Down Expand Up @@ -731,13 +739,18 @@ public void run() {
);
}
}
} else if (_options.getPreShowScript() != null && !_options.getPreShowScript().isEmpty()) {
executorService.execute(new Runnable() {
@Override
public void run() {
injectPreShowScript();
} else if (
_options.getPreShowScript() != null &&
!_options.getPreShowScript().isEmpty()
) {
executorService.execute(
new Runnable() {
@Override
public void run() {
injectPreShowScript();
}
}
});
);
}

ImageButton backButton = _toolbar.findViewById(R.id.backButton);
Expand Down
15 changes: 7 additions & 8 deletions ios/Plugin/InAppBrowserPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ public class InAppBrowserPlugin: CAPPlugin {
call.reject("URL must not be empty")
return
}
var buttonNearDoneIcon: UIImage? = nil

var buttonNearDoneIcon: UIImage?
if let buttonNearDoneSettings = call.getObject("buttonNearDone") {
guard let iosSettingsRaw = buttonNearDoneSettings["ios"] else {
call.reject("IOS settings not found")
Expand All @@ -149,12 +149,12 @@ public class InAppBrowserPlugin: CAPPlugin {
return
}
let iosSettings = iosSettingsRaw as! JSObject

guard let iconType = iosSettings["iconType"] as? String else {
call.reject("buttonNearDone.iconType is empty")
return
}
if (iconType != "sf-symbol" && iconType != "asset") {
if iconType != "sf-symbol" && iconType != "asset" {
call.reject("IconType is neither 'sf-symbol' nor 'asset'")
return
}
Expand All @@ -163,8 +163,7 @@ public class InAppBrowserPlugin: CAPPlugin {
return
}


if (iconType == "sf-symbol") {
if iconType == "sf-symbol" {
buttonNearDoneIcon = UIImage(systemName: icon)
} else {
// UIImage(resource: ImageResource(name: "public/monkey.svg", bundle: Bundle.main))
Expand Down Expand Up @@ -212,9 +211,9 @@ public class InAppBrowserPlugin: CAPPlugin {
self.webViewController?.leftNavigationBarItemTypes = self.getToolbarItems(toolbarType: toolbarType)
self.webViewController?.toolbarItemTypes = []
self.webViewController?.doneBarButtonItemPosition = .right

self.webViewController?.buttonNearDoneIcon = buttonNearDoneIcon

if call.getBool("showArrow", false) {
self.webViewController?.stopBarButtonItemImage = UIImage(named: "Forward@3x", in: Bundle(for: InAppBrowserPlugin.self), compatibleWith: nil)
}
Expand Down
8 changes: 4 additions & 4 deletions ios/Plugin/WKWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
open var reloadBarButtonItemImage: UIImage?
open var stopBarButtonItemImage: UIImage?
open var activityBarButtonItemImage: UIImage?

open var buttonNearDoneIcon: UIImage?

fileprivate var webView: WKWebView?
Expand Down Expand Up @@ -429,7 +429,7 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
self.navigationItem.title = webView?.url?.host
}
case "URL":

self.capBrowserPlugin?.notifyListeners("urlChangeEvent", data: ["url": webView?.url?.absoluteString ?? ""])
self.injectJavaScriptInterface()
default:
Expand Down Expand Up @@ -605,7 +605,7 @@ fileprivate extension WKWebViewController {
}
return UIBarButtonItem()
}
if (rightBarButtons.count == 1 && buttonNearDoneIcon != nil && rightBarButtons[0] == doneBarButtonItem) {
if rightBarButtons.count == 1 && buttonNearDoneIcon != nil && rightBarButtons[0] == doneBarButtonItem {
rightBarButtons.append(UIBarButtonItem(image: buttonNearDoneIcon, style: .plain, target: self, action: #selector(buttonNearDoneDidClick)))
}
navigationItem.rightBarButtonItems = rightBarButtons
Expand Down Expand Up @@ -741,7 +741,7 @@ fileprivate extension WKWebViewController {
@objc func forwardDidClick(sender: AnyObject) {
webView?.goForward()
}

@objc func buttonNearDoneDidClick(sender: AnyObject) {
self.capBrowserPlugin?.notifyListeners("buttonNearDoneClick", data: [:])
}
Expand Down
16 changes: 8 additions & 8 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@ export interface OpenWebViewOptions {
*/
buttonNearDone?: {
ios: {
iconType: 'sf-symbol' | 'asset',
icon: String
},
iconType: "sf-symbol" | "asset";
icon: String;
};
android: {
iconType: 'asset',
icon: String,
width?: number
height?: number
}
iconType: "asset";
icon: String;
width?: number;
height?: number;
};
};
}

Expand Down

0 comments on commit ac11baf

Please sign in to comment.