Skip to content

Commit

Permalink
Merge pull request #1091 from dimagi/detail-callout-fix
Browse files Browse the repository at this point in the history
Fix case detail phone callout & add localizations
  • Loading branch information
wpride committed Feb 24, 2016
2 parents 956a122 + fda27f0 commit 3bc3052
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
4 changes: 4 additions & 0 deletions app/assets/locales/messages_ccodk_default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ select.menu.map=View on Map

select.detail.title=Details
select.list.title=Select
select.detail.callout.title=Select phone number action
select.detail.callout.call=Call
select.detail.callout.sms=Send SMS

home.logged.in.message=Logged In: ${0}
notification.logged.in=Logged Into ${0}
Expand Down Expand Up @@ -642,6 +645,7 @@ permission.all.message=CommCare needs permissions to read/write forms to memory,
permission.all.denial.message=CommCare doesn't have the necessary permissions. Please enable via 'Settings -> Apps'
permission.case.callout.title=Permissions for calling & messaging
permission.case.callout.message=CommCare needs call & messaging permissions to enable communication with cases.
permission.case.callout.denied=Permissions denied for calling & messaging from case detail screen.
permission.sms.install.title=Permission for obtaining SMS app code
permission.sms.install.message=CommCare would like to scan your recent messages for an app install code.
permission.form.gps.title=Permission to capture location during form entry
Expand Down
35 changes: 16 additions & 19 deletions app/src/org/commcare/dalvik/activities/CallOutActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

private void loadStateFromInstance(Bundle savedInstanceState) {
if (savedInstanceState.containsKey(CALLOUT_ACTION_KEY)) {
if (savedInstanceState != null && savedInstanceState.containsKey(CALLOUT_ACTION_KEY)) {
calloutAction = savedInstanceState.getString(CALLOUT_ACTION_KEY);
}
}
Expand Down Expand Up @@ -97,25 +97,27 @@ protected void onResume() {
}

private void showChoiceDialog() {
PaneledChoiceDialog dialog = new PaneledChoiceDialog(this, "Select Action");
final PaneledChoiceDialog dialog = new PaneledChoiceDialog(this, Localization.get("select.detail.callout.title"));

View.OnClickListener callListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
calloutAction = Intent.ACTION_CALL;
dispatchActionWithPermissions();
dialog.dismiss();
}
};
DialogChoiceItem item1 = new DialogChoiceItem("Call", -1, callListener);
DialogChoiceItem item1 = new DialogChoiceItem(Localization.get("select.detail.callout.call"), -1, callListener);

View.OnClickListener smsListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
calloutAction = Intent.ACTION_SENDTO;
dispatchActionWithPermissions();
dialog.dismiss();
}
};
DialogChoiceItem item2 = new DialogChoiceItem("Send SMS", -1, smsListener);
DialogChoiceItem item2 = new DialogChoiceItem(Localization.get("select.detail.callout.sms"), -1, smsListener);

dialog.setChoiceItems(new DialogChoiceItem[]{item1, item2});
dialog.setOnCancelListener(new OnCancelListener() {
Expand All @@ -131,6 +133,7 @@ public void onCancel(DialogInterface dialog) {
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);

outState.putString(CALLOUT_ACTION_KEY, calloutAction);
}

Expand All @@ -151,28 +154,20 @@ private void dispatchActionWithPermissions() {
}
}

private String getPermissionForAction() {
if (calloutAction.equals(Intent.ACTION_CALL)) {
return Manifest.permission.CALL_PHONE;
} else if (calloutAction.equals(Intent.ACTION_SENDTO)) {
return Manifest.permission.RECEIVE_SMS;
}
return "";
}

private boolean missingPhonePermission() {
return ContextCompat.checkSelfPermission(this, getPermissionForAction()) != PackageManager.PERMISSION_GRANTED;
return calloutAction.equals(Intent.ACTION_CALL) &&
ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED;
}

private boolean shouldShowPhonePermissionRationale() {
return ActivityCompat.shouldShowRequestPermissionRationale(this,
getPermissionForAction());
Manifest.permission.CALL_PHONE);
}

@Override
public void requestNeededPermissions(int requestCode) {
ActivityCompat.requestPermissions(this,
new String[]{getPermissionForAction()},
new String[]{Manifest.permission.CALL_PHONE},
requestCode);
}

Expand All @@ -182,17 +177,19 @@ public void onRequestPermissionsResult(int requestCode,
@NonNull int[] grantResults) {
if (requestCode == CALL_OR_SMS_PERMISSION_REQUEST) {
for (int i = 0; i < permissions.length; i++) {
if (getPermissionForAction().equals(permissions[i]) &&
if (Manifest.permission.CALL_PHONE.equals(permissions[i]) &&
grantResults[i] == PackageManager.PERMISSION_GRANTED) {
dispatchAction();
return;
}
}
}
Toast.makeText(this, Localization.get("permission.case.callout.denied"), Toast.LENGTH_LONG).show();
finish();
}

private void dispatchAction() {
// using createChooser to handle any errors gracefully
if(Intent.ACTION_CALL.equals(calloutAction) ) {
if (Intent.ACTION_CALL.equals(calloutAction)) {
tManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);

Intent call = new Intent(Intent.ACTION_CALL);
Expand Down

0 comments on commit 3bc3052

Please sign in to comment.