Refactoring based on feedback from Andrew

This commit is contained in:
Joe Bowser 2015-08-28 16:50:16 -07:00
parent 07912fdecd
commit a0747aa960
5 changed files with 33 additions and 34 deletions

View File

@ -493,8 +493,7 @@ public class CordovaActivity extends Activity {
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[],
int[] grantResults) {
PluginManager pm = this.appView.getPluginManager();
pm.onRequestPermissionResult(requestCode, permissions, grantResults);
cordovaInterface.onRequestPermissionResult(requestCode, permissions, grantResults);
}
}

View File

@ -70,5 +70,6 @@ public interface CordovaInterface {
*/
public ExecutorService getThreadPool();
public void requestPermission(CordovaPlugin plugin);
public void requestPermission(CordovaPlugin plugin, String permission);
public void requestPermissions(CordovaPlugin plugin);
}

View File

@ -38,6 +38,7 @@ public class CordovaInterfaceImpl implements CordovaInterface {
protected ActivityResultHolder savedResult;
protected CordovaPlugin activityResultCallback;
protected CordovaPlugin permissionResultCallback;
protected String initCallbackService;
protected int activityResultRequestCode;
@ -162,9 +163,36 @@ public class CordovaInterfaceImpl implements CordovaInterface {
}
}
public void requestPermission(CordovaPlugin plugin)
/**
* Called by the system when the user grants permissions
*
* @param requestCode
* @param permissions
* @param grantResults
*/
public void onRequestPermissionResult(int requestCode, String[] permissions,
int[] grantResults) {
if(permissionResultCallback != null)
{
pluginManager.requestPermission(plugin);
permissionResultCallback.onRequestPermissionResult(requestCode, permissions, grantResults);
permissionResultCallback = null;
}
}
public void requestPermission(CordovaPlugin plugin, String permission) {
permissionResultCallback = plugin;
String[] permissions = new String [1];
permissions[0] = permission;
int requestCode = 1;
getActivity().requestPermissions(permissions, requestCode);
}
public void requestPermissions(CordovaPlugin plugin)
{
permissionResultCallback = plugin;
String[] permissions = plugin.getPermissionRequest();
int requestCode = 1;
getActivity().requestPermissions(permissions, requestCode);
}
}

View File

@ -372,13 +372,6 @@ public class CordovaPlugin {
return permissions;
}
/**
* requestPermission
*/
public void requestPermission() {
cordova.requestPermission(this);
}
public boolean hasPermisssion() {
for(String p : permissions)
{

View File

@ -511,26 +511,4 @@ public class PluginManager {
}
}
/**
* Called by the system when the user grants permissions
*
* @param requestCode
* @param permissions
* @param grantResults
*/
public void onRequestPermissionResult(int requestCode, String[] permissions,
int[] grantResults) {
if(permissionRequester != null)
{
permissionRequester.onRequestPermissionResult(requestCode, permissions, grantResults);
permissionRequester = null;
}
}
public void requestPermission(CordovaPlugin plugin) {
permissionRequester = plugin;
String[] permissions = plugin.getPermissionRequest();
int requestCode = 1;
ctx.getActivity().requestPermissions(permissions, requestCode);
}
}