Skip to content

Commit 13884fc

Browse files
authored
refactor(android): simplify plugin code (#89)
1 parent ffd3df4 commit 13884fc

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

android/src/main/java/com/getcapacitor/community/media/photoviewer/PhotoViewerPlugin.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ public class PhotoViewerPlugin extends Plugin {
3131
static final String MEDIAIMAGES = "images";
3232
static final String READ_EXTERNAL_STORAGE = "read_external_storage";
3333

34-
private static final String TAG = "CapacitorPhotoViewer";
35-
3634
private PhotoViewer implementation;
3735
private RetHandler rHandler = new RetHandler();
3836
private Boolean isPermissions = false;
@@ -51,7 +49,7 @@ private void imagesPermissionsCallback(PluginCall call) {
5149
} else {
5250
call.reject(PERMISSION_DENIED_ERROR);
5351
}
54-
} else if (Build.VERSION.SDK_INT >= 29 && Build.VERSION.SDK_INT < 33) {
52+
} else if (Build.VERSION.SDK_INT >= 29) {
5553
if (getPermissionState(READ_EXTERNAL_STORAGE) == PermissionState.GRANTED) {
5654
isPermissions = true;
5755
show(call);
@@ -63,13 +61,9 @@ private void imagesPermissionsCallback(PluginCall call) {
6361

6462
private boolean isImagesPermissions() {
6563
if (Build.VERSION.SDK_INT >= 33) {
66-
if (getPermissionState(MEDIAIMAGES) != PermissionState.GRANTED) {
67-
return false;
68-
}
69-
} else if (Build.VERSION.SDK_INT >= 29 && Build.VERSION.SDK_INT < 33) {
70-
if (getPermissionState(READ_EXTERNAL_STORAGE) != PermissionState.GRANTED) {
71-
return false;
72-
}
64+
return getPermissionState(MEDIAIMAGES) == PermissionState.GRANTED;
65+
} else if (Build.VERSION.SDK_INT >= 29) {
66+
return getPermissionState(READ_EXTERNAL_STORAGE) == PermissionState.GRANTED;
7367
}
7468
return true;
7569
}
@@ -85,7 +79,6 @@ public void echo(PluginCall call) {
8579

8680
@PluginMethod
8781
public void show(PluginCall call) {
88-
final AppCompatActivity activity = this.getActivity();
8982
if (!call.getData().has("images")) {
9083
String msg = "Show: Must provide an image list";
9184
rHandler.retResult(call, false, msg);
@@ -153,15 +146,13 @@ public void show(PluginCall call) {
153146
}
154147
implementation.show(images, finalMode, finalStartFrom, finalOptions);
155148
rHandler.retResult(call, true, null);
156-
return;
157149
} catch (Exception e) {
158150
rHandler.retResult(call, false, e.getMessage());
159151
}
160152
});
161153
} catch (Exception e) {
162154
String msg = "Show: " + e.getMessage();
163155
rHandler.retResult(call, false, msg);
164-
return;
165156
}
166157
}
167158
}

0 commit comments

Comments
 (0)