I think maybe this code would be a little easier to understand if you changed leastPreviewWidth and leastPreviewHeight to minPreviewWidth and minPreviewHeight.  And changed leastPreviewRatio to screenAspectRatio.