Skip to content

Commit

Permalink
style: format
Browse files Browse the repository at this point in the history
  • Loading branch information
robingenz committed Aug 29, 2024
1 parent ae0fab3 commit 7151db4
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ private void createMainFragment(ArrayList<Image> imageList, JSObject options) th
FrameLayout frameLayoutView = new FrameLayout(context);
frameLayoutView.setId(frameLayoutViewId);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT
);
// Apply the Layout Parameters to frameLayout
frameLayoutView.setLayoutParams(lp);
Expand All @@ -67,11 +67,11 @@ private void createMainFragment(ArrayList<Image> imageList, JSObject options) th
mainFragment.setOptions(options);

bridge
.getActivity()
.getSupportFragmentManager()
.beginTransaction()
.replace(frameLayoutViewId, mainFragment, "mainfragment")
.commit();
.getActivity()
.getSupportFragmentManager()
.beginTransaction()
.replace(frameLayoutViewId, mainFragment, "mainfragment")
.commit();
} catch (Exception e) {
throw new Exception(e.getMessage());
}
Expand All @@ -83,8 +83,8 @@ private void createImageFragment(ArrayList<Image> imageList, Integer startFrom,
FrameLayout frameLayoutView = new FrameLayout(context);
frameLayoutView.setId(frameLayoutViewId);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT
);
// Apply the Layout Parameters to frameLayout
frameLayoutView.setLayoutParams(lp);
Expand All @@ -96,11 +96,11 @@ private void createImageFragment(ArrayList<Image> imageList, Integer startFrom,
imageFragment.setStartFrom(startFrom);

bridge
.getActivity()
.getSupportFragmentManager()
.beginTransaction()
.replace(frameLayoutViewId, imageFragment, "imagefragment")
.commit();
.getActivity()
.getSupportFragmentManager()
.beginTransaction()
.replace(frameLayoutViewId, imageFragment, "imagefragment")
.commit();
} catch (Exception e) {
throw new Exception(e.getMessage());
}
Expand All @@ -112,8 +112,8 @@ private void createSliderFragment(ArrayList<Image> imageList, Integer startFrom,
FrameLayout frameLayoutView = new FrameLayout(context);
frameLayoutView.setId(frameLayoutViewId);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT
);
// Apply the Layout Parameters to frameLayout
frameLayoutView.setLayoutParams(lp);
Expand All @@ -127,11 +127,11 @@ private void createSliderFragment(ArrayList<Image> imageList, Integer startFrom,
galleryFragment.setStartFrom(startFrom);

bridge
.getActivity()
.getSupportFragmentManager()
.beginTransaction()
.replace(frameLayoutViewId, galleryFragment, "gallery")
.commit();
.getActivity()
.getSupportFragmentManager()
.beginTransaction()
.replace(frameLayoutViewId, galleryFragment, "gallery")
.commit();
} catch (Exception e) {
throw new Exception(e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@
import org.json.JSONObject;

@CapacitorPlugin(
name = "PhotoViewer",
permissions = {
@Permission(alias = PhotoViewerPlugin.MEDIAIMAGES,
strings = { Manifest.permission.READ_MEDIA_IMAGES }),

@Permission(alias = PhotoViewerPlugin.READ_EXTERNAL_STORAGE,
strings = { Manifest.permission.READ_EXTERNAL_STORAGE })
}
name = "PhotoViewer",
permissions = {
@Permission(alias = PhotoViewerPlugin.MEDIAIMAGES, strings = { Manifest.permission.READ_MEDIA_IMAGES }),
@Permission(alias = PhotoViewerPlugin.READ_EXTERNAL_STORAGE, strings = { Manifest.permission.READ_EXTERNAL_STORAGE })
}
)
public class PhotoViewerPlugin extends Plugin {

Expand Down Expand Up @@ -54,7 +51,7 @@ private void imagesPermissionsCallback(PluginCall call) {
} else {
call.reject(PERMISSION_DENIED_ERROR);
}
} else if (Build.VERSION.SDK_INT >= 29 && Build.VERSION.SDK_INT < 33) {
} else if (Build.VERSION.SDK_INT >= 29 && Build.VERSION.SDK_INT < 33) {
if (getPermissionState(READ_EXTERNAL_STORAGE) == PermissionState.GRANTED) {
isPermissions = true;
show(call);
Expand All @@ -70,7 +67,6 @@ private boolean isImagesPermissions() {
return false;
}
} else if (Build.VERSION.SDK_INT >= 29 && Build.VERSION.SDK_INT < 33) {

if (getPermissionState(READ_EXTERNAL_STORAGE) != PermissionState.GRANTED) {
return false;
}
Expand Down Expand Up @@ -146,58 +142,59 @@ public void show(PluginCall call) {
AddObserversToNotificationCenter();

bridge
.getActivity()
.runOnUiThread(
() -> {
try {
if (images.length() <= 1 && (finalMode.equals("gallery") || finalMode.equals("slider"))) {
String msg = "Show : imageList must be greater that one ";
msg += "for Mode " + finalMode;
rHandler.retResult(call, false, msg);
return;
}
implementation.show(images, finalMode, finalStartFrom, finalOptions);
rHandler.retResult(call, true, null);
return;
} catch (Exception e) {
rHandler.retResult(call, false, e.getMessage());
}
.getActivity()
.runOnUiThread(
() -> {
try {
if (images.length() <= 1 && (finalMode.equals("gallery") || finalMode.equals("slider"))) {
String msg = "Show : imageList must be greater that one ";
msg += "for Mode " + finalMode;
rHandler.retResult(call, false, msg);
return;
}
);
implementation.show(images, finalMode, finalStartFrom, finalOptions);
rHandler.retResult(call, true, null);
return;
} catch (Exception e) {
rHandler.retResult(call, false, e.getMessage());
}
}
);
} catch (Exception e) {
String msg = "Show: " + e.getMessage();
rHandler.retResult(call, false, msg);
return;
}
}
}

@PluginMethod
public void saveImageFromHttpToInternal(PluginCall call) {
call.unimplemented("Not implemented on Android.");
}

@PluginMethod
public void getInternalImagePaths(PluginCall call) {
call.unimplemented("Not implemented on Android.");
call.unimplemented("Not implemented on Android.");
}

private void AddObserversToNotificationCenter() {
NotificationCenter
.defaultCenter()
.addMethodForNotification(
"photoviewerExit",
new MyRunnable() {
@Override
public void run() {
JSObject data = new JSObject();
data.put("result", this.getInfo().get("result"));
data.put("imageIndex", this.getInfo().get("imageIndex"));
data.put("message", this.getInfo().get("message"));
NotificationCenter.defaultCenter().removeAllNotifications();
notifyListeners("jeepCapPhotoViewerExit", data);
return;
}
}
);
.defaultCenter()
.addMethodForNotification(
"photoviewerExit",
new MyRunnable() {
@Override
public void run() {
JSObject data = new JSObject();
data.put("result", this.getInfo().get("result"));
data.put("imageIndex", this.getInfo().get("imageIndex"));
data.put("message", this.getInfo().get("message"));
NotificationCenter.defaultCenter().removeAllNotifications();
notifyListeners("jeepCapPhotoViewerExit", data);
return;
}
}
);
}
}
1 change: 0 additions & 1 deletion ios/Plugin/Extensions/UIViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ extension UIViewController {
transition.subtype = CATransitionSubtype.fromRight
}


self.view.window!.layer.add(transition, forKey: nil)
self.dismiss(animated: false, completion: nil)
}
Expand Down
5 changes: 2 additions & 3 deletions ios/Plugin/OnePhoto/OneImageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class OneImageViewController: UIViewController, UIScrollViewDelegate {
private var _colorRange: [String] = ["white", "ivory", "lightgrey"]
private var _btColor: UIColor = UIColor.white


// MARK: - Set-up url

var url: String {
Expand Down Expand Up @@ -96,7 +95,7 @@ class OneImageViewController: UIViewController, UIScrollViewDelegate {
navigationBar.isTranslucent = true
navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationBar.shadowImage = UIImage()
return navigationBar
return navigationBar
}()
lazy var mClose: UIBarButtonItem = {
let bClose = UIBarButtonItem()
Expand Down Expand Up @@ -221,7 +220,7 @@ class OneImageViewController: UIViewController, UIScrollViewDelegate {
NotificationCenter.default.post(name: .photoviewerExit,
object: nil,
userInfo: vId)
// self.dismissWithTransition()
// self.dismissWithTransition()
// self.dismiss(animated: true, completion: nil)
if swipe.direction == .up {
// Slide-up gesture
Expand Down
8 changes: 1 addition & 7 deletions ios/Plugin/PhotoSlider/ImageScrollViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@ class ImageScrollViewController: UIViewController {

}

// MARK: - viewDidLoad

override func viewDidLoad() {
super.viewDidLoad()
}

// MARK: - viewWillAppear

override func viewWillAppear(_ animated: Bool) {
Expand All @@ -136,7 +130,7 @@ class ImageScrollViewController: UIViewController {
mScrollView.addSubview(mImageView)
if url.prefix(4) == "http" || url.contains("base64") {
mImageView.sd_setImage(with: URL(string: url),
placeholderImage: nil)
placeholderImage: nil)
}
if url.prefix(38) ==
"file:///var/mobile/Media/DCIM/100APPLE" ||
Expand Down
6 changes: 3 additions & 3 deletions ios/Plugin/PhotoSlider/ImagesToVideo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class ImagesToVideo {
let mediaQueue = DispatchQueue(label: "mediaInputQueue")
videoWriterInput
.requestMediaDataWhenReady(on: mediaQueue,
using: { () -> Void in
using: { () in
let fps: Int32 = 1
let framePerSecond: Int64 = Int64(imagesPerSecond)
let frameDuration =
Expand Down Expand Up @@ -253,7 +253,7 @@ class ImagesToVideo {
let verticalRatio = CGFloat(movieSize.height) /
nextPhoto.size.height

//let aspectRatio = max(horizontalRatio,
// let aspectRatio = max(horizontalRatio,
// verticalRatio) // ScaleAspectFill

// ScaleAspectFit
Expand Down Expand Up @@ -295,7 +295,7 @@ class ImagesToVideo {
}
}
videoWriterInput.markAsFinished()
videoWriter.finishWriting { [self] () -> Void in
videoWriter.finishWriting { [self] () in

if videoWriter.status == .completed {
self._asset = AVAsset(url: videoURL as URL)
Expand Down
10 changes: 5 additions & 5 deletions ios/Plugin/PhotoViewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ enum PhotoViewerError: Error {
// get image location from the config
guard let imageLocation = config.iosImageLocation else {
let message = "You must have 'iosImageLocation' defined in " +
"the capacitor.config.ts file"
"the capacitor.config.ts file"
throw PhotoViewerError.failed(message: message)
}
guard let imageURL = URL(string: url) else {
Expand All @@ -96,15 +96,15 @@ enum PhotoViewerError: Error {
}

UtilsImage.downloadAndSaveImage(imageURL: imageURL,
imageName: fileName,
imageLocation: imageLocation) { result in
imageName: fileName,
imageLocation: imageLocation) { result in
switch result {
case .success(let imagePath):
// convert the filepath into a Web View-friendly path.
if let range = imagePath.path.range(of: "/Containers/", options: .backwards) {
let extractedPath = imagePath.path[range.upperBound...]
let resultPath = "capacitor://localhost/_capacitor_file_" +
"/var/mobile/Containers/" + String(extractedPath)
"/var/mobile/Containers/" + String(extractedPath)
call.resolve(["webPath": resultPath])
} else {
call.resolve(["message": "cannot create the Web View-friendly path"])
Expand All @@ -120,7 +120,7 @@ enum PhotoViewerError: Error {
// get image location from the config
guard let imageLocation = config.iosImageLocation else {
let message = "You must have 'iosImageLocation' defined in " +
"the capacitor.config.ts file"
"the capacitor.config.ts file"
throw PhotoViewerError.failed(message: message)
}
do {
Expand Down
Loading

0 comments on commit 7151db4

Please sign in to comment.