Skip to content

Commit

Permalink
MNW : Updated Add confirmation dialog on marking a child as deceased …
Browse files Browse the repository at this point in the history
…functionality | Updated Read Me
  • Loading branch information
ndegwamartin committed Jul 6, 2017
1 parent 0242ea7 commit fbae270
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 42 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.org/OpenSRP/opensrp-client.svg?branch=master)](https://travis-ci.org/OpenSRP/opensrp-client) [![Coverage Status](https://coveralls.io/repos/github/OpenSRP/opensrp-client/badge.svg?branch=master)](https://coveralls.io/github/OpenSRP/opensrp-client?branch=master)
[![Build Status](https://travis-ci.org/OpenSRP/opensrp-client.svg?branch=path)](https://travis-ci.org/OpenSRP/opensrp-client) [![Coverage Status](https://coveralls.io/repos/github/OpenSRP/opensrp-client/badge.svg?branch=path)](https://coveralls.io/github/OpenSRP/opensrp-client?branch=path)

[![Dristhi](opensrp-app/res/drawable-mdpi/login_logo.png)](https://smartregister.atlassian.net/wiki/dashboard.action)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.app.FragmentTransaction;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
Expand All @@ -23,9 +22,11 @@
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
Expand Down Expand Up @@ -650,11 +651,29 @@ public void onBackPressed() {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_GET_JSON) {
if (resultCode == RESULT_OK) {
try {
String jsonString = data.getStringExtra("json");
Log.d("JSONResult", jsonString);

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
AllSharedPreferences allSharedPreferences = new AllSharedPreferences(preferences);

JSONObject form = new JSONObject(jsonString);
if (form.getString("encounter_type").equals("Death")) {
confirmReportDeceased(jsonString, allSharedPreferences);
} else if (form.getString("encounter_type").equals("Birth Registration")) {
JsonFormUtils.editsave(this, getOpenSRPContext(), jsonString, allSharedPreferences.fetchRegisteredANM(), "Child_Photo", "child", "mother");
} else if (form.getString("encounter_type").equals("AEFI")) {
JsonFormUtils.saveAdverseEvent(jsonString, location_name,
childDetails.entityId(), allSharedPreferences.fetchRegisteredANM());
}
childDataFragment.childDetails = childDetails;
childDataFragment.loadData();
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}


String jsonString = data.getStringExtra("json");
confirmReportDeceased(jsonString);

}
} else if (requestCode == REQUEST_TAKE_PHOTO) {
if (resultCode == RESULT_OK) {
Expand All @@ -668,51 +687,65 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}

private void saveReportDeceasedJson(String jsonString) throws JSONException {

private void saveReportDeceasedJson(String jsonString, AllSharedPreferences allSharedPreferences) {

Log.d("JSONResult", jsonString);
JsonFormUtils.saveReportDeceased(this, getOpenSRPContext(), jsonString, allSharedPreferences.fetchRegisteredANM(), location_name, childDetails.entityId());

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
AllSharedPreferences allSharedPreferences = new AllSharedPreferences(preferences);

JSONObject form = new JSONObject(jsonString);
if (form.getString("encounter_type").equals("Death")) {
JsonFormUtils.saveReportDeceased(this, getOpenSRPContext(), jsonString, allSharedPreferences.fetchRegisteredANM(), location_name, childDetails.entityId());
} else if (form.getString("encounter_type").equals("Birth Registration")) {
JsonFormUtils.editsave(this, getOpenSRPContext(), jsonString, allSharedPreferences.fetchRegisteredANM(), "Child_Photo", "child", "mother");
} else if (form.getString("encounter_type").equals("AEFI")) {
JsonFormUtils.saveAdverseEvent(jsonString, location_name,
childDetails.entityId(), allSharedPreferences.fetchRegisteredANM());
}
childDataFragment.childDetails = childDetails;
childDataFragment.loadData();
}

private void confirmReportDeceased(final String json) {
private void confirmReportDeceased(final String json, final AllSharedPreferences allSharedPreferences) {

final AlertDialog builder = new AlertDialog.Builder(this).setCancelable(false).create();

AlertDialog dialog = new AlertDialog.Builder(this, R.style.PathAlertDialog)
.setMessage(childDetails.getColumnmaps().get("first_name") + " " + childDetails.getColumnmaps().get("last_name") + " marked as deceased")
.setCancelable(false)
.setPositiveButton(R.string.confirm_button_label,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
try {
saveReportDeceasedJson(json);
} catch (JSONException e) {
Log.e(TAG, e.getMessage());
}
}
})
.setNegativeButton(org.ei.opensrp.path.R.string.undo,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
LayoutInflater inflater = getLayoutInflater();
View notificationsLayout = inflater.inflate(R.layout.notification_base, null);
notificationsLayout.setVisibility(View.VISIBLE);

}
}).create();
ImageView notificationIcon = (ImageView) notificationsLayout.findViewById(R.id.noti_icon);
notificationIcon.setTag("confirm_deceased_icon");
notificationIcon.setImageResource(R.drawable.ic_deceased);

LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) notificationIcon.getLayoutParams();
params.setMargins(30, params.topMargin, params.rightMargin, params.bottomMargin);
notificationIcon.setLayoutParams(params);

TextView notificationMessage = (TextView) notificationsLayout.findViewById(R.id.noti_message);
notificationMessage.setText(childDetails.getColumnmaps().get("first_name") + " " + childDetails.getColumnmaps().get("last_name") + " marked as deceased");
notificationMessage.setTextColor(getResources().getColor(R.color.black));

Button positiveButton = (Button) notificationsLayout.findViewById(R.id.noti_positive_button);
positiveButton.setVisibility(View.VISIBLE);
positiveButton.setText(getResources().getString(R.string.undo));
positiveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

builder.dismiss();

}
});

Button negativeButton = (Button) notificationsLayout.findViewById(R.id.noti_negative_button);
negativeButton.setVisibility(View.VISIBLE);
negativeButton.setText(getResources().getString(R.string.confirm_button_label));
negativeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

saveReportDeceasedJson(json, allSharedPreferences);
builder.dismiss();

Intent intent = new Intent(getApplicationContext(), ChildSmartRegisterActivity.class);
intent.putExtra(BaseRegisterActivity.IS_REMOTE_LOGIN, false);
startActivity(intent);
finish();


}
});

dialog.show();
builder.setView(notificationsLayout);
builder.show();
}

@Override
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fbae270

Please sign in to comment.