Skip to content

Commit

Permalink
refactor if condition
Browse files Browse the repository at this point in the history
  • Loading branch information
dinitri committed May 10, 2024
1 parent 4cf88d1 commit c6a131a
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/android/SpectrumManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,14 @@ private void transcodeImage(String path, int size, CallbackContext callbackConte
String destinationPath = sourcePath.replace(file.getName(), destinationFileName);
File outputFile = new File(destinationPath);

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
callbackContext.error("Cannot compress image on Android version < 11");
return;
}

try (FileOutputStream out = new FileOutputStream(outputFile)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (!bitmap.compress(Bitmap.CompressFormat.JPEG, 80, out)) {
callbackContext.error("Failed to compress image");
return;
}
} else {
Log.d("Warning","Cannot compress image on Android version < 11");
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
pluginResult.setKeepCallback(true);
callbackContext.sendPluginResult(pluginResult);
if (!bitmap.compress(Bitmap.CompressFormat.JPEG, 80, out)) {
callbackContext.error("Failed to compress image");
return;
}
} catch (Exception e) {
Expand Down

0 comments on commit c6a131a

Please sign in to comment.