Github user dpolivy commented on a diff in the pull request:

    https://github.com/apache/cordova-plugin-camera/pull/97#discussion_r32879337
  
    --- Diff: www/Camera.js ---
    @@ -72,4 +72,28 @@ cameraExport.cleanup = function(successCallback, 
errorCallback) {
         exec(successCallback, errorCallback, "Camera", "cleanup", []);
     };
     
    +cameraExport.checkForSavedResult = function(successCallback, 
errorCallback, options) {
    +    argscheck.checkArgs('fFO', 'Camera.checkForSavedResult', arguments);
    +    options = options || {};
    +    var getValue = argscheck.getValue;
    +
    +    var quality = getValue(options.quality, 80);
    +    var destinationType = getValue(options.destinationType, 
Camera.DestinationType.FILE_URI);
    +    var sourceType = getValue(options.sourceType, 
Camera.PictureSourceType.CAMERA);
    +    var targetWidth = getValue(options.targetWidth, -1);
    +    var targetHeight = getValue(options.targetHeight, -1);
    +    var encodingType = getValue(options.encodingType, 
Camera.EncodingType.JPEG);
    +    var mediaType = getValue(options.mediaType, Camera.MediaType.PICTURE);
    +    var allowEdit = !!options.allowEdit;
    +    var correctOrientation = !!options.correctOrientation;
    +    var saveToPhotoAlbum = !!options.saveToPhotoAlbum;
    +    var popoverOptions = getValue(options.popoverOptions, null);
    +    var cameraDirection = getValue(options.cameraDirection, 
Camera.Direction.BACK);
    +
    +    var args = [quality, destinationType, sourceType, targetWidth, 
targetHeight, encodingType,
    +                mediaType, allowEdit, correctOrientation, 
saveToPhotoAlbum, popoverOptions, cameraDirection];
    --- End diff --
    
    It would be much better to refactor this as it's shared code with the 
getPicture API. Here's a refactor:
    
    ````
    // Put this before the getPicture method definition
    
    var prepareArgs = function(options) {
        options = options || {};
        var getValue = argscheck.getValue;
    
        var quality = getValue(options.quality, 50);
        var destinationType = getValue(options.destinationType, 
Camera.DestinationType.FILE_URI);
        var sourceType = getValue(options.sourceType, 
Camera.PictureSourceType.CAMERA);
        var targetWidth = getValue(options.targetWidth, -1);
        var targetHeight = getValue(options.targetHeight, -1);
        var encodingType = getValue(options.encodingType, 
Camera.EncodingType.JPEG);
        var mediaType = getValue(options.mediaType, Camera.MediaType.PICTURE);
        var allowEdit = !!options.allowEdit;
        var correctOrientation = !!options.correctOrientation;
        var saveToPhotoAlbum = !!options.saveToPhotoAlbum;
        var popoverOptions = getValue(options.popoverOptions, null);
        var cameraDirection = getValue(options.cameraDirection, 
Camera.Direction.BACK);
    
        return [quality, destinationType, sourceType, targetWidth, 
targetHeight, encodingType,
                    mediaType, allowEdit, correctOrientation, saveToPhotoAlbum, 
popoverOptions,
                    cameraDirection];
    };
    
    ...
    
    cameraExport.getPicture = function(successCallback, errorCallback, options) 
{
        argscheck.checkArgs('fFO', 'Camera.getPicture', arguments);
        var args = prepareArgs(options);
    
        exec(successCallback, errorCallback, "Camera", "takePicture", args);
        // XXX: commented out
        //return new CameraPopoverHandle();
    };
    
    ...
    
    cameraExport.checkForSavedResult = function(successCallback, errorCallback, 
options) {
        argscheck.checkArgs('fFO', 'Camera.checkForSavedResult', arguments);
        var args = prepareArgs(options);
    
        exec(successCallback, errorCallback, "Camera", "checkForSavedResult", 
args);
    };
    ````


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@cordova.apache.org
For additional commands, e-mail: dev-h...@cordova.apache.org

Reply via email to